1. 程式人生 > >Echarts2繪製動態曲線圖並給出完整程式碼

Echarts2繪製動態曲線圖並給出完整程式碼

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow

也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!

               

標籤式單檔案引入

http://echarts.baidu.com/echarts2/doc/doc.html#引入ECharts2

<!DOCTYPE html><html
lang="en">
<head><meta charset="utf-8"><title>ECharts</title></head><body><!--Step:1 Prepare a dom for ECharts which (must) has size (width & hight)--><!--Step:1 為ECharts準備一個具備大小(寬高)的Dom--><div id="main" style="height:500px;border:1px solid #ccc;padding:10px;"
>
</div><!--Step:2 Import echarts-all.js--><!--Step:2 引入echarts-all.js<script src="js/echarts-all.js"></script>--><script src="http://echarts.baidu.com/build/dist/echarts-all.js"></script><script type="text/javascript">// Step:3 echarts & zrender as a Global Interface by the echarts-plain.js.
// Step:3 echarts和zrender被echarts-plain.js寫入為全域性介面var timeTicket;var myChart = echarts.init(document.getElementById('main'));option = {    title : {        text: '動態資料',        subtext: '純屬虛構'    },    tooltip : {        trigger: 'axis'    },    legend: {        data:['最新成交價', '預購佇列']    },    toolbox: {        show : true,        feature : {            mark : {show: true},            dataView : {show: true, readOnly: false},            magicType : {show: true, type: ['line', 'bar']},            restore : {show: true},            saveAsImage : {show: true}        }    },    dataZoom : {        show : false,        start : 0,        end : 100    },    xAxis : [        {            type : 'category',            boundaryGap : true,            data : (function (){                var now = new Date();                var res = [];                var len = 10;                while (len--) {                    res.unshift(now.toLocaleTimeString().replace(/^\D*/,''));                    now = new Date(now - 2000);                }                return res;            })()        },        {            type : 'category',            boundaryGap : true,            data : (function (){                var res = [];                var len = 10;                while (len--) {                    res.push(len + 1);                }                return res;            })()        }    ],    yAxis : [        {            type : 'value',            scale: true,            name : '價格',            boundaryGap: [0.2, 0.2]        },        {            type : 'value',            scale: true,            name : '預購量',            boundaryGap: [0.2, 0.2]        }    ],    series : [        {            name:'預購佇列',            type:'bar',            xAxisIndex: 1,            yAxisIndex: 1,            data:(function (){                var res = [];                var len = 10;                while (len--) {                    res.push(Math.round(Math.random() * 1000));                }                return res;            })()        },        {            name:'最新成交價',            type:'line',            data:(function (){                var res = [];                var len = 10;                while (len--) {                    res.push((Math.random()*10 + 5).toFixed(1) - 0);                }                return res;            })()        }    ]};var lastData = 11;var axisData;clearInterval(timeTicket);timeTicket = setInterval(function (){    lastData += Math.random() * ((Math.round(Math.random() * 10) % 2) == 0 ? 1 : -1);    lastData = lastData.toFixed(1) - 0;    axisData = (new Date()).toLocaleTimeString().replace(/^\D*/,'');        // 動態資料介面 addData    myChart.addData([        [            0,        // 系列索引            Math.round(Math.random() * 1000), // 新增資料            true,     // 新增資料是否從佇列頭部插入            false     // 是否增加佇列長度,false則自定刪除原有資料,隊頭插入刪隊尾,隊尾插入刪隊頭        ],        [            1,        // 系列索引            lastData, // 新增資料            false,    // 新增資料是否從佇列頭部插入            false,    // 是否增加佇列長度,false則自定刪除原有資料,隊頭插入刪隊尾,隊尾插入刪隊頭            axisData  // 座標軸標籤        ]    ]);}, 2100);myChart.setOption(option);
</script></body></html>


           

給我老師的人工智慧教程打call!http://blog.csdn.net/jiangjunshow

這裡寫圖片描述