如何更改折线图.js的标签颜色



我试着改变一种颜色的线条标签:

标签图片

线路设置:

const linedataset = {
type: 'line',
label: 'label',
data: xavarage,
order: 1,
borderColor: 'rgb(225, 54, 54)',
backgroundColor: lineBackground,
};

常见设置有:

const chartoptions = {
hoverBackgroundColor,
backgroundColor,
responsive: true,
scales: {
x: {},
y: {
min: 0,
},
},
plugins: {
title: {
display: true,
text: this.selectedCategory?.full,
font: {
size: 20,
},
},
datalabels: {
anchor: 'end',
align: 'end',
},
},
};

我已经尝试使用以下代码:

options: {
legend: {
color: "#ccc"
}
}

但它也不起作用。如何设置标签文本的颜色(线条图(?

您的图表使用chartjs插件数据标签。因此,您需要在datalabels中定义color,如下所示:

datalabels: {
color: '#ccc',
anchor: 'end',
align: 'end'
},

最新更新