我使用angular-chart.js,每当我绘制图表(任何类型,如条形或线条)时,我都会看到第一个数据集的图形颜色是灰色的。我确保颜色在绘制之前是随机的......
这是controller.js:
.controller('chartController', function($scope){
$scope.labels = ["January", "February", "March", "April", "May", "June", "July"];
$scope.series = ['Series A', 'Series B'];
$scope.data = [
[65, 59, 80, 81, 56, 51, 40],
[28, 48, 40, 19, 86, 27, 90]
];
$scope.colours = [{
fillColor:"rgba(220,220,220,0.4)",
strokeColor:"rgba(220,220,220,0.2)",
highlightFill:"rgba(220,220,220,0.5)",
highlightStroke:"rgba(220,220,220,0.1)"
}];
})
以下是实际输出:
答案 0 :(得分:1)
有了这个
$scope.colours = [{
fillColor:"rgba(220,220,220,0.4)",
strokeColor:"rgba(220,220,220,0.2)",
highlightFill:"rgba(220,220,220,0.5)",
highlightStroke:"rgba(220,220,220,0.1)"
}];
你正在通过角度图表一个colorset。由于您的图表中有2个数据集,因此角度图表将使用此colorset(即灰色)作为第一个数据集,而对于第二个数据集,它将生成随机颜色。
如果您想要随机(在每次重绘时随机化)两个数据集的颜色执行此操作
$scope.colours = [];
如果您想要两者都有固定颜色,请将其传递给2个颜色的数组(而不是1个)。如果要使用全局默认值,只需将其设置为null
$scope.colours = null;