我有一个柱状图,其中包含多个类别,每个类别只有一个数据点(例如这种类型)。是否可以更改每个类别的柱形图颜色?也就是说,每个柱形图都有自己独特的颜色,而不是所有柱形图都是蓝色吗?
我有一个柱状图,其中包含多个类别,每个类别只有一个数据点(例如这种类型)。是否可以更改每个类别的柱形图颜色?也就是说,每个柱形图都有自己独特的颜色,而不是所有柱形图都是蓝色吗?
如果你将数据数组更改为配置对象,而不是数字,则可以为每个点/条单独设置颜色。
data: [
{y: 34.4, color: 'red'}, // this point is red
21.8, // default blue
{y: 20.1, color: '#aaff99'}, // this will be greenish
20] // default blue
colors
中,然后将colorByPoint
设置为true
。colors: [
'#4572A7',
'#AA4643',
'#89A54E',
'#80699B',
'#3D96AE',
'#DB843D',
'#92A8CD',
'#A47D7C',
'#B5CA92'
],
plotOptions: {
column: {
colorByPoint: true
}
}
参考文献:
是的,这里有一个在jsfiddle上的示例:http://jsfiddle.net/bfQeJ/
Highcharts.setOptions({
colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4']
});
这个示例是一个饼图,但你可以随心所欲地用所有的颜色来填充系列 =)
$('#container').highcharts({
colors: ['#2f7ed8','#910000','#8bbc21','#1aadce'],
chart: {
type: 'column'
},
title: {
text: 'Stacked column chart'
},
如 antonversal 所提到的,通过阅读颜色并在创建图表对象时使用颜色选项即可实现。
var chart3 = new Highcharts.Chart({colors: ['#458006', '#B0D18C']});
只需放置图表
$('#container').highcharts({
colors: ['#31BFA2'], // change color here
chart: {
type: 'column'
}, .... Continue chart
只需添加这个...或者按照您的需求更改颜色。
Highcharts.setOptions({
colors: ['#811010', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'],
plotOptions: {
column: {
colorByPoint: true
}
}
});
colors: ['Red', 'Bule', 'Yellow']
这对我很有用。为一个系列设置所有颜色选项非常繁琐,特别是如果它是动态的。
plotOptions: {
column: {
colorByPoint: true
}
}