我正在从高级图表库制作饼图。我想在饼图中更改每个切片的颜色 我怎样才能做到这一点 ?我的代码是 -
var colors = ["color:'#2a8482'","color:'#64DECF'","color:'#BCCDF8'"];
var responseData = {"2":40,"1":30}
var obj = $.parseJSON(responseData);
var dataArrayFinal = Array();
var value = Array();
var name = Array();
var j = 0;
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
name[j] = "name:'"+key+"'";
value[j] = obj[key];
j++;
}
}
for(k=0;k<name.length;k++) {
var temp = new Array(name[k],value[k],colors[k]);
dataArrayFinal[k] = temp;
}
$(function () {
new Highcharts.Chart({
chart: {
renderTo: 'container'+counter,
type: 'pie',
height: 280,
width: 280
},
title: {
text: ' '
},
tooltip: {
valueSuffix: '%',
positioner: function () {
return {
x: this.chart.series[0].center[0] -
(this.label.width / 2) + 8,
y: this.chart.series[0].center[1] -
(this.label.height / 2) + 8
};
}
},
series: [{
name: 'Answer',
size: '100%',
innerSize: '65%',
data: dataArrayFinal
}]
});
});
此图表即将出现,但颜色不会改变。他们采用默认颜色。
答案 0 :(得分:2)
Highcharts.setOptions({
colors: ['#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4']
});
它应该这样工作; - )
答案 1 :(得分:1)
如果您将颜色数组更改为:
var colors = ["#2a8482","#64DECF","#BCCDF8"];
然后在你的函数的开头:
$(function () {
添加以下代码:
Highcharts.getOptions().plotOptions.pie.colors = colors;
这应该可以解决问题。
着色的例子可以在这个由HighCharts的开发者创建的JSFiddle中找到: http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/pie-monochrome/