echarts动态展示气泡提示框(tooltip)数据

21 篇文章 0 订阅
5 篇文章 0 订阅
直接上栗子
	 this.lineChart = echarts.init(document.getElementById('lineMain'));
                    let option = {
                        tooltip: {
                            trigger: 'axis',
                            formatter: function (params) {
                            
                                let str = params[0].name + '</br>' + '产量:' + params[0].value;

                                return str
                            },
                        },
                        grid: {
                            top: '15%',
                            left: '10%',
                            right: '10%',
                            bottom: '1%',
                            containLabel: true
                        },
                        xAxis: [{
                            type: 'category',
                            axisLine: {
                                show: true
                            },
                            splitArea: {
                                // show: true,
                                color: '#f00',
                                lineStyle: {
                                    color: '#f00'
                                },
                            },
                            axisLabel: {
                                color: '#fff'
                            },
                            splitLine: {
                                show: false
                            },
                            boundaryGap: false,
                            data:['04-22', '04-23', '04-24', '04-25', '04-26', '04-27', '04-28', '04-29'],
                        }],
                        yAxis: [{
                            type: 'value',
                            min: 0,
                            splitNumber: 4,
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(255,255,255,0.1)'
                                }
                            },
                            axisLine: {
                                show: false,
                            },
                            axisLabel: {
                                show: false,
                                margin: 20,
                                textStyle: {
                                    color: '#d1e6eb',
                                },
                            },
                        }],
                        series: [{
                            type: 'line',
                            smooth: true, //是否平滑
                            symbol: 'circle',
                            symbolSize: 5,
                            lineStyle: {
                                normal: {
                                    color: "#00ca95",
                                    shadowColor: 'rgba(0, 0, 0, .3)',
                                    shadowBlur: 0,
                                    shadowOffsetY: 5,
                                    shadowOffsetX: 5,
                                },
                            },
                            label: {
                                show: true,
                                position: 'top',
                                textStyle: {
                                    color: '#00ca95',
                                }
                            },
                            itemStyle: {
                                color: "#00ca95",
                                borderColor: "#fff",
                                borderWidth: 3,
                                shadowColor: 'rgba(0, 0, 0, .3)',
                                shadowBlur: 0,
                                shadowOffsetY: 2,
                                shadowOffsetX: 2,
                            },
                            areaStyle: {
                                normal: {
                                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                        offset: 0,
                                        color: 'rgba(0,202,149,0.3)'
                                    },
                                    {
                                        offset: 1,
                                        color: 'rgba(0,202,149,0)'
                                    }
                                    ], false),
                                    shadowColor: 'rgba(0,202,149, 0.9)',
                                    shadowBlur: 20
                                }
                            },
                          
                            data: [12, 34, 56, 78, 87, 34, 4356]
                        }]
                    };
                    this.lineChart.setOption(option);
                   
                    let app = {
                        currentIndex: -1,
                    };
                    let that = this;
                   
                    if (this.lineChartInterval) {
                        window.clearInterval(that.lineChartInterval)
                    }
                    this.lineChartInterval = setInterval(function () {
                        let dataLen = option.series[0].data.length;
                        // 取消之前高亮的图形
                        that.lineChart.dispatchAction({
                            type: 'downplay',
                            seriesIndex: 0,
                            dataIndex: app.currentIndex
                        });
                        app.currentIndex = (app.currentIndex + 1) % dataLen;
                        //console.log(app.currentIndex);
                        // 高亮当前图形
                        that.lineChart.dispatchAction({
                            type: 'highlight',
                            seriesIndex: 0,
                            dataIndex: app.currentIndex,
                        });
                        // 显示 tooltip
                        that.lineChart.dispatchAction({
                            type: 'showTip',
                            seriesIndex: 0,
                            dataIndex: app.currentIndex
                        });
                    }, 2000);
每隔 2s 气泡提示框(tooltip)就会展示下一个数据信息

在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值