Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

357
Views
Highcharts data from a variable is not working but from works fine from an array

I am very new to JavaScript and Highcharts so thank you in advance. I am trying to create a simple chart using Highcharts. When I manuayy create the variable using this array the chart works:

let result = [1084.58,1084.65,1084.64]

However, when when I grab the data from JSON and put that into the variable the chart does not show the data. If I "alert" the variable that is created from the JSON is appears like this:

1084.58,1084.65,1084.64

I am guessing the format of the data from the JSON is not correct. What should I do to correct it?

When I use the manually created variable the chart appears correctly. When I create the variable from the JSON file the chart appears and the X axis has the correct labels but no data in the chart.

I did some testing and found what I think is the issue. The variable that is created from the JSON has quotes around each entry. How can I remove the quotes?

['1084.58', '1084.65', '1084.64']
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You'll probably need to convert those values to Number type (using Number() or parseFloat()), you can do something like this:

variable => contains ['1084.58', '1084.65', '1084.64']

variable = variable.map(number => {return Number(number)})

Since you're new to Javascript (Welcome to this language!), I'm gonna explain how it works. "map" is an array method which takes each element of an array and returns an value (simillar to forEach method, but forEach doesn't return anything). So when using map to return each element of an array like this you're pushing the new element to the new array, it will be something like

variable.map(number => {return Number(number)})

On the 1st element: It returns Number('1084.58'), then it returns 1084.58 (number type)

On the 2nd element: It returns Number('1084.65'), then it returns 1084.65 (number type)

On the 3rd element: It returns Number('1084.64'), then it returns 1084.64 (number type)

Each return into this new variable is like an array.push(element)

Hope you got the idea

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!