score:2

Accepted answer

have you tried parsing your data (string) into a javascript object before setting it to the series[i].data?

series : [{          
            data: json.parse(data)
        }]

what you are getting from php through $.get is basically string and not a javascript array of array of numbers, which is what you want. it may look like that, but it is as simple as "5"!=5, but parseint("5")==5 same is the case with json objects, you need to parse the string into such an object before javascript or highcharts can interpret it correctly, highcharts could do it on your behalf, but it is not designed that way.

try his fiddle to get an idea of the data types in picture

var data="[[1362639600000, 8],[1362726000000, 20],[1362985200000, 28],[1363071600000, 51],[1363158000000, 64],[1363244400000, 11],[1363330800000, 4],[1363503600000, 4],[1363590000000, 21],[1363676400000, 10],[1363762800000, 31],[1363849200000, 13],[1363935600000, 17],[1364194800000, 10],[1364454000000, 1],[1365058800000, 30],[1365145200000, 10],[1366009200000, 55],[1366182000000, 18],[1366268400000, 22],[1366354800000, 12]]"
console.log(typeof data);    //string
var parseddata=json.parse(data);
console.log(typeof parseddata);    //object
console.log(typeof parseddata[0]);    //object [1362639600000, 8]
console.log(typeof parseddata[0][0]);    //number 1362639600000

when you paste the console value directly in the fiddle, you are actually pasting it as a valid javascript array, try using your console value wrapped by " quotes " and see that the exact issue is reproduced!!

demo @ jsfiddle

an alternate approach could be using the $.getjson() method instead. jquery does the parsing for you before it calls your callback method

score:-1

your problem is in either the output from the php script or when you receive the data in your javascript (quite obvious).

first, don't do json by hand use json_encode (http://php.net/manual/en/function.json-encode.php). it's easier and it will guarantee that strings will be escaped properly.

secondly, inspect your data variable with a debugger. you could also post the exact content of the variable to the question.

but basically, as long as it is working in the fiddle and not in your program you have not yet reproduced the error in your code properly in the fiddle.

for instance, you could replace data in your callback with the data you have in your fiddle to see if the code runs.


Related Query

More Query from same tag