Option返回前台数据丢失
@Liuzh_533 你好,想跟你请教个问题:
非常感谢你编写这个项目和ECharts对接,
我在用SpringMVC的@ResponseBody把
中的例子Option返回给前台时发现丢失了类似于
xAxis : [ { type : 'category', boundaryGap : false, data : ['周一','周二','周三','周四','周五','周六','周日'] } ], yAxis : [ { type : 'value', axisLabel : { formatter: '{value} °C' } } ]
如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

评论(3)

public Option countWDFBySeasonAndYM(Long seasonId,String teamName){
Option option = new Option();
option.title("某楼盘销售情况", "纯属虚构");
option.tooltip().trigger(Trigger.axis);
option.legend("意向", "预购", "成交");
option.toolbox().show(true).feature(Tool.mark,
Tool.dataView,
new MagicType(Magic.line, Magic.bar, Magic.stack, Magic.tiled),
Tool.restore,
Tool.saveAsImage).padding(20);
option.calculable(true);
option.xAxis(new CategoryAxis().boundaryGap(false).data("周一", "周二", "周三", "周四", "周五", "周六", "周日"));
option.yAxis(new ValueAxis());
Line l1 = new Line("成交");
l1.smooth(true).itemStyle().normal().areaStyle().typeDefault();
l1.data(10, 12, 21, 54, 260, 830, 710);
Line l2 = new Line("预购");
l2.smooth(true).itemStyle().normal().areaStyle().typeDefault();
l2.data(30, 182, 434, 791, 390, 30, 10);
Line l3 = new Line("意向");
l3.smooth(true).itemStyle().normal().areaStyle().typeDefault();
l3.data(1320, 1132, 601, 234, 120, 90, 20);
option.series(l1, l2, l3);
return option;
}
这是我的service方法,
public Option getTeamWDFAndYM(@RequestParam(value = "seasonId")Long seasonId,@RequestParam(value = "teamName") String teamName){
Option option = teamService.countWDFBySeasonAndYM(seasonId,teamName);
String str = JSONObject.toJSONString(option);
return option;
}
这是我的Controller,输出str的时候格式化的代码如下:
{
"calculable": true,
"legend": {
"data": [
"意向",
"预购",
"成交"
]
},
"series": [
{
"data": [
10,
12,
21,
54,
260,
830,
710
],
"itemStyle": {
"normal": {
"areaStyle": {
"type": "default"
}
}
},
"name": "成交",
"smooth": true,
"type": "line"
},
{
"data": [
30,
182,
434,
791,
390,
30,
10
],
"itemStyle": {
"normal": {
"areaStyle": {
"type": "default"
}
}
},
"name": "预购",
"smooth": true,
"type": "line"
},
{
"data": [
1320,
1132,
601,
234,
120,
90,
20
],
"itemStyle": {
"normal": {
"areaStyle": {
"type": "default"
}
}
},
"name": "意向",
"smooth": true,
"type": "line"
}
],
"title": {
"subtext": "纯属虚构",
"text": "某楼盘销售情况"
},
"toolbox": {
"feature": {
"mark": {
"lineStyle": {
"color": "#1e90ff",
"type": "dashed",
"width": 2
},
"show": true,
"title": {
"mark": "辅助线开关",
"markClear": "清空辅助线",
"markUndo": "删除辅助线"
}
},
"dataView": {
"lang": [
"数据视图",
"关闭",
"刷新"
],
"readOnly": false,
"show": true,
"title": "数据视图"
},
"magicType": {
"show": true,
"title": {
"bar": "柱形图切换",
"line": "折线图切换",
"stack": "堆积",
"tiled": "平铺"
},
"type": [
"line",
"bar",
"stack",
"tiled"
]
},
"restore": {
"show": true,
"title": "还原"
},
"saveAsImage": {
"lang": [
"点击保存"
],
"show": true,
"title": "保存为图片",
"type": "png"
}
},
"padding": 20,
"show": true
},
"tooltip": {
"trigger": "axis"
}
}
还是少了axis。

var option = { "calculable": true, "title": { "text": "某楼盘销售情况", "subtext": "纯属虚构" }, "toolbox": { "feature": { "mark": { "show": true, "title": { "mark": "辅助线开关", "markClear": "清空辅助线", "markUndo": "删除辅助线" }, "lineStyle": { "color": "#1e90ff", "type": "dashed", "width": 2 } }, "dataView": { "show": true, "title": "数据视图", "readOnly": false, "lang": ["数据视图", "关闭", "刷新"] }, "magicType": { "show": true, "title": { "line": "折线图切换", "stack": "堆积", "bar": "柱形图切换", "tiled": "平铺" }, "type": ["line", "bar", "stack", "tiled"] }, "restore": { "show": true, "title": "还原" }, "saveAsImage": { "show": true, "title": "保存为图片", "type": "png", "lang": ["点击保存"] } }, "show": true, "padding": 20 }, "tooltip": { "trigger": "axis" }, "legend": { "data": ["意向", "预购", "成交"] }, "xAxis": [{ "boundaryGap": false, "type": "category", "data": ["周一", "周二", "周三", "周四", "周五", "周六", "周日"] }], "yAxis": [{ "type": "value" }], "series": [{ "smooth": true, "name": "成交", "type": "line", "itemStyle": { "normal": { "areaStyle": { "type": "default" } } }, "data": [10, 12, 21, 54, 260, 830, 710] }, { "smooth": true, "name": "预购", "type": "line", "itemStyle": { "normal": { "areaStyle": { "type": "default" } } }, "data": [30, 182, 434, 791, 390, 30, 10] }, { "smooth": true, "name": "意向", "type": "line", "itemStyle": { "normal": { "areaStyle": { "type": "default" } } }, "data": [1320, 1132, 601, 234, 120, 90, 20] }] };
发布评论
需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。