我想通过类别属性在数据的y轴上显示。我在一些例子中看到了传递数组
initLapChart() {
hcharts.chart(this.div.nativeElement, {
chart: {
...
},
yAxis: {
categories: ["0:20", "0:30", "0:40", "1:00", "1:15"],
reversed: true,
tickPixelInterval: 50,
gridLineWidth: 1,
...
},
...
}
但它只显示前两个值,为什么?
答案 0 :(得分:0)
categories
数组中的元素从0
索引到categories.length - 1
,因此数组中的第一个元素表示yAxis上的值0,第二个值表示值1等。如果您要全部显示它们,您需要设置值为1的tickInterval
和labels.step
属性。
API参考:
http://api.highcharts.com/highcharts/yAxis.tickInterval
http://api.highcharts.com/highcharts/yAxis.labels.step
答案 1 :(得分:0)
如果要显示所有类别,无论是否有数据,只需设置轴最小值和最大值:
yAxis: {
min: 0,
max: 4,
reversed: true,
tickInterval: 1,
categories: ['0:20', '0:30', '0:40', '1:00', '1:15'],
labels: {
step: 1
}
},
更新了小提琴:
如果您预先定义类别,则可以通过编程方式执行此操作:
var categories = ['0:20', '0:30', '0:40', '1:00', '1:15'],
yMax = categories.length -1;
小提琴: