【发布时间】:2015-02-11 18:33:05
【问题描述】:
我认为这将是一件相当普遍的事情,但我无法在任何地方找到示例。我想比较 2 个不同日期范围的 3 个系列数据,并在条形图中查看它们彼此相邻。看图更容易理解:
不幸的是,我唯一能想到的就是添加一个 HIDDEN 系列,然后在高图之外的 html 中做我的图例。请告诉我有更好的方法来做到这一点。这是我想出的例子。
$(function () {
$('#container').highcharts({
chart: {
type: 'bar'
},
title: {
text: 'Safe Places To Visit'
},
xAxis: {
categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Survey Count',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
},
series: {
dataLabels: {
enabled: false
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
shadow: true
},
credits: {
enabled: false
},
series: [{
name: 'Recommend',
data: [107, 31, 635, 203, 2]
}, {
name: 'Recommend W/ Comp',
data: [133, 156, 947, 408, 6]
}, {
name: 'Dont Recommend',
data: [973, 914, 4054, 732, 34]
}, {
name: 'HIDDEN',
data: [0, 0, 0, 0, 0]
}, {
name: 'Recommend',
data: [107, 31, 635, 203, 2]
}, {
name: 'Recommend W/ Comp',
data: [133, 156, 947, 408, 6]
}, {
name: 'Dont Recommend',
data: [973, 914, 4054, 732, 34]
}]
});
});
你可以看到小提琴here。
【问题讨论】:
-
您是否尝试将隐藏系列类型更改为“区域”?它将保留在图例中,但不会占用图表中的空间。
标签: javascript jquery highcharts