It is currently Fri Oct 31, 2014 6:51 am Advanced search

Changing data in a series causes y_axis to blow up

Technical support, bug reports and more.

Changing data in a series causes y_axis to blow up

Postby earachefl » Tue Nov 22, 2011 9:13 pm

I think I'm probably doing this wrong, but can't figure out the problem. I'm seeing some odd behavior in a Highcharts line chart. I have multiple series displayed, and need to let the user change what's called the "Map level" on the chart, which is a straight line across all time periods. Assuming that the correct series is

Code: Select all
chart.series[i]


and that the new level that I want it set to is stored in var newMapLevel,
I'm changing that series' data like so:

Code: Select all
 data = chart.series[i].data;
   for(j=0; j<data.length; j++){
      data[j].y = newMapLevel;               
   }
   chart.series[i].setData(data);


Calling this function has the desired effect UNLESS the new map level y_value is ONE greater than the highest y_value of all other series, in which case the y-axis scale blows up. In other words, if the y_axis scale is normally from 0 to 275,000, and the highest y_value of any of the other series is, say, 224,000, setting the new map level value to 224,001 causes the y_axis scale to become 0 to 27500M. Yes, that's 27.5 billion.

I've created a fiddle:

http://jsfiddle.net/earachefl/4FuNE/4/
earachefl
 
Posts: 3
Joined: Tue Nov 22, 2011 9:08 pm

Re: Changing data in a series causes y_axis to blow up

Postby torstein.honsi » Fri Nov 25, 2011 1:25 pm

You must parse the incoming value as a number, else JavaScript treats it as a string and concatenates the numbers instead of adding them. See http://jsfiddle.net/highcharts/4FuNE/5/, enter the number 4 into the box.
Torstein Hønsi
CTO, Founder
Highsoft Solutions
User avatar
torstein.honsi
Site Admin
 
Posts: 9200
Joined: Thu Nov 09, 2006 1:22 pm
Location: Vik i Sogn, Norway

Re: Changing data in a series causes y_axis to blow up

Postby earachefl » Fri Nov 25, 2011 4:43 pm

Thanks so much for the help. I am still a bit confused as to exactly what is happening though - when you say that js is concatenating the numbers, what is getting concatenated? In my example, I'm just getting a value (as a string originally) and assigning its value to data[j].y. Where is the concatenation happening?

EDIT: Oh, I think I get it - Highcharts is internally concatenating the new number with the existing series high points to set the maximum - so if the high point of the other series is 3, and the new number is "4", it thinks the new high point is 43, and sets the high point of the scale to 50. If this is the case, why not have Highcharts automatically parse the number instead of leaving it to the implementer?

EDIT: Actually, I still don't quite get it - even if you were adding the high points together, 4+3 would still be 7, which would set the new high scale higher than it shows in your example - so I'm still confused as to exactly what is happening.

Also, I was curious as to why although the original series shows the individual data points, the same series after having new data assigned to it no longer shows the individual points.

Thanks again.
earachefl
 
Posts: 3
Joined: Tue Nov 22, 2011 9:08 pm

Re: Changing data in a series causes y_axis to blow up

Postby hfrntt » Tue Nov 29, 2011 2:14 am

I suppose that it occurs because you used "series.data" to get current data points. It's good solution but not when you want to reuse this array in setData. See modified example: http://jsfiddle.net/hfrntt/4FuNE/7/
Slawek Kolodziej
Highcharts support team
hfrntt
 
Posts: 6394
Joined: Mon Aug 30, 2010 10:41 am


Return to Highcharts Usage

Who is online

Users browsing this forum: Google [Bot] and 6 guests