關於SSM與echart結合的問題總結

mnk發表於2017-12-11

這是我用ssm框架和echart圖實現的效果:

 

 

以下是我遇到的問題和解決辦法

1.對映檔案的配置(XXMapper.xml):

2.css,js的問題:

 

3.css,js地址的配置

4.ajax的同步非同步問題

5.springMvc控制層的相關配置和訪問頁面的控制

6.儲存echart圖資料的資料結構:

7.這是echart圖的jsp程式碼

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE html>

<html>

<head>

    <base href="<%=basePath%>">

    <meta charset="utf-8">

    <title>ECharts</title>

    <!-- 引入 echarts.js -->

    <script src="js/echarts.js"></script>

    <script src="js/jquery-3.2.1.min.js"></script>

</head>

<body>

    <!-- 為ECharts準備一個具備大小(寬高)的Dom -->

    <div id="main" style="width: 600px;height:400px;"></div>

    <script type="text/javascript">

      

       

           var colors = ['#5793f3', '#d14a61', '#675bba'];

           var area="";

           var loan="";

           var asset="";

           var rate="";

            $.ajax({

            url:"<%=basePath%>showechart",

            type:"post",

            data:{"data_Time":"201706"},

            dataType:"json",

            async:false,

            success:function(data){

                area = data.modelMap.area;//橫座標名(寧德市分行。。。。。。)

                loan = data.modelMap.loan;//貨款餘額

                asset = data.modelMap.asset;//資產餘額

                rate = data.modelMap.rate;//歸行率

            },

            error:function(data){

               alert("error");

            }

           

          });

         

         

        var arr1 = loan;

           var arr2 = asset;

           var arr3 = rate;

           var loanMax =  eval("Math.max(" + loan.toString() + ")");

           var assetMax =  eval("Math.max(" + asset.toString() + ")");

           var rateMax =  eval("Math.max(" + rate.toString() + ")");

           option = {

               title: {

                     text: '圖例',

                     x:'center',

                     y:'top'

                },

                color: colors,

                tooltip: {

                     trigger: 'axis',

                     axisPointer: {type: 'cross'}

                },

                grid: {

                    top: '20%',

                     right: '20%'

                },

                toolbox: {

                     feature: {

                           dataView: {show: true, readOnly: false},

                           restore: {show: true},

                           saveAsImage: {show: true}

                     }

                },

                legend: {

                     data:['歸行率','貨款餘額','資產餘額'],

                     y:'8%'

                },

                xAxis: [

                     {

                           type: 'category',

                           axisTick: {

                                alignWithLabel: true

                           },

                           data: area,

                           axisLabel:{

                                 interval:0,

                                rotate:60,

                           }

                     }

                ],

                yAxis: [

                     {

                           type: 'value',

                           name: '歸行率',

                           min: 0,

                           max: rateMax,

                           position: 'right',

                           offset: 60,

                           axisLine: {

                                lineStyle: {

                                     color: colors[2]

                                }

                           },

                           axisLabel: {

                                formatter: '{value} %'

                           }

                     },

                     {

                           type: 'value',

                           name: '資產餘額',

                           min: 0,

                           max: assetMax,

                           position: 'right',

                           axisLine: {

                                lineStyle: {

                                     color: colors[1]

                                }

                           },

                           axisLabel: {

                                formatter: '{value} '

                           }

                     },

                     {

                           type: 'value',

                           name: '貨款餘額',

                           min: 0,

                           max: loanMax,

                           position: 'left',

                           axisLine: {

                                lineStyle: {

                                     color: colors[0]

                                }

                           },

                           axisLabel: {

                                formatter: '{value} '

                           }

                     }

                ],

                series: [

                    {

                           name:'貸款餘額',

                           type:'bar',

                           yAxisIndex: 2,

                           data: arr1

                     },

                

                     {

                           name:'資產餘額',

                           type:'bar',

                           yAxisIndex: 1,

                           data:arr2

                     },

                     {

                           name:'歸行率',

                           type:'line',

                           yAxisIndex: 0,

                           data:arr3

                     }

                ]

           };

         // 基於準備好的dom,初始化echarts例項

        var myChart = echarts.init(document.getElementById('main'));

        // 使用剛指定的配置項和資料顯示圖表。

        myChart.setOption(option);

    </script>

</body>

</html>

 

相關文章