8.0.0 • Published 2 years ago

@ctrl/ngx-chartjs v8.0.0

Weekly downloads
1,022
License
MIT
Repository
github
Last release
2 years ago

Functional Chart.js wrapper for Angular

Based on react-chartjs-2

Demo: https://ngx-chartjs.vercel.app

Install

requires peer dependency js package chart.js

npm install @ctrl/ngx-chartjs chart.js

Dependencies

Latest version available for each version of Angular

@ctrl/ngx-chartjsAngular
1.1.26.x 7.x
2.0.08.x
3.0.19.x
4.0.210.x
6.0.111.x
current>=12.x

Use

Import and Add to module

import { ChartjsModule } from '@ctrl/ngx-chartjs';

register chartjs at root of app or module. Must run before this component mounts

// What you register will depend on what chart you are using and features used.
import { BarController, BarElement, Chart, Title, Tooltip, Legend } from 'chart.js';
Chart.register(BarController, BarElement, Title, Tooltip, Legend);

setup data and other settings

import type { ChartData, ChartOptions } from 'chart.js';
const data: ChartData = {
  labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  datasets: [
    {
      label: 'My First Dataset',
      data: [65, 59, 80, 81, 56, 55, 40],
      fill: false,
      backgroundColor: [
        'rgba(255, 99, 132, 0.2)',
        'rgba(255, 159, 64, 0.2)',
        'rgba(255, 205, 86, 0.2)',
        'rgba(75, 192, 192, 0.2)',
        'rgba(54, 162, 235, 0.2)',
        'rgba(153, 102, 255, 0.2)',
        'rgba(201, 203, 207, 0.2)',
      ],
      borderColor: [
        'rgb(255, 99, 132)',
        'rgb(255, 159, 64)',
        'rgb(255, 205, 86)',
        'rgb(75, 192, 192)',
        'rgb(54, 162, 235)',
        'rgb(153, 102, 255)',
        'rgb(201, 203, 207)',
      ],
      borderWidth: 1,
    },
  ],
};
const options: ChartOptions = {
  responsive: true,
  plugins: {
    legend: {
      position: 'top',
    },
    title: {
      display: true,
      text: 'Chart.js Doughnut Chart',
    },
  },
};

Add ngx-chartjs directive to element

<ngx-chartjs type="bar" [data]="data" [options]="options"></ngx-chartjs>

Inputs

nametypedefaultdescription
typestring'doughnut'chart.js type 'bar', 'line', etc.
dataChartData{}chart.js data object, see docs
optionsany{}chart.js options
redrawbooleanfalseforce redraw on any input change, like to change legend
updateModestringundefinedparameter passed to chart.update()
widthnumber300canvas width
heightnumber150canvas height

License

MIT


GitHub @scttcper  ·  Twitter @scttcper

8.0.0

2 years ago

6.0.1

3 years ago

7.0.0

3 years ago

6.0.0

3 years ago

5.0.0

3 years ago

4.1.0

3 years ago

4.1.1

3 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.2

4 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago