ng-chartist
Version:
Chartist component for Angular
150 lines (119 loc) • 2.64 kB
Markdown
[](https://willsoto.github.io/ng-chartist/demo/index.html)
[](https://willsoto.github.io/ng-chartist/docs/)
| Angular | ng-chartist |
| ------- | ----------- |
| 12x | 5x |
| <=11x | 4x |
- [About](
- [Installation](
- [Documentation](
- [Development](
- [License](
Chartist component for Angular 4+
```bash
yarn add ng-chartist chartist
yarn add --dev @types/chartist
```
```bash
npm i --save ng-chartist chartist
npm i --save-dev @types/chartist
```
Add to styles section in `angular.json` file:
```json
"styles": [
"node_modules/chartist/dist/chartist.css",
"src/style.scss"
],
```
```typescript
// app.module.ts
import { ChartistModule } from "ng-chartist";
@NgModule({
imports: [
ChartistModule, // add ChartistModule to your imports
],
})
export class AppModule {}
```
```typescript
// bar-chart.component.ts
import {
IBarChartOptions,
IChartistAnimationOptions,
IChartistData
} from 'chartist';
import { ChartEvent, ChartType } from 'ng-chartist';
@Component({
selector: 'app-bar-chart',
template: `
<x-chartist
[]="type"
[]="data"
[]="options"
[]="events"
></x-chartist>
`
]
})
export class BarChartComponent {
type: ChartType = 'Bar';
data: IChartistData = {
labels: [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
],
series: [
[],
[]
]
};
options: IBarChartOptions = {
axisX: {
showGrid: false
},
height: 300
};
events: ChartEvent = {
draw: (data) => {
if (data.type === 'bar') {
data.element.animate({
y2: <IChartistAnimationOptions>{
dur: '0.5s',
from: data.y1,
to: data.y2,
easing: 'easeOutQuad'
}
});
}
}
};
}
```
You may also find it useful to view the [demo source](https://github.com/willsoto/ng-chartist/blob/master/projects/ng-chartist-demo/src/app/app.component.ts).
Apache-2.0