ctx.textAlign = rtlHelper.textAlign('left');
ctx.textBaseline = 'middle';
ctx.lineWidth = 0.5;
- ctx.strokeStyle = fontColor; // for strikethrough effect
- ctx.fillStyle = fontColor; // render in correct colour
ctx.font = labelFont.string;
const {boxWidth, boxHeight, itemHeight} = getBoxSize(labelOpts, fontSize);
const lineHeight = itemHeight + padding;
me.legendItems.forEach((legendItem, i) => {
+ // TODO: Remove fallbacks at v4
+ ctx.strokeStyle = legendItem.fontColor || fontColor; // for strikethrough effect
+ ctx.fillStyle = legendItem.fontColor || fontColor; // render in correct colour
+
const textWidth = ctx.measureText(legendItem.text).width;
const textAlign = rtlHelper.textAlign(legendItem.textAlign || (legendItem.textAlign = labelOpts.textAlign));
const width = boxWidth + (fontSize / 2) + textWidth;
// lineWidth :
generateLabels(chart) {
const datasets = chart.data.datasets;
- const {labels: {usePointStyle, pointStyle, textAlign}} = chart.legend.options;
+ const {labels: {usePointStyle, pointStyle, textAlign, color}} = chart.legend.options;
return chart._getSortedDatasetMetas().map((meta) => {
const style = meta.controller.getStyle(usePointStyle ? 0 : undefined);
return {
text: datasets[meta.index].label,
fillStyle: style.backgroundColor,
+ fontColor: color,
hidden: !meta.visible,
lineCap: style.borderCapStyle,
lineDash: style.borderDash,
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
fillStyle: '#f31',
+ fontColor: '#666',
hidden: false,
lineCap: undefined,
lineDash: undefined,
}, {
text: 'dataset2',
fillStyle: 'rgba(0,0,0,0.1)',
+ fontColor: '#666',
hidden: true,
lineCap: undefined,
lineDash: undefined,
}, {
text: 'dataset3',
fillStyle: 'rgba(0,0,0,0.1)',
+ fontColor: '#666',
hidden: false,
lineCap: undefined,
lineDash: undefined,
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
fillStyle: '#f31',
+ fontColor: '#666',
hidden: false,
lineCap: 'round',
lineDash: [2, 2],
}, {
text: 'dataset2',
fillStyle: 'rgba(0,0,0,0.1)',
+ fontColor: '#666',
hidden: true,
lineCap: 'butt',
lineDash: [],
}, {
text: 'dataset3',
fillStyle: 'rgba(0,0,0,0.1)',
+ fontColor: '#666',
hidden: false,
lineCap: 'butt',
lineDash: [],
expect(chart.legend.legendItems).toEqual([{
text: 'dataset3',
fillStyle: 'rgba(0,0,0,0.1)',
+ fontColor: '#666',
hidden: false,
lineCap: 'butt',
lineDash: [],
}, {
text: 'dataset2',
fillStyle: 'rgba(0,0,0,0.1)',
+ fontColor: '#666',
hidden: true,
lineCap: 'butt',
lineDash: [],
}, {
text: 'dataset1',
fillStyle: '#f31',
+ fontColor: '#666',
hidden: false,
lineCap: 'round',
lineDash: [2, 2],
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
fillStyle: '#f31',
+ fontColor: '#666',
hidden: false,
lineCap: undefined,
lineDash: undefined,
}, {
text: 'dataset3',
fillStyle: 'rgba(0,0,0,0.1)',
+ fontColor: '#666',
hidden: false,
lineCap: undefined,
lineDash: undefined,
expect(chart.legend.legendItems).toEqual([{
text: 'dataset3',
fillStyle: 'rgba(0,0,0,0.1)',
+ fontColor: '#666',
hidden: false,
lineCap: 'butt',
lineDash: [],
}, {
text: 'dataset2',
fillStyle: 'rgba(0,0,0,0.1)',
+ fontColor: '#666',
hidden: true,
lineCap: 'butt',
lineDash: [],
}, {
text: 'dataset1',
fillStyle: '#f31',
+ fontColor: '#666',
hidden: false,
lineCap: 'round',
lineDash: [2, 2],
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
fillStyle: '#f31',
+ fontColor: '#666',
hidden: false,
lineCap: undefined,
lineDash: undefined,
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
fillStyle: 'rgb(50, 0, 0)',
+ fontColor: '#666',
hidden: false,
lineCap: undefined,
lineDash: undefined,
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
fillStyle: 'rgba(0,0,0,0.1)',
+ fontColor: '#666',
hidden: false,
lineCap: undefined,
lineDash: undefined,
}, {
text: 'dataset2',
fillStyle: '#f31',
+ fontColor: '#666',
hidden: false,
lineCap: undefined,
lineDash: undefined,
expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
fillStyle: 'rgba(0,0,0,0.1)',
+ fontColor: '#666',
hidden: false,
lineCap: undefined,
lineDash: undefined,
}, {
text: 'dataset2',
fillStyle: '#f31',
+ fontColor: '#666',
hidden: false,
lineCap: undefined,
lineDash: undefined,