ext js linechart前台接不到数据,求解

衆尋 2012-04-20 06:30:39
js:
Ext.chart.Chart.CHART_URL = '../resources/charts.swf'; // 模板flash
var json_store;

Ext.onReady(function() {
alert('d');
var json_reader = new Ext.data.JsonReader({
idProperty : "name",
root : 'data',
totalProperty : "totalCount",
fields : [{
name : 'name',
type : "string"
}, {
name : 'views',
type : "int"
}, {
name : 'visits',
type : "int"
}]
});

json_store = new Ext.data.Store({
proxy : new Ext.data.HttpProxy({
url : 'listSellBillForDemo',
method : 'POST'
}),
reader : json_reader
});

// extra extra simple
new Ext.Panel({
title : 'ExtJS.com Visits Trend, 2007/2008 ',
renderTo : 'container',
width : 500,
height : 300,
layout : 'fit',

items : {
xtype : 'linechart', // 类型
store : json_store,
xField : 'name', // X轴取值
yField : 'visits', // Y轴取值
listeners : {
itemclick : function(o) {// 点击事件.
var rec = store.getAt(o.index);
Ext.example.msg('被选中项:', '你选择了 {0}.', rec
.get('name'));
}
},
series : [{
type : 'line', // line
displayName : '点击数',
yField : 'visits',
style : {
color : '#6666CC'
}
}]
}
});



json_store.load();
});


jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>charts</title>

<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css"/>
<script type="text/javascript" src="ext-base.js"></script>
<script type="text/javascript" src="ext-all.js"></script>
<script type="text/javascript" src="scripts/testDemo.js"></script>

</head>

<body>


<div id="container" >

</div>
</body>
</html>


java
HttpServletResponse response=ServletActionContext.getResponse();
PrintWriter out = response.getWriter ();
String jsonString = "";
List<DataBean> list = new ArrayList<DataBean> ();
String[] names = { "1G", "2G", "3G", "4G", "5G", "6G", "7G", "8G" };
Random random = new Random ();
for (int i = 0; i < names.length; i++) {
int num = random.nextInt ( 100 ) * 100;
DataBean data = new DataBean ( names[i], num, num / 2 );
list.add ( data );
}
JSONArray arryData = null;
arryData = JSONArray.fromObject ( list );
jsonString = "{success:true,totalCount:" + list.size () + ",data:" + arryData.toString ().replaceAll ( "\n", "" ) + "}";
System.out.println (jsonString);
out.print ( jsonString );
//Struts2Utils.renderJson(jsonString);
out.flush ();
out.close ();
return "listSellBillForDemoResult";

我后台输出的数据形式:
{totalCount:8,data:[{"views":3550,"name":"1G","visits":7100},{"views":2200,"name":"2G","visits":4400},{"views":3000,"name":"3G","visits":6000},{"views":4000,"name":"4G","visits":8000},{"views":4900,"name":"5G","visits":9800},{"views":3150,"name":"6G","visits":6300},{"views":350,"name":"7G","visits":700},{"views":1250,"name":"8G","visits":2500}]}
前台不显示数据,坐标轴也不显示,求解释~~~~(>_<)~~~~
...全文
205 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧