Highcharts - 列颜色与图例中的颜色不同
Highcharts - column color different from color in legend
我已经为 highcharts 柱形图的系列数据定义了自定义颜色
data: [{y: 1234.5, color: '#234567'}, ...]
示例代码
var options = {
chart: {
type: 'column'
},
title: {
text: 'Period'
},
xAxis: {
categories: ['Cat 1', 'Cat 2'];
})
},
yAxis: {
min: 0,
title: {
text: null
}
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [
{
name: 'Dog',
data: [{y: 1, color: '#FF0000'}, {y: 1.45, color: '#FF0000'}]
},
{
name: 'Cow',
data: [{y: 2, color: '#CCCCCC'}, {y: 5.00, color: '#CCCCCC'}]
},
{
name: 'Bird',
data: [{y: 3, color: '#BBBBBB'}, {y: 3.45, color: '#BBBBBB'}]
},
]
};
然而,图例中的一列颜色与图片中相应列的颜色不同:
我看不出可以为 xAxis > 类别定义自定义颜色,但只能在数据输入中定义。
有什么想法吗?
您正在点级别而不是系列级别设置颜色。
这会将系列颜色保留为 Highcharts 默认颜色,尽管您的列是您想要的颜色。
系列颜色决定图例图标颜色。
所以这个:
name: 'Dog',
data: [{y: 1, color: '#FF0000'}, {y: 1.45, color: '#FF0000'}]
应该是:
name: 'Dog',
color: '#f00',
data: [1,1.45]
已更新 fiddle,颜色设置为 series
级别:
我已经为 highcharts 柱形图的系列数据定义了自定义颜色
data: [{y: 1234.5, color: '#234567'}, ...]
示例代码
var options = {
chart: {
type: 'column'
},
title: {
text: 'Period'
},
xAxis: {
categories: ['Cat 1', 'Cat 2'];
})
},
yAxis: {
min: 0,
title: {
text: null
}
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [
{
name: 'Dog',
data: [{y: 1, color: '#FF0000'}, {y: 1.45, color: '#FF0000'}]
},
{
name: 'Cow',
data: [{y: 2, color: '#CCCCCC'}, {y: 5.00, color: '#CCCCCC'}]
},
{
name: 'Bird',
data: [{y: 3, color: '#BBBBBB'}, {y: 3.45, color: '#BBBBBB'}]
},
]
};
然而,图例中的一列颜色与图片中相应列的颜色不同:
我看不出可以为 xAxis > 类别定义自定义颜色,但只能在数据输入中定义。
有什么想法吗?
您正在点级别而不是系列级别设置颜色。
这会将系列颜色保留为 Highcharts 默认颜色,尽管您的列是您想要的颜色。
系列颜色决定图例图标颜色。
所以这个:
name: 'Dog',
data: [{y: 1, color: '#FF0000'}, {y: 1.45, color: '#FF0000'}]
应该是:
name: 'Dog',
color: '#f00',
data: [1,1.45]
已更新 fiddle,颜色设置为 series
级别: