Merge pull request #28941 from Conrad777/master

@types/chart.js: added missing legendCallback to ChartOptions
This commit is contained in:
Jesse Trinity
2018-09-19 15:49:05 -07:00
committed by GitHub
2 changed files with 24 additions and 10 deletions
+22 -10
View File
@@ -5,8 +5,8 @@ import { Chart, ChartData, Point } from "chart.js";
// => chartjs.Chart
const plugin = {
afterDraw: (chartInstance: Chart, easing: string, options?: any) => {
}
afterDraw: (chartInstance: Chart, easing: string, options?: any) => {
}
};
const chart: Chart = new Chart(new CanvasRenderingContext2D(), {
@@ -82,6 +82,18 @@ if (chart.chartArea) {
console.log(chart.chartArea.left);
}
// Testing custom legends
chart.config.options = {
...chart.config.options,
legend: {
display: false,
},
legendCallback: () => 'legend replacement'
};
chart.update();
const customLegend = chart.generateLegend();
console.log(customLegend === 'legend replacement');
// Testing radial chart
const tickOptions: Chart.LinearTickOptions = {
max: 100,
@@ -107,14 +119,14 @@ const chartConfig: Chart.ChartConfiguration = {
data: {
labels: ['#apples', '#pears', '#apricots', '#acorns', '#amigas', "#orics"],
datasets: [{
label: "test",
lineTension: 0.15,
data: [1, 1, 2, 3, 5],
backgroundColor: '#37738353',
borderColor: '#37738353',
borderWidth: 3,
fill: true
}]
label: "test",
lineTension: 0.15,
data: [1, 1, 2, 3, 5],
backgroundColor: '#37738353',
borderColor: '#37738353',
borderWidth: 3,
fill: true
}]
},
options: radarChartOptions
};
+2
View File
@@ -14,6 +14,7 @@
// Francesco Benedetto <https://github.com/frabnt>
// Alexandros Dorodoulis <https://github.com/alexdor>
// Manuel Heidrich <https://github.com/mahnuh>
// Conrad Holtzhausen <https://github.com/Conrad777>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -264,6 +265,7 @@ declare namespace Chart {
aspectRatio?: number;
maintainAspectRatio?: boolean;
events?: string[];
legendCallback?(chart: Chart): string;
onHover?(this: Chart, event: MouseEvent, activeElements: Array<{}>): any;
onClick?(event?: MouseEvent, activeElements?: Array<{}>): any;
onResize?(this: Chart, newSize: ChartSize): void;