Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当x轴dataZoom的左端不在数据序列的0索引位置时,showTip事件参数中的e.dataIndex值不合理 #2920

Closed
netwww1 opened this issue Mar 30, 2016 · 1 comment

Comments

@netwww1
Copy link

netwww1 commented Mar 30, 2016

问题简述 (One-line summary)

如下图,当x轴 dataZoom 的左端在“周三”位置时(数据序列索引为2),鼠标移动到“周四”位置触发showTip事件中的 e.dataIndex 值不是3,而是1,即 e.dataIndex 实际是(3 - dataZoom左端在数据序列中的偏移值 2)这么一个间接的值。

这个可能不太合理,在根据 e.dataIndex 索引数据时会很不方便。

类似的,该事件对应的action.tooltip.showTip方法是否也存在该 dataIndex 的问题?

版本及环境 (Version & Environment)

  • ECharts 版本 (ECharts version): 3.1.5
  • 浏览器类型和版本 (Browser version): chrome 49
  • 操作系统类型和版本 (OS Version): win7 64位

重现步骤 (Steps to reproduce)

  1. 使用如下js代码,并观察控制台输出。
    2.

期望结果 (Expected behaviour)

dataIndex 是数据序列的绝对索引,而不是dataZoom相关联的相对索引。
如果确实有相对索引的必要,应该另设一个成员变量,例如OffsetIndex,来指示相对索引。

可能哪里有问题 (What went wrong)

ECharts配置项 (ECharts option)

    var myChart = echarts.init(document.getElementById('main'));
    myChart.on('showTip',onshowTip);

    function onshowTip(e) {
        console.log('onShowTip: seriesIndex: ' + e.seriesIndex + ', dataIndex: ' + e.dataIndex);
    }

    // 指定图表的配置项和数据
    var option = {
        title: {
            text: '未来一周气温变化',
            subtext: '纯属虚构'
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data:['最高气温','最低气温']
        },
        toolbox: {
            show: true,
            feature: {
                dataZoom: {},
                dataView: {readOnly: false},
                magicType: {type: ['line', 'bar']},
                restore: {},
                saveAsImage: {}
            }
        },
        xAxis:  {
            type: 'category',
            boundaryGap: false,
            data: ['周一','周二','周三','周四','周五','周六','周日']
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                formatter: '{value} °C'
            }
        },
        dataZoom: [{
            type: 'inside',
            start: 0,
            end: 50
        }, {
            start: 0,
            end: 50
        },
                {
                    show: true,
                    yAxisIndex: 0,
                    filterMode: 'empty',
                    width: 12,
                    handleSize: 8,
                    showDataShadow: false,
                    left: '93%'
                }],
        series: [
            {
                name:'最高气温',
                type:'line',
                data:[11, 11, 15, 13, 12, 13, 10],
                markPoint: {
                    data: [
                        {type: 'max', name: '最大值'},
                        {type: 'min', name: '最小值'}
                    ]
                },
                markLine: {
                            name: '平均值',
                            animation:false,
                            symbolSize:0,
                            lineStyle:{normal:{color:'#268'}},
                            data:[
                                [{value:8,coord:[2,8]},{value:4,coord:[5,4]}]
                            ]
                }
            },
            {
                name:'最低气温',
                type:'line',
                data:[1, -2, 2, 5, 3, 2, 0],
                markPoint: {
                    data: [
                        {name: '周最低', value: -2, xAxis: 1, yAxis: -1.5}
                    ]
                },
                markLine : {
                            name: '平均值',
                            animation:false,
                            symbolSize:0,
                            lineStyle:{normal:{color:'#268'}},
                            data:[
                                [{value:'8',coord:[2,8]},{value:'4',coord:[5,4]}]
                            ]
                }
            }
        ]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);

其他信息 (Other comments)

showtipdz

@chengwb53
Copy link

这个2.0版本里面可以通过chart.getSeries();获取当前显示的数据的series.data再来获取dataIndex,3.0的改版了不清楚了

@100pah 100pah closed this as completed in e20e448 Oct 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants