0

I am using Firebase Realtime Database to get data to render in Highchart. I have declared an empty array.

    arrY = [];

And then inside a function, I push the value for x-axis along with a timestamp to the array.

   arrY.push([time, parseFloat(tempC)]);

Then when initiating the Highchart when I assign the array to the series, the chart is not rendered (no error message in the console)

           series: [{
                name: 'Temperature',
                data: arrY
            }]

However, If I hardcode an array with it's value and timestamp and assign it to the highchart it gets rendered

    a = [[1591815122, 28],[1591815141, 28],[1591815161, 28],[1591815180, 28],[1591815200, 28]];

and

           series: [{
                name: 'Temperature',
                data: arrY
            }]

when I log both the array in the console both are displayed as arrays but why is one working and the other one not working? Console Output in the picture below

Console Output

1 Answer 1

1

The problem which you are struggling to is related to JavaScript Asynchronous. Notice that when you console.log the arrY it is an empty array. You need to delay the chart rendering until the data will be downloaded from the server.

Currently, something like this happens:

  1. The array is defined,
  2. The chart is rendering with an empty array,
  3. Data is downloaded and pushed to the array,
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.