diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index 36f25643d9..41ab453e0f 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -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 }; diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index 8160c001a0..854d4557ed 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -14,6 +14,7 @@ // Francesco Benedetto // Alexandros Dorodoulis // Manuel Heidrich +// Conrad Holtzhausen // 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;