5

我的图表定义为:

  <canvas #chart baseChart
              [data]="_chartData"
              [labels]="_chartLabels"
              [chartType]="_chartType"
              [colors]="_backgroundColors">
  </canvas>

我将颜色指定为:

private _backgroundColors:string[] = ["#345657", "#112288", "#adf444"];

一切正常,但颜色。如果我传入这个数组,所有颜色都显示为相同的颜色,浅灰色。任何人都看到什么可能是错的?

4

3 回答 3

5

可以在这里找到解决方案。目前没有记录。

它需要是这样的:

[{backgroundColor: ["#e84351", "#434a54", "#3ebf9b", "#4d86dc", "#f3af37"]}]
于 2017-02-07T21:04:16.610 回答
2

我同意上面的答案,如果有人需要,我想提供详细信息。我的例子是在饼图中它也适用于其他人。

步骤1:

在您的 component.ts 文件中添加以下内容

     public pieChartColors: Array < any > = [{
       backgroundColor: ['#fc5858', '#19d863', '#fdf57d'],
       borderColor: ['rgba(252, 235, 89, 0.2)', 'rgba(77, 152, 202, 0.2)', 'rgba(241, 107, 119, 0.2)']
   }];

第2步 :

您的 component.html 应如下所示:

   <canvas baseChart 
                [data]="pieChartData" 
                [labels]="pieChartLabels" 
                [chartType]="pieChartType"
                [options]="pieChartOptions"
                [plugins]="pieChartPlugins"
                [legend]="pieChartLegend"
                [colors]="pieChartColors"
                (chartHover)="chartHovered($event)"
                (chartClick)="chartClicked($event)"
                >
              </canvas>
于 2020-06-30T08:04:15.380 回答
1

它应该是这样的:

[
   {
      backgroundColor:"#ffa954",

   },
   {
      borderColor:"#589b00",

   }
]

每个对象代表dataSets数组中的相应对象

于 2017-02-07T17:04:59.777 回答