Echarts 柱狀圖組

經過Echarts能夠實現柱狀圖組,以下圖:是一個學生三次模考成績對比結果html

image

源碼

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
    <!-- 引入 echarts.js -->
    <script src="js/echarts.min.js"></script>
</head>
<body>
    <!-- 爲ECharts準備一個具有大小(寬高)的Dom -->
    <div id="main" style="width: 600px;height:400px;"></div>
    <script>
        // 基於準備好的dom,初始化echarts實例
        var myChart = echarts.init(document.getElementById('main'));

        // 指定圖表的配置項和數據
        var option = {
            title : {
                text: '模考分數對比',
                subtext: '純屬虛構'
            },
            tooltip : {
                trigger: 'axis'
            },
            legend: {
                data:['一模','二模','三模']
            },
            toolbox: {
                show : true,
                feature : {
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    data : ['數學','語文','英語','綜合']
                }
            ],
            yAxis : [
                {
                    type : 'value'
                }
            ],
            series : [
                {
                    name:'一模',
                    type:'bar',
                    data:[78, 80, 87, 93],
                    color:'#CC0066'
                },
                {
                    name:'二模',
                    type:'bar',
                    data:[90, 77, 62, 76],
                    color:'#009999'
                },
                {
                    name:'三模',
                    type:'bar',
                    data:[91, 78, 87, 89],
                    color:'#FFCC33'
                }
            ]
        };
        // 使用剛指定的配置項和數據顯示圖表。
        myChart.setOption(option);
    </script>
</body>
</html>

上圖是一個橫座標爲種類,縱座標爲值的圖形,若是須要將座標軸互換,只須要xAixs與yAixs中的type參數便可echarts

image

修改後的效果圖以下:dom

image

相關文章
相關標籤/搜索