1

我正在尝试根据城市名称为气泡着色。类似 if this.point.capital == Montgomery & this.point.capital == Juneau; 颜色=“红色”。但我不能将此 if 函数添加到颜色属性。你能帮我吗?

谢谢!!!!

series: [{
            name: 'Basemap',
            mapData: map,
            borderColor: '#606060',
            nullColor: 'rgba(200, 200, 200, 0.2)',
            showInLegend: false
        }, {
            name: 'Separators',
            type: 'mapline',
            data: H.geojson(map, 'mapline'),
            color: '#101010',
            enableMouseTracking: false
        }, {
            type: 'mapbubble',
            dataLabels: {
                enabled: true,
                format: '{point.capital}'
            },
            name: 'Cities',
            data: data,
            maxSize: '12%',
            color: H.getOptions().colors[0]
        }]

http://jsfiddle.net/oufwhmz0/

4

1 回答 1

3

data在启动图表之前,对数组中的每个气泡(而不是整个系列)单独执行此操作。例如扩展您的代码(JSFiddle):

function determineColor(entry) {
    if(entry.capital == "Montgomery")
        return "#FF00FF";
    else if(entry.capital == "Salt Lake City")
        return "#00FF00";
    return null;
}

// Add series with state capital bubbles
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=us-capitals.json&callback=?', function (json) {
    var data = [];
    $.each(json, function (ix, entry) {
        entry.z = entry.population;
        entry.color = determineColor(entry); // Added
        data.push(entry);
    });

    // ... rest as usual
});

这只是设置函数定义的colorfor each (这将是一个气泡) 。entrydetermineColor

于 2015-06-06T00:27:08.150 回答