echarts多條折線圖和柱狀圖實現


參考鏈接:echarts官網:http://echarts.baidu.com/
原型圖(效果圖):

圖片.png

代碼:

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>

    <body>
        <!-- 折線統計圖 -->
        <div class="row">
            <div id="main" style="width: 900px; height: 350px; margin-top:80px;"></div>
        </div>
    </body>
    <script src="js/echarts/echarts.min.js" type="text/javascript"></script>
    <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
    <script type="text/javascript"> // 基於准備好的dom,初始化echarts實例 var myChart = echarts.init(document.getElementById('main')); // 指定圖表的配置項和數據 myChart.setOption({ title: { text: '堆疊區域圖' }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross', label: { backgroundColor: '#6a7985' } } }, legend: { data: ['SA服務', '等號', '機修', '鈑金', '噴漆', '總檢', '洗車', '滯留'] }, toolbox: { feature: { saveAsImage: {} } }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, xAxis: [{ type: 'category', boundaryGap: false, data: ['10.1', '10.2', '10.3', '10.4', '10.5', '10.6', '10.7'] }], yAxis: [{ type: 'value' }], series: [{ name: 'SA服務', type: 'line', stack: '總量', areaStyle: { normal: {} }, data: [120, 132, 101, 134, 90, 230, 210] }, { name: '等號', type: 'line', stack: '總量', areaStyle: { normal: {} }, data: [220, 182, 191, 234, 290, 330, 310] }, { name: '機修', type: 'line', stack: '總量', areaStyle: { normal: {} }, data: [150, 232, 101, 154, 190, 330, 410] }, { name: '鈑金', type: 'line', stack: '總量', areaStyle: { normal: {} }, data: [320, 332, 301, 334, 190, 330, 320] }, { name: '噴漆', type: 'line', stack: '總量', areaStyle: { normal: {} }, data: [310, 312, 301, 334, 390, 330, 320] }, { name: '總檢', type: 'line', stack: '總量', areaStyle: { normal: {} }, data: [320, 332, 311, 334, 390, 330, 320] }, { name: '洗車', type: 'line', stack: '總量', areaStyle: { normal: {} }, data: [320, 332, 101, 334, 390, 310, 320] }, { name: '滯留', type: 'line', stack: '總量', label: { normal: { show: true, position: 'top' } }, areaStyle: { normal: {} }, data: [820, 932, 901, 934, 1290, 1330, 1320] } ] }); /* // 異步加載數據 $.get('data.json').done(function (data) { // 填入數據 myChart.setOption({ xAxis: { data: data.categories }, series: [{ // 根據名字對應到相應的系列 name: '銷量', data: data.data }] });});*/ </script>

</html>

橫向柱狀圖:

圖片.png
<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>

    <body>
        <!-- 柱狀統計圖 -->
        <div class="row">
            <div id="main" style="width: 900px; height: 350px; margin-top:80px;"></div>
        </div>
    </body>
    <script src="../../js/echarts/echarts.min.js" type="text/javascript"></script>
    <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
    <script type="text/javascript"> // 基於准備好的dom,初始化echarts實例 var myChart = echarts.init(document.getElementById('main')); // 指定圖表的配置項和數據 myChart.setOption({ title: { text: '平均耗時(分鍾)', }, tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } }, legend: { /* data: [ '2012年']*/ }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, xAxis: { type: 'value', boundaryGap: [0, 0.01] }, yAxis: { type: 'category', data: ['SA服務', '洗車', '總檢', '噴漆', '鈑金', '機修', '等號'] }, series: [ { name: '2012年', type: 'bar', itemStyle: { normal: { color: '#a8bcd4' } }, data: [10, 20, 31, 14, 11, 67] } ] }); </script>

</html>

原文作者:祈澈姑娘
原文鏈接:https://www.jianshu.com/u/05f416aefbe1
創作不易,轉載請告知

90后前端妹子,愛編程,愛運營,愛折騰。
堅持總結工作中遇到的技術問題,堅持記錄工作中所所思所見,歡迎大家一起探討交流。
有個很難漲粉的的公眾號叫:【編程微刊】


免責聲明!

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



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