使用Echarts过程中问题小结

本文介绍了ECharts在实际应用中的几个特殊需求解决方案,包括点击作用域问题、滚动图例及加载效果的实现方法。

Echarts简单易上手,官网简洁明了,但使用过程中遇到几个特殊需求,解决时耗时较长,特此记录。

1. echarts点击作用域问题


ECharts 支持常规的鼠标事件类型,包括
‘click’、’dblclick’、’mousedown’、’mousemove’、’mouseup’、’mouseover’、’mouseout’ 事件。

Click示例:
// 处理点击事件并且跳转到相应的百度搜索页面

myChart.on('click', function (params) {
    window.open('https://www.baidu.com/s?wd=' + encodeURIComponent(params.name));});

params,这是一个包含点击图形的数据信息的对象
具体参阅官网

点击柱状图非数据区域:
(参考官网柱状图第三个示例:)

series: [
        { // For shadow
            type: 'bar',
            itemStyle: {
                normal: {color: 'rgba(0,0,0,0.05)'}
            },
            barGap:'-100%',
            barCategoryGap:'40%',
            data: dataShadow,
            animation: false
        },
        {
            type: 'bar',
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(
                        0, 0, 0, 1,
                        [
                            {offset: 0, color: '#83bff6'},
                            {offset: 0.5, color: '#188df0'},
                            {offset: 1, color: '#188df0'}
                        ]
                    )
                },
                emphasis: {
                    color: new echarts.graphic.LinearGradient(
                        0, 0, 0, 1,
                        [
                            {offset: 0, color: '#2378f7'},
                            {offset: 0.7, color: '#2378f7'},
                            {offset: 1, color: '#83bff6'}
                        ]
                    )
                }
            },
            data: data
        }

解决思路:添加透明层,覆盖想要点击区域,可响应点击事件。

2、滚动图例

官网案例:
这里写图片描述

 legend: {
        type: 'scroll',
        orient: 'vertical',
        right: 10,
        top: 20,
        bottom: 20,
        data: data.legendData
},

只要添加 type: ‘scroll’,即可
注意事项:V3.7.0之后才有此功能,因为版本不对,浪费了许多时间调试
这里写图片描述

3、showLoading

在echarts上显示和隐藏loading效果

myChart.showLoading({
        text: '数据获取中',
        effect: 'whirling'
    });
myChart.hideLoading();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值