michal
michal

Reputation: 758

highcharts series update in javascript

I am creating 5 separate charts and try to update them every few seconds with new series data. If I define just one function that creates new chart and add series data in constructor, it works, but the downside is that every page refresh with setInterval() destroys charts and rebuilds them, which looks terrible.

So I created two functions, CreateChart() called once, and UpdateChart() called on every setInterval() refresh. Now charts are empty and I get error on UpdateChart():

TypeError: FlightCharts[Index].series[0] is undefined

Link to javascript code
Link to example json series data

Any tips (I'm new to javascript)

thanks

Upvotes: 0

Views: 444

Answers (1)

Paweł Fus
Paweł Fus

Reputation: 45079

The problem is that you defined empty series:

series: []

Next you are trying to set data for a first series:

FlightCharts[Index].series[0]

Instead you should create that one series at least:

series: [{
  name: "MyName",
  data: []
}]

Upvotes: 1

Related Questions