我在使用高图中的不同ID为yAxis添加系列时遇到了一些问题。
我举了一个例子:
$(function () {
$('#graf').highcharts({
chart: {
zoomType: 'xy'
},
title: {
text: ''
},
subtitle: {
text: ''
},
xAxis: [{type: 'datetime',
title: {
text: 'Date'
}}],
yAxis: [],
series : []
,
tooltip: {
shared: true
},
legend: {
enabled: true,
align: 'left',
backgroundColor: '#FFFFFF',
borderColor: 'grey',
borderWidth: 1,
layout: 'vertical',
verticalAlign: 'top',
y: 0,
shadow: true
}
});
var chart = $('#graf').highcharts();
$('#add').click(function () {
chart.addAxis({ // Secondary yAxis
id: "asd",
title: {
text: 'Rainfall'
},
lineWidth: 2,
lineColor: '#08F',
opposite: true
});
chart.addAxis({ // Secondary yAxis
id: "abc",
title: {
text: 'Rainfall'
},
lineWidth: 2,
lineColor: '#08F',
opposite: true
});
chart.addSeries({
name: 'Rainfall',
type: 'column',
color: '#08F',
yAxis: "asd",
data: [ [Date.UTC(1970, 9, 27), 0 ],
[Date.UTC(1970, 10, 10), 0.6 ],
[Date.UTC(1970, 10, 18), 0.7 ],
[Date.UTC(1970, 11, 2), 0.8 ],
[Date.UTC(1970, 11, 9), 0.6 ]]
});
$(this).attr('disabled', true);
$('#remove').attr('disabled', false);
});
});
JSFIDDLE:http://jsfiddle.net/5f6b6mu9/
我有id“asd”和“abc”的yAxis。 当试图将系列添加到“asd”yAxis时它不起作用。 未捕获的TypeError:无法读取未定义的属性“长度”。
以下是我网页上的最新消息: http://i61.tinypic.com/8yx7cw.jpg
如果我将两个yaxis id更改为相同的id,它可以工作,但那不是重点。
有什么建议吗?感谢
答案 0 :(得分:1)
那非常简单。
在添加系列后立即添加与y轴对应的系列。
chart.addAxis({ // Secondary yAxis
id: "asd",
title: {
text: 'Rainfall'
},
lineWidth: 2,
lineColor: '#08F',
opposite: true
},false);
chart.addSeries({
name: 'Rainfall',
type: 'column',
color: '#08F',
yAxis: "asd",
data: [ [Date.UTC(1970, 9, 27), 0 ],
[Date.UTC(1970, 10, 10), 0.6 ],
[Date.UTC(1970, 10, 18), 0.7 ],
[Date.UTC(1970, 11, 2), 0.8 ],
[Date.UTC(1970, 11, 9), 0.6 ]]
});
chart.addAxis({ // Secondary yAxis
id: "abc",
title: {
text: 'Rainfall'
},
lineWidth: 2,
lineColor: '#08F',
opposite: true
},false);
我在这里更新了您的fiddle