GithubHelp home page GithubHelp logo

ng2-chartjs2's Introduction

npm

NPM

Chart.js 2.0 Component for Angular 2

This is an Angular 2 component to display charts. This component uses Chart.js 2.0. It works well with responsive sites, so it should work properly with all Angular2 apps, as well as Ionic 2 apps.

Note: This is work in progress, watch this repo to stay up to date.

Installation

You must manually include Chart.js library into your build or index.html

npm i --save-dev ng2-chartjs2

Example Usage

You can either pass options attribute with your own custom options (see Chart.js Docs) or pass individual options like labels, data, and type.

import {ChartComponent, Chart} from 'ng2-chartjs2';

@Component({
  selector: 'my-app',
  template: '<chart [labels]="labels" [data]="data" type="bar"></chart>',
  directives: [ChartComponent]
})
export class AppComponent {
  labels: string[] = ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"];
  data: Chart.Dataset[] = [
    {
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      backgroundColor: [
        'rgba(255, 99, 132, 0.2)',
        'rgba(54, 162, 235, 0.2)',
        'rgba(255, 206, 86, 0.2)',
        'rgba(75, 192, 192, 0.2)',
        'rgba(153, 102, 255, 0.2)',
        'rgba(255, 159, 64, 0.2)'
      ],
      borderColor: [
        'rgba(255,99,132,1)',
        'rgba(54, 162, 235, 1)',
        'rgba(255, 206, 86, 1)',
        'rgba(75, 192, 192, 1)',
        'rgba(153, 102, 255, 1)',
        'rgba(255, 159, 64, 1)'
      ],
      borderWidth: 1
    }
  ];
}

Reference

This repo will only document things related to the Angular 2 Component. To understand how Chart.js works you need to visit their docs

Chart.js Doc Section Represented by interface
Options / Common Chart Configuration Chart.Options
Title Configuration Chart.TitleConfiguration
Legend Configuration Chart.LegendConfiguration
Legend Item Interface Chart.LegendItem
Tooltip Configuration Chart.TooltipConfiguration
Tooltip Callbacks Chart.TooltipCallbacks
Tooltip Item Interface Chart.TooltipItem
Hover Configuration Chart.HoverConfiguration
Animation Configuration Chart.AnimationConfiguration
Animation Interface Chart.Animation
Element Configuration
Data Point (for any type) Chart.Dataset

TODO

  • Get the charts working
  • Define interfaces and enums
    • Main options (missing a few)
    • Chart types
    • Title Configuration
    • Legend Configuration
    • Legend Label Configuration
    • Tooltip Configuration
    • Hover Configuration
    • Animation Configuration
    • Element Configuration
    • Line Configuration
    • Rectangle Configuration
    • Animation
  • Provide more options and control via component inputs
    • Labels
    • Data
    • Type
  • Route chart events through component outputs

ng2-chartjs2's People

Contributors

ihadeed avatar

Watchers

Gilberto Botaro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.