Extending definition of scales (#39318)

Allowing ChartScales, LinearScale, LogarithmicScale and TimeScale as value for scales property of ChartOptions.
This commit is contained in:
Adrián Caballero
2019-10-22 10:52:52 -07:00
committed by Wesley Wigham
parent a151389bac
commit ff522b12c1
2 changed files with 40 additions and 2 deletions
+39 -1
View File
@@ -1,4 +1,4 @@
import { BorderWidth, Chart, ChartData, Point, ChartColor } from 'chart.js';
import { BorderWidth, Chart, Point, ChartColor } from 'chart.js';
// alternative:
// import chartjs = require('chart.js');
@@ -241,3 +241,41 @@ const chartWithScriptedOptions = new Chart(new CanvasRenderingContext2D(), {
}],
}
});
// linear scale
const linearScaleChart: Chart = new Chart(ctx, {
type: 'bar',
data: {
datasets: [{
backgroundColor: '#000',
borderColor: '#f00',
data: [],
type: 'line',
}]
},
options: {
scales: {
displayFormats: {
month: 'MMM YYYY',
},
xAxes: [{
type: 'time',
distribution: 'series',
ticks: {
source: 'data',
autoSkip: true
}
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Closing price ($)'
}
}]
},
tooltips: {
intersect: false,
mode: 'index',
}
}
});
+1 -1
View File
@@ -249,7 +249,7 @@ declare namespace Chart {
elements?: ChartElementsOptions;
layout?: ChartLayoutOptions;
scale?: RadialLinearScale;
scales?: ChartScales;
scales?: ChartScales | LinearScale | LogarithmicScale | TimeScale;
showLines?: boolean;
spanGaps?: boolean;
cutoutPercentage?: number;