ext中无法JSon解析数据,不知道原因所在
- HTML code
[code=JScript]
Ext.chart.Chart.CHART_URL='Ext/resources/charts.swf'; //模板falsh
Ext.onReady( //onReady函数入参是一个函数
function(){
//var store=new Ext.data.JsonStore({
// fields:['name','visits','views'],
//data:[
//{name:'Jul 07',visits:245000,views:300000},
// {name:'Aug 07',visits:240000,views:350000},
// {name:'Sep 07',visits:335000,views:400000},
//{name:'Oct 07',visits:375000,views:420000},
//{name:'Nov 07',visits:490000,views:550000},
//{name:'Dec 07',visits:495000,views:580000},
//{name:'Jan 07',visits:520000,views:600000},
//{name:'Feb 07',visits:620000,views:750000}
//]
//});
var MyRecord = Ext.data.Record.create([
{name: 'name'},
{name: 'visits'},
{name: 'views'}
]);
var pie_mananode_store = new Ext.data.Store({
proxy : new Ext.data.HttpProxy({
url : 'testchartajaxjson.jsp'
}),
reader : new Ext.data.JsonReader(
{
root : 'data'
}, MyRecord),
baseParams:
{
type:1
}
});
pie_mananode_store.load();
alert(MyRecord.getField("name"));
new Ext.FormPanel({
title:'ExtJs pieChart',
autoWidth:true,
height:500,
renderTo:'container',
iconCls:'chart',
frame:true,
items:[{
fieldLabel:'饼图1',
name:'piechart1',
xtype:'piechart',
height:200,
store:pie_mananode_store,
dataField:'visits', //重要属性
categoryField:'name',
series:[{
style:
{
showLables:true,
/*定义pie的颜色范围及画图上显示百分比*/
colors:['#953030','#ff8c40','#ffdb59','#8dc63f','#ff4fff',
'#ffbbcc','#953040','#ff8440','#ffd459','#84c63f','#4fff44','#aabbee']
}
}],
extraStyle:
{ //添加底部图例
legend:
{
display:'bottom', //名称显示的位置,bottom为下,还有left,right
animationEnabled:true, //动画效果,默认为true
font:{family:'Tahoma',size:13}
}
}
},
{
fieldLabel:'饼图2',
name:'piechart1',
xtype:'piechart',
height:200,
store:pie_mananode_store,
dataField:'visits', //重要属性
categoryField:'name',
series:[{
style:
{
showLables:true,
/*定义pie的颜色范围及画图上显示百分比*/
colors:['#953030','#ff8c40','#ffdb59','#8dc63f','#ff4fff',
'#ffbbcc','#953040','#ff8440','#ffd459','#84c63f','#4fff44','#aabbee']
}
}],
extraStyle:
{ //添加底部图例
legend:
{
display:'bottom', //名称显示的位置,bottom为下,还有left,right
animationEnabled:true, //动画效果,默认为true
font:{family:'Tahoma',size:13}
}
}
}
]
});
}
);
<div id=container></div>
[/code]
'testchartajaxjson.jsp'代码
- HTML code
<body><% String type=request.getParameter("type"); System.out.println(type); String rejsonstr=""; //{name:'Jul 07',visits:245000,views:300000}, // {name:'Aug 07',visits:240000,views:350000}, // {name:'Sep 07',visits:335000,views:400000}, //{name:'Oct 07',visits:375000,views:420000}, //{name:'Nov 07',visits:490000,views:550000}, //{name:'Dec 07',visits:495000,views:580000}, //{name:'Jan 07',visits:520000,views:600000}, //{name:'Feb 07',visits:620000,views:750000} rejsonstr="{data:[{name:'Jul 07',visits:245000,views:300000}," + "{name:'Aug 07',visits:240000,views:350000}," + "{name:'Sep 07',visits:335000,views:400000}," + "{name:'Oct 07',visits:375000,views:420000}," + "{name:'Nov 07',visits:490000,views:550000}," + "{name:'Dec 07',visits:495000,views:580000}," + "{name:'Jan 07',visits:520000,views:600000}," + "{name:'Feb 07',visits:620000,views:750000}]}"; System.out.println(rejsonstr); response.getWriter().print(rejsonstr); System.out.println(3); %></body>
原来是静态数据,现在搞了一个远程请求了jsp页面,但是始终无法正常显示piechart,请高手指教一下代码错在哪儿,遇到这种问题怎么查错??
[解决办法]
做个从后台传数据的例子呗
[解决办法]
楼主在贡献例子啊。不错,值得学习!
[解决办法]
var MyRecord = Ext.data.Record.create([
{name: 'name', type: 'string'},
{name: 'visits', type: 'int'},
{name: 'views', type: 'int'}
]);
是这样解决的吗
[解决办法]
JSON格式好象不对吧.