Pass Json Object from Play! framework to HighCharts JS
http://www.playframework.com/documentation/2.1.x/JavaTodoList
Using the above tutorial as a reference, I have created an application
which sends data from the model to view via the Application controller. I
have managed to display the model(Tasks) as a high chart. The code is
here.
public static Result format(){
return ok(views.html.frmt.render("Visualize it",Task.all()));
}
This goes to this view page. http://ideone.com/ycz9ko
Currently, I use scala templating inside the javascript code itself. Refer
to lines 9-14 and lines 20-24.This unelegant style of doing things is not
really optimal.
I want to be able to accomplish the above using Json instead.
public static Result jsonIt(){
List<Task> tasks = Task.all();
return ok(Json.toJson(tasks));
}
My Qns are how to send the JSON objects to a view template. And how to
parse it into a Highcharts format. Is there some standard procedure to do
this ? Or else I have to write my own method to do this ?
I also found this stackoverflow post useful.how to parse json into
highcharts. However, it didnt answer the part about converting from Play
format to Highcharts format.
Thanks in advance
No comments:
Post a Comment