ngx-admin/src/app/pages/charts/chartjs/chartjs-bar.component.ts

73 lines
1.7 KiB
TypeScript
Raw Normal View History

import { Component } from '@angular/core';
import { NbThemeService } from '@nebular/theme';
@Component({
2017-07-27 12:06:50 +03:00
selector: 'ngx-chartjs-bar',
styles: [
`
:host {
display: block;
}
`,
],
template: `
<canvas baseChart
2017-07-27 12:06:50 +03:00
[datasets]="chartData"
[labels]="chartLabels"
[options]="chartOptions"
[legend]="chartLegend"
[chartType]="chartType"></canvas>
`,
})
export class ChartjsBarComponent {
2017-07-27 12:06:50 +03:00
chartLabels: string[] = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
chartType: string = 'bar';
chartLegend: boolean = true;
chartData: any[] = [
{ data: [65, 59, 80, 81, 56, 55, 40], label: 'Series A' },
{ data: [28, 48, 40, 19, 86, 27, 90], label: 'Series B' },
];
chartOptions: any;
constructor(private theme: NbThemeService) {
this.theme.getJsTheme().subscribe(config => {
2017-08-01 15:42:06 +03:00
const chartjs: any = config.variables.chartjs;
this.chartOptions = {
scaleShowVerticalLines: false,
responsive: true,
legend: {
labels: {
2017-08-01 15:42:06 +03:00
fontColor: chartjs.legendTextColor,
},
},
scales: {
xAxes: [
{
gridLines: {
display: true,
2017-08-01 15:42:06 +03:00
color: chartjs.xAxisColor,
},
ticks: {
2017-08-01 15:42:06 +03:00
fontColor: chartjs.tickColor,
},
},
],
yAxes: [
{
gridLines: {
display: true,
2017-08-01 15:42:06 +03:00
color: chartjs.yAxisColor,
},
ticks: {
2017-08-01 15:42:06 +03:00
fontColor: chartjs.tickColor,
},
},
],
},
};
});
}
}