JAVA中引入ECHARTS报表(柱状图)

前台:

<!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->  
<div id="main" style="width: 1500px; height: 400px;"></div>
<script type="text/javascript">  
        // 基于准备好的dom,初始化echarts实例  
        var myChart = echarts.init(document.getElementById('main'));  
        var url = '${pageContext.request.contextPath}/income/sumCash';  
        $.ajax({
        url:url,
        success:function(data){
                // 2.获取数据  
                cash = data.cash;//金额
                userName = data.userName;//开单中心 
             // 3.更新图表myChart的数据  
                var option = {  
                    title : {  
                        text : '财务纳表'  
                    },  
                    tooltip : {},  
                    legend : {  
                        data : [ '金额' ],  
                    },  
                    xAxis : {  
                        data : userName  
                    },  
                    yAxis : {},  
                    series :  {  
                        name : '金额',  
                        type : 'bar',  
                        data : cash  
                    },   
                    toolbox : {  
                        show : true,  
                        feature : {  
                            mark : {  
                                show : true  
                            },  
                            dataView : {  
                                show : true,  
                                readOnly : false  
                            },  
                            magicType : {  
                                show : true,  
                                type : 'bar' 
                            },  
                            restore : {  
                                show : true  
                            },  
                            saveAsImage : {  
                                show : true  
                            }  
                        }  
                    },  
                }  
                myChart.setOption(option); 
        }         
        })  
    </script>  

后台:

        @RequestMapping("sumCash")
@ResponseBody
public Map<String,Object> sumCash() throws IOException {
List<sumCashEntity>list=incomeService.sumCash();
/*金额*/  
    Double[] cash=new Double[list.size()];
    for(int i=0;i<cash.length;i++){
    cash[i]=list.get(i).getCash();
    }
    /*横轴, 开单中心*/  
        String[]userName=new String[list.size()];
    for(int i=0;i<userName.length;i++){
    userName[i]=list.get(i).getUserName();
    }
   
    Map<String, Object> map = new HashMap<>();  
        map.put("cash", cash);    
        map.put("userName", userName);
        return map; 
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值