I'm using jqPlot and since I can't find one decent place to find out how to send multiple series to jqplot through JSON, I will try to work around it.
so here's a little background:
Right now, I can call my servlet and return a JSON array with the data that I'm going to display in the chart.
AJAX CALL
$.ajax({
type: 'POST',
cache: 'false',
data: params,
url: '/miloWeb/PlotChartServlet',
async: false,
dataType: 'json',
success: function(series){
coordinates = [series] ;
},
error: function (xhr, ajaxOptions, thrownError){
alert(ajaxOptions);
}
});
SERVLET
private void generateCoordinates(HttpServletRequest request, HttpServletResponse response) throws IOException{
JSONArray coordinates = new JSONArray();
try {
coordinates = findChartCoordinatesByPatientPK();
} catch (JSONException e) {
e.printStackTrace();
}
response.getOutputStream().print(coordinates.toString());
}
What this does is return the string:
[["07/06/2000","22.0"],["08/06/2000","20.0"],["08/06/2003","15.0"],["08/06/2005","35.0"],["08/06/2007","12.0"],["08/06/2010","10.0"],["08/06/2012","10.0"]]
So I store that in the variable 'coordinates' and use those to plot the jqPlot graph using:
var plot10 = $.jqplot ('chartdiv', coordinates);
Up To this point everything works great, now comes what I'm trying to achieve:
If I hardcode a String that symbolizes the two arrays inside another array, like so:
[[["07/06/2000","22.0"],["08/06/2000","20.0"],["08/06/2003","15.0"],["08/06/2005","35.0"],["08/06/2007","12.0"],["08/06/2010","10.0"],["08/06/2012","10.0"]], [["07/06/2000","21.0"],["08/06/2000","19.0"],["08/06/2003","14.0"],["08/06/2005","34.0"],["08/06/2007","11.0"],["08/06/2010","9.0"],["08/06/2012","9.0"]]]
I can get the jQplot to plot the two distinct lines in the chart! So I tried doing the same and returning a String exactly like that one through the servlet:
NOT WORKING SERVLET
private void generateCoordinates(HttpServletRequest request, HttpServletResponse response) throws IOException{
JSONArray coordinates = new JSONArray();
JSONArray coordinates2 = new JSONArray();
try {
coordinates = VitalsBB.findChartCoordinatesByPatientPK();
coordinates2 = VitalsBB.findChartCoordinatesByPatientPK2();
} catch (JSONException e) {
e.printStackTrace();
}
response.getOutputStream().print( coordinates.toString() + ", " + coordinates2.toString());
}
But that doesn't work, it gives me a parse Error. So do I need to modify the AJAX call? or is there a way to give back two JSON arrays.toString() to my form and store them in a variable? Or maybe I need two variables?
'['and']'? Notice that you need this for it to be a JSON array.