echart图柱状图前后台写法

主要是后台查询数据放到json里的形式,和前台如何取出json

<td style="width:35%;padding:0px;">
                      <div id="qingTuiTJ" style="width: 100%;height:220px;"></div>
                      <script type="text/javascript">
                        // 基于准备好的dom,初始化echarts实例
                        var myChart22 = echarts.init(document.getElementById('qingTuiTJ'));
                
                        var option22 = {
                            title : {
                                text: '${yearMonth!''}清退统计',
                                subtext: '',
                                x:'right'
                            },
                            tooltip : {
                                trigger: 'item',
                                formatter: "{b} : {c} ({d}%)"
                            },
                            legend: {
                                orient: 'vertical',
                                left: 'left',
                                data: ['超时清退','按时清退','尚未清退','无需清退']
                            },
                            series : [
                                {
                                    name: '访问来源',
                                    type: 'pie',
                                    radius: ['50%', '70%'],
                                    center: ['58%', '58%'],
                                    data:[],
                                    itemStyle: {
                                        emphasis: {
                                            shadowBlur: 10,
                                            shadowOffsetX: 0,
                                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                                        }
                                    }
                                }
                            ]
                        };

                
                        // 使用刚指定的配置项和数据显示图表。
                        myChart22.setOption(option22);
                        $(function(){
                            $.post("./countNumByMonth",{},function(result){
                                var nums=[];  
                                  $.each(result.obj,function(key,values){ //此处我返回的是list<String,map<String,String>>循环map  
                                      var obj = new Object();  
                                      obj.name = values.name;  
                                      obj.value = values.value;  
                                      nums.push(obj);  
                                   });
                                myChart22.setOption({
                                    series: [{
                                        data: nums
                                    }]
                                });
                            },"json");
                        });
                    </script>
                  </td>

 

后台代码:

@ResponseBody
    @RequestMapping(value = "/countNumByMonth", method = { RequestMethod.POST, RequestMethod.GET })
    public Json countNumByMonth(
            HttpServletRequest request, HttpServletResponse response, ModelMap model
            ){
        Json json = new Json();
        
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String yearMonth = sdf.format(new Date());
        json.setSuccess(true);
        List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
        Map<String,Object> map1 = new HashMap<String,Object>();
        EntityWrapper<GwdjIdeainfo> wrapper1 = new EntityWrapper<GwdjIdeainfo>();
        wrapper1.like("SI_SEND_TIME", yearMonth, SqlLike.RIGHT);
        wrapper1.eq("SI_STATE", "3");
        map1.put("name", "超时清退");
        map1.put("value", gwdjIdeainfoServiceImpl.selectCount(wrapper1));

        Map<String,Object> map2 = new HashMap<String,Object>();
        EntityWrapper<GwdjIdeainfo> wrapper2 = new EntityWrapper<GwdjIdeainfo>();
        wrapper2.like("SI_SEND_TIME", yearMonth, SqlLike.RIGHT);
        wrapper2.eq("SI_STATE", "2");
        wrapper2.where("SI_QTTYPE!='0'");
        map2.put("name", "按时清退");
        map2.put("value", gwdjIdeainfoServiceImpl.selectCount(wrapper2));

        Map<String,Object> map3 = new HashMap<String,Object>();
        EntityWrapper<GwdjIdeainfo> wrapper3 = new EntityWrapper<GwdjIdeainfo>();
        wrapper3.like("SI_SEND_TIME", yearMonth, SqlLike.RIGHT);
        wrapper3.eq("SI_STATE", "1");
        map3.put("name", "尚未清退");
        map3.put("value", gwdjIdeainfoServiceImpl.selectCount(wrapper3));

        Map<String,Object> map4 = new HashMap<String,Object>();
        EntityWrapper<GwdjIdeainfo> wrapper4 = new EntityWrapper<GwdjIdeainfo>();
        wrapper4.like("SI_SEND_TIME", yearMonth, SqlLike.RIGHT);
        wrapper4.eq("SI_STATE", "2");
        wrapper2.eq("SI_QTTYPE", "0");
        map4.put("name", "无需清退");
        map4.put("value", gwdjIdeainfoServiceImpl.selectCount(wrapper4));
        resultList.add(map1);
        resultList.add(map2);
        resultList.add(map3);
        resultList.add(map4);

        
        json.setObj(resultList);
        
        return json;
    }
   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值