笔记:Echarts - 柱状折线图

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>柱状折线图demo</title>
    <style>
        .section {
            width: 915px;
            border: 1px solid #ccc;
        }
        .chart {
            width: 810px;
            height: 400px;
        }
    </style>
</head>
<body>
<div class="section">
    <div class="chart" id="chartBarLineDemo"></div>
</div>

<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/echarts.min.js"></script>
<script>

    var axisData = ["语文", "政治", "地理", "数学", "英语", "历史", "生物", "音乐", "体育", "物理", "化学", "美术"];
    var seriesBarData = [4, 5, 9, 8, 6, 5, 4, 8, 9, 8, 6, 4];
    var seriesLineData = [20, 22, 33, 45, 63, 100, 66, 80, 70, 50, 60, 90];
    initChartBarLine("chartBarLineDemo", axisData, seriesBarData, seriesLineData);

    /**
     * 初始化柱状折线图
     * @param domChartId 统计图dom容器id
     * @param axisData 轴线label数组
     * @param seriesBarData 柱状图series data数组
     * @param seriesLineData 折线图series data数组
     */
    function initChartBarLine(domChartId, axisData, seriesBarData, seriesLineData) {
        var chart = echarts.init(document.getElementById(domChartId));
        var opt = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    crossStyle: {
                        color: '#999'
                    }
                }
            },
            legend: {
                data: ['≥60%(单位:个)', '平均值(%)'],
                y: 'bottom' // 图例位置
            },
            xAxis: [{
                type: 'category',
                data: axisData
            }
            ],
            yAxis: [{
                type: 'value',
                name: '人数',
//                    min: 0,
                max: Math.max.apply(Math, seriesBarData) * 3 // 让柱状图在折线图下方
                /*,interval: 50,
                axisLabel: {
                    formatter: '{value} 个'
                }*/
            },
                {
                    type: 'value',
                    name: '学科兴趣指数均值'/*,
                    min: 0,
                    max: 25,
                    rmatter: '{value}%'// 单位
                    }*/
                }
            ],
            series: [{
                name: '≥60%(单位:个)',
                type: 'bar',
                data: seriesBarData,
                barWidth: 10,
                itemStyle: {
                    emphasis: {//柱形图圆角
                        barBorderRadius: 30
                    },
                    normal: {
                        barBorderRadius: [10, 10, 10, 10],//柱形图圆角,初始化效果
                        color: '#2196f3'
                    }
                }
            },
                {
                    name: '平均值(%)',
                    type: 'line',
                    symbolSize: 10,//设置折点大小
                    yAxisIndex: 1,
                    data: seriesLineData,
                    itemStyle: {
                        normal: {
                            color: '#2ecdbb'
                        }
                    },
                    label: {
                        show: true
                    }
                }
            ],

            label: {
                normal: {
                    show: true, //显示数据
                    position: 'top'
                }
            }
        };
        chart.setOption(opt);
    }
</script>
</body>
</html>

效果图:
这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值