angular-chart.js基于图表标签值的自定义颜色

时间:2016-10-20 12:09:26

标签: chart.js angular-chart donut-chart

我正在使用angular-chart.js整合圆环图,我想根据图表标签值使用自定义颜色。

//Controller
    vm.labels = ["A", "B", "C"];
    vm.data = [1, 2, 3];

//HTML
    <canvas id="doughnut" class="chart chart-doughnut"
                        chart-data="vm.data" 
                        chart-labels="vm.labels"                    
                        chart-options="options"
                        chart-colors = "colours"
                        chart-legend = "true" >
    </canvas>

我正在设置颜色如下

ChartJsProvider.setOptions({
       colours: ['#DD1C2C', '#E03E2D','#E35B2B'],
       responsive: true
});

只有当所有A,B和C都在那里时才能完美(A => #DD1C2C B=> #E03E2DC=>#E35B2B

但是对于以下情况

$scope.labels = ["A", "C"];
$scope.data = [1, 3];

A => #DD1C2CC=>#E03E2D

预期:A => #DD1C2CC=>#E35B2B

1 个答案:

答案 0 :(得分:0)

您是否尝试使用空字符串填充缺少的部分,而像

那样填充0
$scope.labels = ["A", "", "C"];
$scope.data = [1, 0, 3];