2017-07-26 19:59:47 +03:00
|
|
|
import { Component } from '@angular/core';
|
2017-07-28 16:09:02 +03:00
|
|
|
import { NgaThemeService } from '@akveo/nga-theme';
|
2017-07-26 19:59:47 +03:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'ngx-chartjs-multiple-xaxis',
|
2017-07-27 12:06:50 +03:00
|
|
|
styles: [
|
|
|
|
|
`
|
|
|
|
|
:host {
|
|
|
|
|
display: block;
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
],
|
|
|
|
|
template: `
|
|
|
|
|
<canvas baseChart
|
|
|
|
|
[datasets]="chartData"
|
|
|
|
|
[labels]="chartLabels"
|
|
|
|
|
[options]="chartOptions"
|
|
|
|
|
[legend]="chartLegend"
|
|
|
|
|
[chartType]="chartType"></canvas>
|
|
|
|
|
`,
|
2017-07-26 19:59:47 +03:00
|
|
|
})
|
|
|
|
|
export class ChartjsMultipleXaxisComponent {
|
2017-07-27 12:06:50 +03:00
|
|
|
chartType: string = 'line';
|
|
|
|
|
chartLabels = ['January', 'February', 'March', 'April', 'May', 'June', 'July'];
|
|
|
|
|
chartLegend: boolean = true;
|
|
|
|
|
chartData: any[] = [
|
|
|
|
|
{
|
|
|
|
|
label: 'dataset - big points',
|
|
|
|
|
data: [
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
],
|
|
|
|
|
backgroundColor: 'red',
|
|
|
|
|
borderColor: 'red',
|
|
|
|
|
fill: false,
|
|
|
|
|
borderDash: [5, 5],
|
|
|
|
|
pointRadius: 15,
|
|
|
|
|
pointHoverRadius: 10,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'dataset - individual point sizes',
|
|
|
|
|
data: [
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
],
|
|
|
|
|
backgroundColor: 'blue',
|
|
|
|
|
borderColor: 'blue',
|
|
|
|
|
fill: false,
|
|
|
|
|
borderDash: [5, 5],
|
|
|
|
|
pointRadius: [2, 4, 6, 18, 0, 12, 20],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'dataset - large pointHoverRadius',
|
|
|
|
|
data: [
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
],
|
|
|
|
|
backgroundColor: 'green',
|
|
|
|
|
borderColor: 'green',
|
|
|
|
|
fill: false,
|
|
|
|
|
pointHoverRadius: 30,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'dataset - large pointHitRadius',
|
|
|
|
|
data: [
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
this.randomScalingFactor(),
|
|
|
|
|
],
|
|
|
|
|
backgroundColor: 'yellow',
|
|
|
|
|
borderColor: 'yellow',
|
|
|
|
|
fill: false,
|
|
|
|
|
pointHitRadius: 20,
|
|
|
|
|
},
|
|
|
|
|
];
|
2017-07-28 16:09:02 +03:00
|
|
|
chartOptions: any;
|
|
|
|
|
|
|
|
|
|
constructor(private theme: NgaThemeService) {
|
|
|
|
|
this.theme.getJsTheme().subscribe(config => {
|
2017-08-01 15:42:06 +03:00
|
|
|
|
|
|
|
|
const chartjs: any = config.variables.chartjs;
|
|
|
|
|
|
2017-07-28 16:09:02 +03:00
|
|
|
this.chartOptions = {
|
|
|
|
|
responsive: true,
|
|
|
|
|
legend: {
|
|
|
|
|
position: 'bottom',
|
|
|
|
|
labels: {
|
2017-08-01 15:42:06 +03:00
|
|
|
fontColor: chartjs.legendTextColor,
|
2017-07-28 16:09:02 +03:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
hover: {
|
|
|
|
|
mode: 'index',
|
|
|
|
|
},
|
|
|
|
|
scales: {
|
|
|
|
|
xAxes: [
|
|
|
|
|
{
|
|
|
|
|
display: true,
|
|
|
|
|
scaleLabel: {
|
|
|
|
|
display: true,
|
|
|
|
|
labelString: 'Month',
|
|
|
|
|
},
|
|
|
|
|
gridLines: {
|
|
|
|
|
display: true,
|
2017-08-01 15:42:06 +03:00
|
|
|
color: chartjs.xAxisColor,
|
2017-07-28 16:09:02 +03:00
|
|
|
},
|
|
|
|
|
ticks: {
|
2017-08-01 15:42:06 +03:00
|
|
|
fontColor: chartjs.tickColor,
|
2017-07-28 16:09:02 +03:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
yAxes: [
|
|
|
|
|
{
|
|
|
|
|
display: true,
|
|
|
|
|
scaleLabel: {
|
|
|
|
|
display: true,
|
|
|
|
|
labelString: 'Value',
|
|
|
|
|
},
|
|
|
|
|
gridLines: {
|
|
|
|
|
display: true,
|
2017-08-01 15:42:06 +03:00
|
|
|
color: chartjs.xAxisColor,
|
2017-07-28 16:09:02 +03:00
|
|
|
},
|
|
|
|
|
ticks: {
|
2017-08-01 15:42:06 +03:00
|
|
|
fontColor: chartjs.tickColor,
|
2017-07-28 16:09:02 +03:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-07-27 12:06:50 +03:00
|
|
|
|
|
|
|
|
private randomScalingFactor() {
|
|
|
|
|
return Math.round(Math.random() * 100);
|
|
|
|
|
}
|
2017-07-26 19:59:47 +03:00
|
|
|
}
|