I have a simple javascript/jquery code which requests a data from some web service which returns the data which can be used to create a highcharts bar chart. The response from the server can't be parsed into JSON as it contains a click event handler which fails to be parsed by JSON.parse with error Unexpected keyword ....
The javascript code looks like this
$.ajax({
type:"POST",
url:"service/call"
}).done(function( xdata ) {
// this is not going to work as xdata is not object but plain text
$('#container').highcharts(xdata);
});
The response from the server is like
{
"chart" : {
"type" : "bar"
},
"series" : [ {
"data" : [ 25, 10 ]
} ],
"title" : {
"text" : ""
},
"xAxis" : [ {
"categories" : [ "data1", "data2"],
"allowDecimals" : false
} ],
"yAxis" : [ {
"title" : {
"align" : "high",
"text" : "Some Title"
},
"allowDecimals" : false,
"labels" : {
"overflow" : "justify"
},
"min" : 0
} ],
"credits" : {
"enabled" : false
},
"plotOptions" : {
"bar" : {
"colors" : [ "#87bdee", "#ffcccc"],
"colorByPoint" : true,
"dataLabels" : {
"enabled" : true
},
"point" : {
"events" : {
"click" : function(){window.location.href = '/data?type=' + (this.x == 0 ? 'data1' : (this.x == 1 ? 'hold' : (this.x == 2 ? 'data2' : (this.x == 3 ? 'data3' : (this.x == 4 ? 'data4' : (this.x == 5 ? 'data5' : (this.x == 6 ? 'data6' : 'data7')))))) )}
}
}
}
},
"tooltip" : {
"valueSuffix" : " elements"
},
"creditOptions" : {
"enabled" : false
}
}
I have access to both server and client side code.
So is there a easy way a making things work ? I mean how can I create the highchart without changing the response ?