i've created an application for drawing a line graph using plot plugin.
i've created a json array using java JSONObject
class and passed to jquery-ajax, but while importing the json to $plot() function, i'm getting no line graph drawn.
can anyone please tell me some solution for this
my javascript is this
var options = {};
var placeholder = $("#placeholder1");
$.ajax({
url : "getDashboardvalue.action",
dataType : "application/json",
type : "POST",
data : {
operation : "custyear"
},
success : function(data) {
var plot = $.plot(placeholder, data, options);
}
});
my struts2.xml
<action name="getDashboardvalue" class="commonpackage.Graphclass" method="getDashboardvalue">
</action>
inside my my Graphclass.java
public void getDashboardvalue() throws IOException
{
try{
HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_RESPONSE);
HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_REQUEST);
System.out.println("operation-------------->"+operation);
if(operation.equals("custyear"))
{
JSONObject jsonObj = new JSONObject(
"{ label: \'Development\', data: [[1,53914],[2,32172],[3,825],[4,838],[5,756],[6,50877],[7,0], [8,0],[9,0],[10,0],[11,0],[12,0]]}");
System.out.println(jsonObj.toString());
response.setContentType("application/json");
response.getWriter().write(jsonObj.toString());
}
}catch(Exception e){
System.out.println("Exception:"+e);
e.printStackTrace();
}
}
when i put the json directly like as shown below i'm getting the graph
var data =[
{ label:"Development", data: [[1,53914],[2,32172],[3,825],[4,838],[5,756],[6,50877],[7,0], [8,0],[9,0],[10,0],[11,0],[12,0]] }
}
var options = {};
var placeholder = $("#placeholder1");
var plot = $.plot(placeholder, data, options);