Chart.js如何编辑标题标签颜色

clj7thdc  于 2022-12-13  发布在  Chart.js
关注(0)|答案(1)|浏览(141)

我在一个项目上工作,我显示股票图表,一切工作正常,但我找不到如何改变图表上方的标题颜色,如这里:"AAPL" here
这是我目前的代码:

public renderChart(xData, yData, symbol){
    this.chart = new Chart("canvas" + symbol, {
      type: "line",
      data : {
        labels: xData,
        datasets: [{
          label: symbol,
          data: yData,
          backgroundColor: "#fdb44b",
          borderColor: "#00204a",
        }
        ]
      },
      options: {
        responsive: true,
        maintainAspectRatio: false,
        scales: {
          y: {
            ticks: { color: '#f5f5f5'}
          },
          x: {
            ticks: { color: "#f5f5f5" }
          }
        }}
    })
  }

任何帮助都是感激不尽的!

x4shl7ld

x4shl7ld1#

“AAPL”不是图表标题,而是图例的标签。
要更改该颜色,请将以下代码放入选项块中。

options: {
      plugins: {
        legend: {
          labels: {
            color: 'red'
          }
        }
      },
   ...
   }

https://www.chartjs.org/docs/latest/configuration/legend.html

相关问题