admin管理员组文章数量:1334704
I'm using Chart.js and I'm trying to change the legend output. At the moment I have this code:
chart.options.plugins.legend.labels.generateLabels = (chart) => {
const labels = [
{ text: `${dataset.label}`, fillStyle: dataset.borderColor },
{ text: `Last: ${lastValue}`, fillStyle: 'rgba(0, 0, 0, 0)' },
{ text: `Min: ${minValue}`, fillStyle: 'rgba(0, 0, 0, 0)' },
{ text: `Max: ${maxValue}`, fillStyle: 'rgba(0, 0, 0, 0)' },
{ text: `Avg: ${avgValue}`, fillStyle: 'rgba(0, 0, 0, 0)' }
];
return labels;
};
I want to add additional lines (Last, Min, Max, Avg) under the main text (dataset.label value) so that they look like signatures.
I tried using \n
, but it doesn't work.
How to correctly add additional lines under the main text of the legend in the Chart.js? Or is there a way to discard the legend and just add text under the graph?
I'm using Chart.js and I'm trying to change the legend output. At the moment I have this code:
chart.options.plugins.legend.labels.generateLabels = (chart) => {
const labels = [
{ text: `${dataset.label}`, fillStyle: dataset.borderColor },
{ text: `Last: ${lastValue}`, fillStyle: 'rgba(0, 0, 0, 0)' },
{ text: `Min: ${minValue}`, fillStyle: 'rgba(0, 0, 0, 0)' },
{ text: `Max: ${maxValue}`, fillStyle: 'rgba(0, 0, 0, 0)' },
{ text: `Avg: ${avgValue}`, fillStyle: 'rgba(0, 0, 0, 0)' }
];
return labels;
};
I want to add additional lines (Last, Min, Max, Avg) under the main text (dataset.label value) so that they look like signatures.
I tried using \n
, but it doesn't work.
How to correctly add additional lines under the main text of the legend in the Chart.js? Or is there a way to discard the legend and just add text under the graph?
Share Improve this question edited Nov 20, 2024 at 7:41 Sadra Saderi 3944 silver badges12 bronze badges asked Nov 20, 2024 at 7:28 MaximMaxim 115 bronze badges1 Answer
Reset to default 0When you are using literal `` than just do a new line literally and that it. Example:
(I'm using ""
in the example because it's show my answer as code temple, lol. Just use literal instead in your code)
const testStr = " Hello,
World! ";
console.log(testStr);
/*
Hello,
World!
*/
If you still don't see new line, than just add this in your css file (check in the browser inspect what the tag has those text value and add it there):
div .chart-text{
white-space: pre-line; or use
white-space: pre-wrap;
}
And you can also use the regular ""
with \n
, that can also works: "Last: \n" + lastValue
Let me know if it help you
本文标签: javascriptHow to move a legend to another lineStack Overflow
版权声明:本文标题:javascript - How to move a legend to another line? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742374659a2462921.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论