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

值为0的lines不会被visualMap着色 #4346

Closed
mirari opened this issue Oct 28, 2016 · 3 comments
Closed

值为0的lines不会被visualMap着色 #4346

mirari opened this issue Oct 28, 2016 · 3 comments
Labels
enhancement pending We are not sure about whether this is a bug/new feature.

Comments

@mirari
Copy link

mirari commented Oct 28, 2016

问题简述 (One-line summary)

series类型为lines的数据,其value为0时,即使visualMap定义包含0,也不会被正确着色。
请直接访问线上实例。可以看到即使关闭所有图例显示,值为0的暗红色线条依然存在。
http://gallery.echartsjs.com/editor.html?c=xB1pdCBgex

版本及环境 (Version & Environment)

  • ECharts 版本 (ECharts version):v3.2.3
  • 浏览器类型和版本 (Browser version):全部
  • 操作系统类型和版本 (OS Version):全部

重现步骤 (Steps to reproduce)

定义visualMap:

        visualMap: {
            type: "piecewise",
            left: 'right',
            min: 0,
            max: 15,
            splitNumber: 5,
            color: ['red', 'yellow', 'green']
        },

或者

        visualMap: {
            type: "piecewise",
            pieces: [
                {min: 15}, // 不指定 max,表示 max 为无限大(Infinity)。
                {min: 12, max: 15},
                {min: 9, max: 12},
                {min: 6, max: 9},
                {min: 3, max: 6},
                {max: 3}     // 不指定 min,表示 min 为无限大(-Infinity)。
            ],
            left: 'right',
            color: ['red', 'yellow', 'green']
        },

定义series[0].data,例如:

{
    value:0,
    coords:[...]
}

期望结果 (Expected behaviour)

值为0的折线被绘制成绿色。
实际效果是值为0的折线在默认主题下绘制成暗红色。
而且仅当值为0的时候出现此情况,若value为字符串的"0"则显示正常。
官网例子使用scatter绘制,value为Number类型也显示正常。

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

可能是空值判断不严谨。

ECharts配置项 (ECharts option)

var uploadedDataURL = "/asset/get/s/data-1477626617822-SJMboHgel.txt";

function convertData(sourceData) {
    return [].concat.apply([], $.map(sourceData, function(busLine, index) {
        var prevPoint = null;
        var points = [];
        var value = busLine.shift();
        for (var i = 0; i < busLine.length; i += 2) {
            var point = [busLine[i], busLine[i + 1]];
            if (i > 0) {
                point = [
                    prevPoint[0] + point[0],
                    prevPoint[1] + point[1]
                ];
            }
            prevPoint = point;

            points.push([point[0] / 1e5, point[1] / 1e5]);
        }
        return {
            value: value,
            coords: points
        };
    }));
}

var option = {
    bmap: {
        roam: true
    },
    visualMap: {
        type: "piecewise",
        pieces: [{
                min: 15
            }, // 不指定 max,表示 max 为无限大(Infinity)。
            {
                min: 12,
                max: 15
            }, {
                min: 9,
                max: 12
            }, {
                min: 6,
                max: 9
            }, {
                min: 3,
                max: 6
            }, {
                max: 3
            } // 不指定 min,表示 min 为无限大(-Infinity)。
        ],
        left: 'right',
        // min: 0,
        // max: 15,
        // splitNumber: 5,
        color: ['red', 'yellow', 'green']
    },
    tooltip: {
        formatter: function(params, ticket, callback) {
            return "拥堵指数:" + params.value;
        },
        trigger: 'item'
    },
    series: [{
        type: 'lines',
        coordinateSystem: 'bmap',
        polyline: true,
        lineStyle: {
            normal: {
                opacity: 1,
                width: 4
            },
            emphasis: {
                width: 6
            }
        },
        effect: {
            show: true,
            symbolSize: 2,
            color: "white"
        }
    }]
};

$.getJSON(uploadedDataURL, function(rawData) {
    option.series[0].data = convertData(rawData);
    myChart.setOption(option);
    // console.log(option);
    //获取echart中使用的bmap实例
    var map = myChart.getModel().getComponent('bmap').getBMap();
    map.disableDoubleClickZoom();
    map.centerAndZoom("嘉兴", 13);

});

其他信息 (Other comments)

请直接访问线上实例。可以看到即使关闭所有图例显示,值为0的暗红色线条依然存在。
http://gallery.echartsjs.com/editor.html?c=xB1pdCBgex

@mirari
Copy link
Author

mirari commented Oct 28, 2016

另外,定义pieces的时候需要手动指定所有区间,而min、max、splitNumber组合可以自动生成区间。
平时更常用更习惯的使用方式是后者,但是,如果数据中存在value数值超过了max,这个点或者线就不会被上色,只会以透明表现,而不是使用最接近max的颜色。
希望能有一个配置项,开启后大于max的值用最大区间的色彩表示,min同理。

@pissang pissang added pending We are not sure about whether this is a bug/new feature. enhancement labels Oct 28, 2016
@pissang
Copy link
Contributor

pissang commented Oct 28, 2016

已修复第一个问题

100pah added a commit that referenced this issue Oct 28, 2016
…luding -Infinity or Inifinity when using `splitNumber`.
@100pah
Copy link
Member

100pah commented Oct 28, 2016

第二个问题,加了个配置。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement pending We are not sure about whether this is a bug/new feature.
Projects
None yet
Development

No branches or pull requests

3 participants