【问题标题】:How to change background color in ng2-charts如何更改 ng2-charts 中的背景颜色
【发布时间】:2019-04-29 20:49:30
【问题描述】:

我正在使用 ng2-charts 绘制堆积条形图。但我无法更改条形图的默认背景颜色。

Stackblitz link

尝试将背景颜色属性添加到图表数据集,但它不起作用。

更新: 工作演示:stackblitz

【问题讨论】:

    标签: angular chart.js ng2-charts


    【解决方案1】:

    在我看来,colors 属性可以选择这样做。 只需传递一组颜色对象 (refer here to see the object)

    here is a working example

    像这样在 HTML 中添加输入:

    <div style="display: block;">
       <canvas baseChart 
          [datasets]="barChartData"
          [labels]="barChartLabels"
          [options]="barChartOptions"
          [plugins]="barChartPlugins"
          [legend]="barChartLegend"
          [chartType]="barChartType"
          [colors]="colors">//<---------------the colors input property
       </canvas>
    </div>
    

    然后在你的 ts 文件中添加下一个对象:

      public colors = [
        { backgroundColor:"red" },
        { backgroundColor:"green" },
        { backgroundColor:"blue" },
        { backgroundColor:"yellow" }
      ];
    

    【讨论】:

    • 工作。谢谢
    • 很高兴看到。这是我的荣幸。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 2020-09-08
    • 2011-11-11
    • 1970-01-01
    • 2021-12-08
    相关资源
    最近更新 更多