Reputation: 51
When i tried to pass the string value(data) to highchart series, it return blank chart. How to use the String value in series in highchart jquery plugin.
var data="{name: 'Jane',data: [1, 0, 4]},{name: 'John',data: [5, 7, 3]},{name: 'RAHUL', data: [1, 5, 4]}";
$('#container').highcharts({
chart: {
type: 'bar'
},
title: {
text: 'Fruit Consumption'
},
xAxis: {
categories: ['Apples', 'Bananas', 'Oranges']
},
yAxis: {
title: {
text: 'Fruit eaten'
}
},
series:[data]
});
Note: the data will be passed as dynamic.
Check this : http://jsfiddle.net/prathi89/FDjq7/26/
Upvotes: 2
Views: 2214
Reputation: 8715
JSON.parse()
is not working for you as your data is not a valid JSON string.
There is a trick, however, to force JavaScript to parse that kind of strings:
var data="{name: 'Jane',data: [1, 0, 4]},{name: 'John',data: [5, 7, 3]},{name: 'RAHUL', data: [1, 5, 4]}";
console.log(Function("return [" + data + "];")());
This is not clean and considered harmful, so if you can get your data in a valid JSON format - do it instead.
http://jsfiddle.net/neustroev_ai/FDjq7/27/
Upvotes: 1