拼接符合highCharts格式的数据类型
2016-04-18 14:55
369 查看
我使用easyUI的方式传递数据到后台,将所需的数据拼接起来后返回一个result给easyui,其中result需要包含横坐标的值,还有分组后的多条数据,具体的highcharts代码是
$.ajax({ url : "login/registerChart.action", cache : true, type : "post", dataType : "json", data:{"agentName":daiLiShang,"areaName":diqu,"teamName":duan,"picName":fu,"businessName":shangWu, "customerName":keFU,"projectName":xiangMu,"productName":chanPing,"agentName1":agentName1, "areaName1":areaName1,"teamName1":teamName1,"picName1":picName1,"businessName1":businessName1, "customerName1":customerName1,"projectName1":projectName1,"productName1":productName1,"statTime":statTime}, success : function(result) { $('#container').highcharts({ chart: { type: 'line' }, title: { text: 'Blue-Game' }, subtitle: { text: 'Build the most cutting-edge fishing game in the world' }, xAxis: { categories: result.date }, yAxis: { title: { text: '数量' } }, tooltip: { enabled: false, formatter: function() { return '<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'; } }, plotOptions: { line: { dataLabels: { enabled: true }, enableMouseTracking: false } }, series:result.line }); }, error:function(data){ alert("网络异常,请稍候再试"); } });其中 X轴的result.date存放的是date中的值,也就是要表现在X轴上的值,date是我在后台自己定义的,result.line的值存放的是具体的数据,line是我在后台自己定义的因为数据不是单一的,所以我需要按要求拼接字符窜,拼接的格式如下{"date":["2016-03-29","2016-03-30"],"line":[{"name":"注册人数","data":[32,45]}]}line中可以包含多个,比如{"name":"产品1","data":[21,33]},{"name":"产品2","data":[11,12]}首先拼接的是line中的值{"name":"产品1","data":[21,33]},{"name":"产品2","data":[11,12]}思路是通过判断name是否重复,从而将值放入到对应的map中,如果重复,就把相对应的值存入到匹配的name中去,代码如下
if (map2.keySet().contains(line)) { List vList = (List) map2.get(line); // 得到line所对应的list数据 vList.add(Integer.valueOf(map1.get("SUM").toString())); map2.put(map1.get(name1).toString(), vList); } else { List vList = new ArrayList(); vList.add(Integer.valueOf(map1.get("SUM").toString())); map2.put(map1.get(name1).toString(), vList); }通过上述代码中在以产品名分组的条件下,我们得到的是{项目b=[11, 12], 项目a=[21, 33]}这种格式,这时候要通过迭代的方式把他变成line,代码如下
Iterator it = map2.keySet().iterator();while (it.hasNext()) {JSONObject jo = new JSONObject();String mkey = it.next().toString();jo.accumulate("name", mkey);jo.accumulate("data", map2.get(mkey));ja.add(jo);}
通过这种方式
相关文章推荐
- 使用按键精灵+umdh定位内存泄露问题的方式
- cocos笔记
- 深圳证券交易所网络投票业务指南
- poj 1036 Gangsters 简单dp
- bzoj 2162: 男生女生
- boost的配置解析库
- PHP常量与变量,函数
- 相似性度量(Similarity Measurement)
- OpenCV读取序列图片(二)
- 关于在不同品牌的手机在自带的存储空间上创建文件的区别
- 面向业务的立体化高可用架构设计
- iOS 单例模式 浅叙
- XAMPP(集成PHP+MySQL+Apache)修改Apache默认工程位置
- Win8.1安装itunes提示此windows installer软件包有一个问题如何解决
- Direct3D 11第三节 Shaders and Effect System
- OSG源码编译
- 华为研发实习生(一面)
- 关于Android的nodpi,xhdpi,hdpi,mdpi,ldpi
- 机器学习实战之k-means
- 《Spark MLlib 机器学习》勘误(持续更新)