1. 程式人生 > >【前端統計圖】echarts多條折線圖和橫柱狀圖實現

【前端統計圖】echarts多條折線圖和橫柱狀圖實現

5640239-a332b9cc4f90c87f.png 圖片.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>

橫向柱狀圖:

5640239-ae25e69d92e392b1.png 圖片.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>

90後前端妹子,愛程式設計,愛運營,愛折騰。
堅持總結工作中遇到的技術問題,堅持記錄工作中所所思所見,歡迎大家一起探討交流。