I am trying to add the data into below function using jQuery (or highcharts). The question is how to embed the data into the javascript code without using eval since I will have to write all the code as string?
function pie(data)
{
$(function () {
$('#renderingdiv').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2010'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [**data**]
});
});
};
data looks like:
{\
type: 'pie',\
name: 'Statuses',\
data: [\
[WSCH, 377]\
,\
[WMATL, 4]\
,\
[WAPPR, 349]\
,\
[NCOMP, 3]\
,\
[INPRG, 56]\
,\
[COMP, 18]\
,\
[CLOSE, 697]\
,\
[APPR, 420]\
\
]\
}
Any idea please?
datasupposed to be a string literal? Then useJSON.parseinstead ofeval. If not, what are all those backslashes doing there? And how did you got them there in the first place? Remove them and you could just use the markup as a JS object literal.