Echarts图表之带提示框的折线图(二)

 <!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Echarts图表</title>
        <!-- 引入echarts.min.js -->
        <script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
    </head>
    <body>
        <div id="main" style="width: 600px;height:400px;"></div>
        <script type="text/javascript">
            var myChart = echarts.init(document.getElementById('main'));
            var option = {
                color: ['#88be1f', '#0088d2', '#dd3135'],
                backgroundColor: '#061436',
                // 表格位置
                grid: {
                    left: 40,
                    right: 30,
                    top: 60,
                    bottom: 40,
                },
                // 提示框
                tooltip: {
                    trigger: 'axis',
                    showContent: true,
                    formatter: function(params) {
                        var res = '<div><p>' + params[0].name + '</p></div>'
                        for (var i = 0; i < params.length; i++) {
                            res += '<p>' + params[i].marker + params[i].seriesName + ':' + params[i].value + '</p>'
                        }
                        return res;
                    }
                },
                // 图例
                legend: {
                    top: 10,
                    textStyle: {
                        fontSize: 10,
                        color: 'rgba(255,255,255,.7)'
                    },
                    data: ['小型车', '中型车', '大型车']
                },
                xAxis: [{
                    name: '',
                    // 类目轴
                    type: 'category',
                    // 坐标轴两端空策略
                    boundaryGap: false,
                    axisLine: {
                        lineStyle: {
                            color: 'rgba(255,255,255,.2)'
                        }
                    },
                    splitLine: {
                        lineStyle: {
                            color: 'rgba(255,255,255,.1)'
                        }
                    },
                    axisLabel: {
                        color: "rgba(255,255,255,1)"
                    },
                    data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
                }],
                yAxis: [{
                    // 数值轴
                    type: 'value',
                    name: '',
                    min: 0,
                    max: 100,
                    interval: 20,
                    axisTick: {
                        show: false
                    },
                    axisLine: {
                        lineStyle: {
                            color: 'rgba(255,255,255,.3)'
                        }
                    },
                    splitLine: {
                        lineStyle: {
                            type: 'dashed',
                            color: 'rgba(255,255,255,.1)'
                        }
                    },
                    axisLabel: {
                        color: "rgba(255,255,255,1)"
                    }
                }],
                series: [{
                        name: '小型车',
                        type: 'line',
                        // 折线图变曲线图
                        smooth: true,
                        data: [20, 35, 30, 43, 50, 41, 50, 62, 22, 52, 22, 37]
                    },
                    {
                        name: '中型车',
                        type: 'line',
                        smooth: true,
                        data: [96, 97, 96, 97, 98, 90, 80, 92, 68, 65, 90, 82]
                    },
                    {
                        name: '大型车',
                        type: 'line',
                        smooth: true,
                        data: [82, 80, 65, 62, 42, 70, 57, 72, 78, 65, 62, 0]
                    }
                ]
            };
            myChart.setOption(option);
        </script>
    </body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值