user3515232
user3515232

Reputation: 133

Highcharts JSON decimal data format issue

I'm trying to solve an odd problem. I'm getting a json array back from an ajax call and I'm attempting to plot it in highcarts. I've mapped other graphs from the same array and all is well, up until the point I hit decimal numbers (maybe co-incidence). In this case the dates show fine but the y-axis (prices) is empty.

Now, I can 'alert(s5)' and the data displays on the alert box as it should. I also ran a consol log and see "["5.15", "4.94", "4.43", "4.49", "4.42", "4.41"]" (maybe the " in the numbers is causing the issue!?)

If I put the values manually into the highcharts data it works perfectly but I just can't assign the array to a value and get it to display.

code looks like:

    function draw_flow(garray)
    {

    var obj = JSON.stringify(garray);
    obj = JSON.parse(obj);
    s5 = obj["closeprice"][0];
    ticks = obj["date"][0];

alert(s5); //THIS DISPLAYS DATA FINE! "5.15,4.94,4.43,4.42,4.41"



          $('#chart3').highcharts({
                chart: {
                    marginBottom: 80
                },
                xAxis: {
                    categories: ticks
                },

                yAxis: {
                    labels: {
                        align: 'left',
                        x: 0,
                        y: -2
                    }
                },

                series: [{
                    data: s5 //This does not work
                    //data: [5.15,4.94,4.43,4.42,4.41] //this works
                }]
            });

        }

Upvotes: 2

Views: 288

Answers (2)

cjds
cjds

Reputation: 8426

You are correct. The reason the Y axis is not displaying is because of the Strings in your data. (which should be read as numbers)

You have to convert your data from Strings to an array of numbers which can be achieved with the following

s5 = s5.map(Number);

This is an example jsFiddle which shows it in action http://jsfiddle.net/e803sjsp/

Upvotes: 1

potatopeelings
potatopeelings

Reputation: 41065

A bit cheeky but have you checked that s5 is actually an array and not a string of comma separated values. You might want to try a console.log to be sure..

Upvotes: 0

Related Questions