-
-
Notifications
You must be signed in to change notification settings - Fork 654
/
legendOptions.ts
35 lines (33 loc) · 1.17 KB
/
legendOptions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type { Chart } from 'chart.js';
export const legendOptions = {
position: 'bottom',
labels: {
boxWidth: 12,
padding: 30,
generateLabels: (chart: Chart) => {
const datasets = chart.data.datasets;
const {
labels: { usePointStyle, pointStyle, textAlign, color },
} = chart?.legend?.options || {
labels: {},
};
return (chart as any)._getSortedDatasetMetas().map((meta: any) => {
const style = meta.controller.getStyle(
usePointStyle ? 0 : undefined,
);
return {
text: datasets[meta.index].label,
fillStyle: style.borderColor,
fontColor: color,
hidden: !meta.visible,
lineWidth: 0,
borderRadius: 6,
strokeStyle: style.borderColor,
pointStyle: pointStyle || style.pointStyle,
textAlign: textAlign || style.textAlign,
datasetIndex: meta.index,
};
});
},
},
} as const;