Reputation: 3086
i'm new to highchart
using a default JSON value given by highchart team wrks fine here is the link
but however when i try to give input as JSON as a local variable shows nothing in the graph, here is the code
var myval = new Array();
myval [0] = "1146096000000,69.36";
myval [1] = "1146182400000,70.39";
myval [2] = "1146441600000,69.60";
/******* OR ******/
//var myval = [ [1146096000000,69.36], [1146182400000,70.39], [1146441600000,69.60]];
/***** DOESN'T WORk *****/
var obj = jQuery.parseJSON ( myval );
$.getJSON(obj, function(data) {
$('#container').highcharts('StockChart', {
rangeSelector : {
selected : 2
},
title : {
text : 'value graph'
},
series : [{
name : 'val 1',
data : data,
tooltip: {
valueDecimals: 2
}
}]
});
});
});
Upvotes: 0
Views: 676
Reputation: 19093
If you define myVal as:
var myVal = [ [1146096000000,69.36], [1146182400000,70.39], [1146441600000,69.60]];
then it is already json, and doesn't need to be parsed using parseJSON. You can simply set
data = myVal;
If myVal is defined as
var myval = new Array();
myval [0] = "1146096000000,69.36";
myval [1] = "1146182400000,70.39";
myval [2] = "1146441600000,69.60";
Then myval is a json object containing strings. You can either parse out each elemnt of the array (e.g. using split) or define it like this:
var myval = new Array();
myval [0] = [1146096000000,69.36];
myval [1] = [1146182400000,70.39];
myval [2] = [1146441600000,69.60];
in which case, it is also already a json object and won't need to be parsed.
The only time you need to parse JSON is if the original data is a string representation of a json object, e.g. when getting the data from an ajax call.
Upvotes: 1