ChartJS 如何改变标签颜色的折线图.js?

9gm1akwq  于 2022-11-06  发布在  Chart.js
关注(0)|答案(1)|浏览(165)

我试着改变线标签的颜色:
exmaple of label pic
该行具有以下设置:

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"
   }
}

但它不工作太。如何设置颜色的标签文本(线图形)?

jaql4c8m

jaql4c8m1#

您的图表使用chartjs-plugin-datalabels。因此,您需要在datalabels中定义color,如下所示:

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

相关问题