我需要大幅添加点
但保持数据的长度相同
我用
chart.series[i].addPoint(1 * 5, false, true);
实现#1
但我找不到一个API来添加点到最后一点的开头。
$("#prev").click(function(){
chart.xAxis[0].setCategories(['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas', 'Lemon']);
for (var i = 0; i < chart.series.length; i++)
{
chart.series[i].data[4].remove(false);
//TODO add point to the head
}
chart.redraw();
});
这是jsfiddle:http://jsfiddle.net/bvuWR/187/
答案 0 :(得分:0)
问题解决了:
以下是演示:http://jsfiddle.net/wesu4daz/3/
Code Snippets:
//add point to last
$('#add').off('click').on('click',function(){
var next = parseInt($(this).attr('end'),10)+1;
var prev = parseInt($('#prev').attr('start'),10)+1;
var chart = $('#container').highcharts();
//IMPORTANT to update categories before add point to the head
var newCategories = $.merge([],chart.xAxis[0].categories);
newCategories.push('new'+(newCategories.length))
chart.xAxis[0].setCategories(newCategories);
chart.series[0].addPoint({x:next,y:next},false,true);//add to last
chart.redraw();
$(this).attr('end',next);
$('#prev').attr('start',prev);
});
//remove last point and add point to head
$('#prev').off('click').on('click',function(){
var next = parseInt($('#add').attr('end'),10)-1;
var prev = parseInt($('#prev').attr('start'),10)-1;
var chart = $('#container').highcharts();
console.log(chart.xAxis[0]);
chart.series[0].data[3].remove(false);
chart.series[0].addPoint({x:prev,y:prev},false,false);
chart.redraw();
$('#add').attr('end',next);
$('#prev').attr('start',prev);
});