1

I have searched and searched but i'm unable to find the solution yet.

I'm trying to load data into Highcharts with json from my server. This is the json returned from my server:

   [{
    "x": "\/Date(1352674800000)\/",
        "y": 621
}, {
    "x": "\/Date(1352761200000)\/",
        "y": 646
}, {
    "x": "\/Date(1352847600000)\/",
        "y": 690
}, {
    "x": "\/Date(1352934000000)\/",
        "y": 688
}, {
    "x": "\/Date(1353020400000)\/",
        "y": 499
}]

this is my highchart: (from my jsfiddle)

    var seriesData = [];
for (var i = 0; i < data.length; i++) {
   var dateString = data[i].x;
var x = dateString.replace(/\/Date\((\d+)\)\//, '$1');


    var y = data[i].y;


    seriesData.push([x, y]);

}
alert(seriesData);

var options = {
    chart: {
        renderTo: 'container'
    },
    xAxis: {        
        type: 'datetime',
        labels: {
            formatter: function() {
            var monthStr = Highcharts.dateFormat('%a', this.value);
            var firstLetter = monthStr.substring(0, 1);
            return firstLetter;
            }
        }
    },



    series: []
};

function myfunk() {
   options.series.push(seriesData);



    chart = new Highcharts.Chart(options);
}
myfunk();

but my data is not showing.

i made a jsfiddel: http://jsfiddle.net/grVFk/12105/

Edit:

Now it's working but is the data point showing the wrong dates? http://jsfiddle.net/dxCHB/18/

If someone could help me i would be very grateful ! :)

2 Answers 2

2

You were very close. The series array needs to contain an object with a data member:

 series: [
    {
       data:[]
    }
 ]

You can then set it using:

function myfunk() {
    options.series[0].data = seriesData;

I modified your jsfiddle: http://jsfiddle.net/dxCHB/

Format your date numerically

seriesData.push([x/1, y]);
Sign up to request clarification or add additional context in comments.

4 Comments

Lol. I've seen you around on the highcharts questions. You've posted some good answers.
Thanks @SteveP. I use HighCharts every day at my job, decided I should probably start helping people on here if I can. I'm definitely not a master, but I try.
Thx SteveP! But how do i get it to display date/weekday on the x axis? Why is this not working? jsfiddle.net/dxCHB/10
Your date data needs to numerical, not a string. X/1 forces it to be a number.
0

Your data should be number, so you can use parseFloat() function to transform string to number.

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.