Echarts笔记——折线图/柱状图(1)设置Y轴双坐标轴

Echarts笔记——折线图/柱状图(1)设置Y轴双坐标轴,图表参考右坐标轴

  • 设置Y右坐标轴
position: "right",         # y 轴的位置,参数 "left","right"。
  • 设置图标参考右边坐标轴
yAxisIndex: 1,         #  y轴的 index定位索引 ,默认值为0 ,参数类型:number。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/echarts.min.js"></script>
    <script src="../../js/jquery.min.js"></script>
</head>
<body>
<div id="main" style="width: 1200px; height: 800px;"></div>
<style>
    #main {
        margin-top: 100px;
        margin-left: 100px;
    }
</style>
</body>
<script type="text/javascript">
    line_Data = [62.4, 56.9, 41.8, 18.6, 17.8, 19.7]
    bar_Data = [21750, 34120, 48370, 57370, 67582, 80892]
    x_Data = ['2015', '2016', '2017', '2018', '2019', '2020']

      // 基于准备好的dom,初始化echarts实例
    var myChart1 = echarts.init(document.getElementById('main'))
    $(function (ec) {
        var option = {
            title: {
                text: '2015-2020年中国移动电商市场交易额(纯属虚构)',
                subtext: "Transaction volume of China mobile e-commerce market from 2015 to 2020",
                left: '20%',
                textStyle: {
                    color: 'red',
                    fontSize: 30
                }
            },
            legend: {
                right: '45%',
                top: "10%"
            },
            xAxis: {
                name: '部门',
                type: 'category',
                data: x_Data,
                nameGap:60,         // 坐标轴名称与轴线之间的距离。
                axisLabel: {        // x轴标签样式
                    textStyle: {fontSize: 20}
                },
                nameTextStyle: {     // 坐标轴名字样式
                    fontSize: 20
                },
            },
            yAxis: [
                {
                    name: '交易额(亿元)',
                    type: 'value',
                    min: 0,
                    max: 100000,
                    axisLabel: {            // 坐标轴标签样式设置
                        textStyle: {fontSize: 20},
                        formatter: '{value} 件',     // 给坐标轴标签加单位
                    },
                    nameTextStyle: {fontSize: 20},
                }, {
                    name: "增长率(%)",
                    type: "value",
                    min: 0,
                    max: 70,
                    position: "right",
                    formatter: "{value}%",
                    axisLabel: {
                        textStyle: {fontSize: 20},
                        formatter: '{value} %',     // 给坐标轴标签加单位
                    },
                    nameTextStyle: {fontSize: 20},
                    itemStyle: {
                        color: "#ffd07a"
                    },
                }
            ],
            series: [
                {
                    type: "bar",
                    data: bar_Data,
                    label: {
                        show: true,
                        position: "top"
                    }
                },
                {
                    name: '销量折线图',
                    type: 'line',
                    data: line_Data,
                    barWith: "40%",
                    label: {
                        show: true,
                        position: "top",
                        formatter: "{c}%"
                    },
                    lineStyle: {
                        color: "#ffb122"
                    },
                    yAxisIndex: 1
                },
            ]
        };
        myChart1.setOption(option)
    })

</script>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

寧三一

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值