RoundSparrow hilltx
RoundSparrow hilltx

Reputation: 799

Highcharts dynamic-update example - adding 1 new value every second - without historic data

Using this example code:

http://www.highcharts.com/stock/demo/dynamic-update

NOTE: There is a link to jsfiddle.net on that page to view the code.

I find that this code example does two basic things: A) it primes with 1000 random values right as the graph loads, B) it adds a new random item each 1 second.

The problem is when I have no available historic data to populate the initial load, and start with an empty [] series dataset. The graph doesn't appear or ends up all out of scale. This example's behavior seems dependent on the 1000 values being populated before adding new values.

Does anyone understand my question / problem?

Upvotes: 1

Views: 531

Answers (1)

Halvor Holsten Strand
Halvor Holsten Strand

Reputation: 20536

The addPoint function in your example shifts out the first point when adding a new one, to keep the total number of points at the same value. This is unnoticeable at 1000 points, but if you only have 1 point it will look odd.

The addPoint method signature is (API):

addPoint (Object options, [Boolean redraw], [Boolean shift], [Mixed animation])

In the example the code is:

series.addPoint([x, y], true, true);

To remove the shift, remove (or set to false) the third parameter:

series.addPoint([x, y], true);

Or to dynamically keep it at a specific value you could:

shift = series.data.length >= 1000 ? true : false;
series.addPoint([x, y], true, shift);

Upvotes: 1

Related Questions