如何从x轴的特定点添加动态y轴。
suppose my x-axis values are (jan,feb,march....dec)
i want to generate y axis from Jun-dec (x-axis)
。
当我点击按钮但它生成 yaxis 并从x轴开始 jan-july 而不是 jun-dec
请参阅jsfiddle,您可以清楚地了解我的问题。
var chart = Highcharts.chart('container', {
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: 'Temperature'
},
lineWidth: 2,
lineColor: '#F33',
id: 'temperature-axis'
},
series: [{
name: 'Temperature',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6],
color: '#F33'
}]
});
// the button handlera
$('#add').click(function () {
chart.addAxis({ // Secondary yAxis
id: 'rainfall-axis',
title: {
text: 'Rainfall'
},
lineWidth: 2,
lineColor: '#08F',
opposite: true
});
chart.addSeries({
name: 'Rainfall',
type: 'line',
color: '#08F',
yAxis: 'rainfall-axis',
data: [135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
});
$(this).attr('disabled', true);
});

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="height: 400px"></div>
<button id="add" class="autocompare">Add axis and series</button>
<button id="remove" disabled="disabled" class="autocompare">Remove axis</button>
&#13;
答案 0 :(得分:2)
上述问题可以通过
解决 1&GT;使用null
值更新数组以匹配xAxis
类别
$('#add').click(function () {
chart.addAxis({ // Secondary yAxis
id: 'rainfall-axis',
title: {
text: 'Rainfall'
},
lineWidth: 2,
lineColor: '#08F',
opposite: true
});
chart.addSeries({
name: 'Rainfall',
type: 'line',
color: '#08F',
yAxis: 'rainfall-axis',
data: [null,null,null,null,null,null,135.6, 148.5, 216.4, 194.1, 95.6, 54.4] //update with null values
});
$(this).attr('disabled', true);
});
Fiddle演示
2 - ;使用pointStart从要开始的值传递额外参数。
$('#add').click(function () {
chart.addAxis({ // Secondary yAxis
id: 'rainfall-axis',
title: {
text: 'Rainfall'
},
lineWidth: 2,
lineColor: '#08F',
opposite: true
});
chart.addSeries({
name: 'Rainfall',
type: 'line',
color: '#08F',
yAxis: 'rainfall-axis',
pointStart: 6, //start point
data: [135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
});
$(this).attr('disabled', true);
});
Fiddle演示
答案 1 :(得分:1)