Chart.js : legend label with several curves #12156
Replies: 1 comment
-
|
The Replace your flat font props with a generateLabels: function(chart) {
const datasets = chart.data.datasets;
return datasets.map((dataset, i) => {
return {
text: dataset.label,
fillStyle: dataset.borderColor,
strokeStyle: dataset.borderColor,
fontColor: (i === 0) ? "red" : "green",
font: {
family: (i === 0) ? "Arial" : "sans-serif",
style: (i === 0) ? "italic" : "normal",
weight: (i === 0) ? "bold" : "normal",
size: (i === 0) ? 20 : 12
},
datasetIndex: i
};
});
}The reason See the LegendItem interface in the docs for the full list of supported properties. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone !
I want to create a graph containing two 'line' type curves.
My difficulty is that I want to be able to use a different font for the legend label of the first curve than for the second curve.
The result is that I get both curves correctly, but the font is the same for both labels. The code only works for the text color, but it doesn't change the size, style, or weight.
What is wrong in this code ?
Thanks in advance for your help.
Here is the code I'm using :
Beta Was this translation helpful? Give feedback.
All reactions