2
  function b(data){
           document.write(data);
          $('#graphContainer').highcharts(data);
      }

I need to pass JSON to .highcharts() API.

Using document.write() i have printed that the value of data is:

{"chart" : { "type" : "line"} , "title" : { "text" : "First Time Fix Rate"} , "xAxis" : { "title" : { "text" : "Time"} , "categories" : [ 2009.0 , 2010.0 , 2011.0 , 2012.0 , 2013.0]} , "yAxis" : { "title" : { "text" : "FTFR"}} , "plotOptions" : { "series" : { "cursor" : "pointer" , "point" : { "events" : { "click" :function () {alert (this.category+':' + this.y);}}}}} , "tooltip" : { "pointFormat" : "{series.name} produced {point.y:,.0f}
warheads in {point.x}"} , "series" : [ { "data" : [ 100.0 , 222.0 , 555.0 , 367.0 , 100.0]}]}

If I manually place this in

$('#graphContainer').highcharts(data);

removing the white spaces, graph is getting generated. but if want chart to be generated dynamically, its failing without any javascript error.

I tried json2.js, JSON.parse and Stringify, but that didn't solve the issue. Am i missing something?

If i set the data in session from my client code and access it using scriplet ie $('#graphContainer').highcharts(<%=session1.getAttribute("data")%>); it works fine. I wonder whats wrong with variables?

I cant use session here.

2
  • And if you just do data = data.replace(/ /g, ''); before the document.write? Commented Dec 16, 2013 at 14:13
  • you want dynamic chart with json data? Commented Dec 17, 2013 at 6:15

2 Answers 2

1

Generally in json you cannot use functions, so it can cause problems.

Sign up to request clarification or add additional context in comments.

Comments

0

I have created a chart from the json data from another source. But what I have done is, I have created the series array programmatically and then asigned the array in the Highchart chart' series value. Not sure though if this helps you.

2 Comments

cant have template here in jsp bro
i did not know it also works like what you are showing. new learning for me. thanks. +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.