🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@ctrl/ngx-chartjs

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ctrl/ngx-chartjs

chartjs wrapper for angular

Source
npmnpm
Version
4.0.1
Version published
Weekly downloads
1.6K
3.03%
Maintainers
1
Weekly downloads
 
Created
Source

ngx-chartjs


npm travis codecov

Functional Chart.js wrapper for Angular

Based on react-chartjs-2

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

Install

requires the 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
current>= 10.x

Use

Import and Add to module

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

setup data and other settings

const data = {
  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,
    },
  ],
};

Add ngx-chartjs directive to element

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

[Inputs]

nametypedefaultdescription
typestring'doughnut'chart.js type 'bar', 'line', etc.
dataChartData{}chart.js data object, see docs
pluginsany[][]chart.js plugin array, see docs
redrawbooleanfalseforce redraw on any input change, like to change legend
optionsany{}chart.js options
legendany{display: true, position: 'bottom'}chart.js legend see docs
widthnumber300canvas width
heightnumber150canvas height

Tips

data: do not modify data as change detection will not fire, only replace with new object
legend: can also be overwritten via options

(Ouput)

Chart.js events are available via options or legend object, otherwise a canvas click event is exposed for use

nametypedescription
chartClickChartClickEventreturns the click $event along with element, elements and dataset see docs

License

MIT

GitHub @scttcper  ·  Twitter @scttcper

Keywords

chartjs

FAQs

Package last updated on 21 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts