acid
acid

Reputation: 2149

Chart series fixed range

My chart consist of website statistics (time on x-axis, views on y-axis) and its series are updated by addPoint() method every fifteen minutes. However after gathering more and more data I don't want to show all of them, just limit them to one last hour.

To give you an example - if my series consist of data:

2013-08-21 12:15 2000
2013-08-21 12:30 3000
2013-08-21 12:45 2500
2013-08-21 13:00 2300
2013-08-21 13:15 2700
2013-08-21 13:30 3000

I want only have 2013-08-21 13:30 to 2013-08-21 13:30 on the graph.

Upvotes: 0

Views: 102

Answers (1)

Barbara Laird
Barbara Laird

Reputation: 12717

Everytime you add a point, I'd check if the 1st point was < however far back you want to go. If it is, remove it.

if (chart.series[0].data[0].x < time cutoff) {

    chart.series[0].data[0].remove();
}

Since you're doing a consistant time interval, you should be safe with just checking the 1st point.

http://api.highcharts.com/highcharts#Point.remove()

Another option based on the comments above:

var bShift = false;
if(!bShift && chart.series[0].data[0].x < time cutoff)  
    bShift = true;
chart.series[0].addPoint(point, true, bShift);

Upvotes: 2

Related Questions