我正在尝试绘制柱形图/条形图,如 JSFiddle 所示: http://jsfiddle.net/qh17f7ao/1/
这是我的 Highcharts 数据:
series: [{
name: 'Tokyo',
data: [['Jan',49.9], ['Feb', 71.5], ['Mar', 91]]
}, {
name: 'New York',
data: [['Jan',83.6], ['Feb',78.8], ['Apr',100]]
}, {
name: 'London',
data: [['Mar',83.6], ['Jun',78.8], ['Aug',100]]
}, {
name: 'Berlin',
data: [['Jan',83.6], ['Apr',78.8], ['Sep',100]]
}]
如果您查看 x 轴类别,我会列出范围广泛的月份,例如一月、二月、三月、四月、六月、八月、九月。
但是,当我将数据传递给 Highcharts 进行渲染时,轴不一致并且缺少特定的数据点。
最佳答案
这里可以说很多,但我认为这行来自 the API总结一下:
If the xAxis.type is set to category, and no categories option exists, the category will be pulled from the
point.name
of the last series defined. For multiple series, best practice however is to definexAxis.categories
.
因此,我最好的建议就是这样做。不要使用名称,使用 categories
。
例如 ( JSFiddle ):
$('#container').highcharts({
xAxis: {
categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
},
series: [{
name: 'Tokyo',
data: [[0,49.9], [1, 71.5], [2, 91]]
}, {
name: 'New York',
data: [[0,83.6], [1,78.8], [3,100]]
}, {
name: 'London',
data: [[2,83.6], [5,78.8], [7,100]]
}, {
name: 'Berlin',
data: [[0,83.6], [3,78.8], [8,100]]
}]
});
关于javascript - Highcharts:使用类别时 x 轴不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30226095/