我创建了一个使用绘图插件绘制折线图的应用程序。我已经使用 javaJSONObject
类创建了一个 json 数组并传递给 jquery-ajax,但是在将 json 导入 $plot() 函数时,我没有绘制线图。
谁能告诉我一些解决方案
我的javascript是这个
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);
}
});
我的struts2.xml
<action name="getDashboardvalue" class="commonpackage.Graphclass" method="getDashboardvalue">
</action>
在我的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();
}
}
当我如下所示直接放置 json 时,我得到了图表
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);