![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
ng2-charts
Advanced tools
Beautiful charts for Angular based on Chart.js
Samples using ng2-charts
https://valor-software.com/ng2-charts/
You can install ng2-charts by using the Angular CLI:
ng add ng2-charts
The required packages will be automatically installed, and your app.module.ts
will be updated with the required
changes to start using the library right away.
npm install ng2-charts --save
or yarn
yarn add ng2-charts --save
Chart.js
library in your application (it is a peer dependency of this
library, more info can be found in the
official chart.js
documentation)npm install chart.js --save
or with yarn:
yarn add chart.js --save
NgChartsModule
in your app main module:import { NgChartsModule } from 'ng2-charts';
// In your App's module:
imports: [
NgChartsModule
]
There is one directive for all chart types: baseChart
, and there are 8 types of charts: line
, bar
, radar
, pie
, polarArea
, doughnut
, bubble
and scatter
. You can use the directive on a canvas
element as follows:
<canvas baseChart
[data]="barChartData"
[options]="barChartOptions"
[type]="'bar'">
</canvas>
Note: For more information about possible options please refer to original chart.js documentation
type
: (ChartType
) - indicates the type of chart, it can be: line
, bar
, radar
, pie
, polarArea
, doughnut
or any custom type added to Chart.jsdata
: (ChartData<TType, TData, TLabel>
) - the whole data structure to be rendered in the chart. Support different
flexible formats and parsing options,
see here. In alternative, and depending on
the type
of your chart, you can use the labels
and datasets
properties to specify individual options.labels
: (TLabel[]
) - Datasets labels. It's necessary for charts: line
, bar
and radar
. And just labels (on
hover) for charts: polarArea
, pie
and doughnut
. Labels are matched in order with the datasets
array.datasets
: ( ChartDataset<TType, TData>[]
) - Same as the datasets
property of the data
input.
See here for details.options
: (ChartOptions<TType>
) - chart options (as
per chart.js documentation).legend
: (boolean = false
) - if true, chart legend is shown.chartClick
: fires when click on a chart has occurred, returns information regarding active points and labelschartHover
: fires when mousemove (hover) on a chart has occurred, returns information regarding active points and
labelsThe library comes with a set of predefined default colors (which are exported as baseColors
). If there are more
datasets than colors, colors are generated randomly. You can specify custom colors by following
these instructions.
The NgChartsModule
provides a service called ThemeService
which allows clients to set a structure specifying colors
override settings. This service may be called when the dynamic theme changes, with colors which fit the theme. The
structure is interpreted as an override, with special functionality when dealing with arrays. Example:
type Theme = 'light-theme' | 'dark-theme';
private _selectedTheme: Theme = 'light-theme';
public get selectedTheme(){
return this._selectedTheme;
}
public set selectedTheme(value){
this._selectedTheme = value;
let overrides: ChartOptions;
if (this.selectedTheme === 'dark-theme') {
overrides = {
legend: {
labels: { fontColor: 'white' }
},
scales: {
xAxes: [ {
ticks: { fontColor: 'white' },
gridLines: { color: 'rgba(255,255,255,0.1)' }
} ],
yAxes: [ {
ticks: { fontColor: 'white' },
gridLines: { color: 'rgba(255,255,255,0.1)' }
} ]
}
};
} else {
overrides = {};
}
this.themeService.setColorschemesOptions(overrides);
}
constructor(private themeService: ThemeService<AppChartMetaConfig>){
}
setCurrentTheme(theme: Theme){
this.selectedTheme = theme;
}
The overrides
object has the same type as the chart options object ChartOptions
, and wherever a simple field is
encountered it replaces the matching field in the options
object. When an array is encountered (as in the xAxes
and yAxes
fields above), the single object inside the array is used as a template to override all array elements in
the matching field in the options
object. So in the case above, every axis will have its ticks and gridline colors
changed.
There are schematics that may be used to add this library to your project and generate chart components using Angular CLI.
ng add ng2-charts
This schematics will add the NgChartsModule
as an imported module in the main app module (or another module as specified
in the --module
command option).
ng generate ng2-charts:line my-line-chart
This calls angular's component schematics and then modifies the result, so all the options for the component schematic are also usable here.
Please follow this guidelines when reporting bugs and feature requests:
Thanks for understanding!
The MIT License (see the LICENSE file for the full text)
FAQs
Reactive, responsive, beautiful charts for Angular based on Chart.js
The npm package ng2-charts receives a total of 99,901 weekly downloads. As such, ng2-charts popularity was classified as popular.
We found that ng2-charts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.