【问题标题】:Chart.js canvas change label colorChart.js 画布更改标签颜色
【发布时间】:2018-10-02 03:01:10
【问题描述】:

在 html 中定义图表:

<div class="chart">
        <canvas
          baseChart
          [chartType]="'line'"
          [datasets]="chartData"
          [labels]="chartLabels"
          [options]="chartOptions"
          [legend]="true"
          (chartClick)="onChartClick($event)">
        </canvas>
      </div>

如何更改 html 中标签的颜色?

【问题讨论】:

    标签: javascript html css


    【解决方案1】:

    您可以通过以下方式更改图例标签的字体颜色... 在ts集合中

    chartOptions.options.legend.labels.fontColor= 'white'; //set your desired color
    

    在你的情况下:

    chartOptions =  { 
        responsive: true, 
        maintainAspectRatio: false, 
        fontColor: 'red',
        options:{
            legend:{
                labels:{
                    fontColor:'white';//change the color
                }
            }
        }
    };
    

    【讨论】:

    • 在我的 TS 文件中得到:chartOptions = { responsive: true, maintainAspectRatio: false, fontColor: 'red' };
    猜你喜欢
    • 2018-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    • 2018-10-08
    • 2014-08-15
    相关资源
    最近更新 更多