echarts如何顯示在頁面上


echarts如何顯示在頁面上

1.引入echarts的相關.js文件

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

2.新建一個div,style自己定,但必須要有width和height

<div id="history_state" style="width: 400px;height: 200px"></div>

3.document.ready()中設置echarts的option

$(document).ready(function(e) {
     option = {
         tooltip : {
             trigger: 'axis',
             axisPointer : {            // 坐標軸指示器,坐標軸觸發有效
                 type : 'shadow'        // 默認為直線,可選為:'line' | 'shadow'
             }
         },
         calculable : true,
         yAxis : [
             {
                 type : 'value'
             }
         ],
         xAxis : [
             {
                 type : 'category',
                 data : ['1','2','3','4','5','6','7','8','9','10','11','12']
             }
         ],
         series : [
             {
                 name:'直接訪問',
                 type:'bar',
                 stack: '總量',
                 itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
                 data:[320, 302, 301, 334, 390, 330, 320]
             },
             {
                 name:'郵件營銷',
                 type:'bar',
                 stack: '總量',
                 itemStyle : { normal: {label : {show: true, position: 'insideRight'}}},
                 data:[120, 132, 101, 134, 90, 230, 210]
             }
         ]
     };

   //獲取echarts對象
var history_state = echarts.init(document.getElementById('history_state')); //設置option
   history_state.setOption(option); });

這樣就能顯示了。

補充。。document.ready()方法是在dom加載完成,頁面完全呈現后調用的。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM