javaweb通过ajax异步请求获取echart3Dpunch数据生成图表失败
以下分别是js和servlet层的代码,请各位佬帮忙看一下如何改进,一直显示不了
var Poption = {
tooltip: {}
,toolbox: {
feature: {
dataView: { show: true, readOnly: false },
restore: { show: true },
saveAsImage: { show: true }
}
}
,visualMap: {
max: 20,
inRange: {
color: [
'#313695',
'#4575b4',
'#74add1',
'#abd9e9',
'#e0f3f8',
'#ffffbf',
'#fee090',
'#fdae61',
'#f46d43',
'#d73027',
'#a50026'
]
}
}
,xAxis3D: {
type: 'category'
,data: []
},
yAxis3D: {
type: 'category'
,data: []
},
zAxis3D: {
type: 'value'
}
,grid3D: {
boxWidth: 60
,boxDepth: 120
,viewControl: {}
,light: {
main: {
intensity: 1.2
,shadow: true
}
,ambient: {
intensity: 0.3
}
}
}
,series: [
{
trpe: 'bar3D'
,name: 'data'
,data: []
,shading: 'lambert'
,label: {
fontSize: 16
,borderWidth: 1
}
,emphasis: {
label: {
fontSize: 20
,color: '#900'
}
,itemStyle: {
color: '#900'
}
}
}
]
};
function update3D() {
$.ajax({
url: '/ItemPunch'
,type: 'get'
,dataType: 'json'
,success: function (result) {
Pchart.hideLoading();
Pchart.setOption({
xAxis3D: {
data: result.row
}
,yAxis3D: {
data: result.col
}
,series: [
{
data: result.data
}
]
});
}
,error: function (error) {
layer.msg(error);
}
});
}
@WebServlet("/ItemPunch")
public class ItemPunchServlet extends HttpServlet {
ItemData itemData = new ItemDataImpl();
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("application/json");
resp.setCharacterEncoding("UTF-8");
String[] row = new String[] {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
String[] col = new String[] {"01","02","03","04","05","06","07","08","09","10"};
int[][] data = new int[260][3];
for (int i=0; i < 26; i++) {
String r = row[i];
for (int j=0; j < 10; j++) {
String c = col[j];
data[i*10+j][0] = i;
data[i*10+j][1] = j;
data[i*10+j][2] = itemData.numByAdd(r + "-" + c);
}
}
JSONObject j = new JSONObject();
j.put("col",col);
j.put("row",row);
j.put("data",data);
PrintWriter pw = resp.getWriter();
pw.write(j.toString());
pw.flush();
pw.close();
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doPost(req, resp);
}
}
这是效果图:
