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

当y为类目轴且series的data为二维数组时,tooltip里的formatter回调的params[0].name属性不显示 #2822

Closed
RachelWaffle opened this issue Mar 15, 2016 · 3 comments
Labels

Comments

@RachelWaffle
Copy link

问题简述 (One-line summary)

当y为类目轴且series的data为二维数组时,tooltip里的formatter回调的params[0].name属性不显示

版本及环境 (Version & Environment)

  • ECharts 版本 (ECharts version): 3.1.3 / 3.1.2
  • 浏览器类型和版本 (Browser version): Chrome
  • 操作系统类型和版本 (OS Version): Mac OS

当y为类目轴且series的data为二维数组时,tooltip里的formatter回调的params[0].name属性不显示
如果series的data为一维数组的时候,这个name可以正常显示
image

ECharts配置项 (ECharts option)

option = {

    tooltip : {
        trigger: 'axis',
        formatter : function (params) {

            output = params[0].name + '<br/>';
            for(var i=0;i<params.length;i++){
                output += params[i].seriesName + " : " + params[i].value[0]  +'<br/>';
            }
            return output;
        }
    },
    yAxis : [
        {
            type : 'category',
            data : ['2015/12/21','2015/12/22','2015/12/23','2015/12/24','2015/12/25']
        }
    ],
    xAxis : [
        {
            type : 'value' ,
        }
    ],
    series : [{
            name: 'dm存活率',
            type: 'bar',
            data: [[200,0],[220,1],[280,2],[210,3]]
        }
    ]
};

在x轴为类目轴的时候formatter的回调name属性能正常显示
image

ECharts配置项 (ECharts option)

option = {

    tooltip : {
        trigger: 'axis',
        formatter : function (params) {

            output = params[0].name + '<br/>';
            for(var i=0;i<params.length;i++){
                output += params[i].seriesName + " : " + params[i].value[1]  +'<br/>';
            }
            return output;
        }
    },
    xAxis : [
        {
            type : 'category',
            data : ['2015/12/21','2015/12/22','2015/12/23','2015/12/24','2015/12/25']
        }
    ],
    yAxis : [
        {
            type : 'value' ,
        }
    ],
    series : [{
            name: 'dm存活率',
            type: 'bar',
            data: [[0,200],[1,220],[2,280],[3,210]]
        }
    ]
};
@pissang
Copy link
Contributor

pissang commented Mar 17, 2016

谢谢反馈,是 bug

@RachelWaffle
Copy link
Author

        function createNameList(result, data) {
            var nameList = [];

            if (result && result.categoryAxisModel) {
                // FIXME Two category axis
                var categories = result.categoryAxisModel.getCategories();
                if (categories) {
                    var dataLen = data.length;
                    // Ordered data is given explicitly like
                    // [[3, 0.2], [1, 0.3], [2, 0.15]]
                    // or given scatter data,
                    // pick the category
                    if (zrUtil.isArray(data[0]) && data[0].length > 1) {
                        nameList = [];
                        for (var i = 0; i < dataLen; i++) {
                            nameList[i] = categories[data[i][0]];
                        }
                    }
                    else {
                        nameList = categories.slice(0);
                    }
                }
            }

            return nameList;
        }

源码18400行获取nameList的代码中,series出现二维数组时会默认将categories[data[i][0]];设置为name。当类目轴为x轴时data[i][0]表示的是x轴的类目,不会出现问题,但是类目轴为y轴时data[i][0]表示的是值,data[i][1]才表示的是类目,所以此时categories[data[i][0]]作为name取出来会有问题。
我现在的办法是将

                    if (zrUtil.isArray(data[0]) && data[0].length > 1) {
                        nameList = [];
                        for (var i = 0; i < dataLen; i++) {
                            nameList[i] = categories[data[i][0]];
                        }
                    }

判断删掉,但是这样的话series就必须是按顺序排列的,出现离散数据的时候数据会乱。

我想正确方法应该是通过判断类目轴来确定data[i][0]或data[i][1],但是我不会js啊。先就这么办吧。。

@RachelWaffle
Copy link
Author

我提的issue居然有人看!太感动了!

pissang added a commit that referenced this issue Mar 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants