繁体   English   中英

MapPointSeries 不在 amcharts5 中调用 heatRules?

[英]MapPointSeries not calling heatRules in amcharts5?

我已经使用 heatRules 在 amcharts5 上成功创建了 MapPolygonSeries。 但我正在尝试添加 MapPointSeries 来设置项目符号的颜色。 在我看来,根本没有调用 heatRules。 有没有人有一个工作示例,或者我的代码的问题是否明显?

            var rootElements = am5.registry.rootElements;
            var root = (rootElements.length > 0? rootElements[0]: am5.Root.new("chartdiv"));
            root.container.children.clear();
            
            var chart = root.container.children.push (
                am5map.MapChart.new(root, {
                    projection: am5map.geoMercator(),
                    panX: "none",
                    panY: "none",
                    wheelX: "none",
                    wheelY: "none"
                })
            );
            
            var pointSeries = chart.series.push(
                am5map.MapPointSeries.new(root, {
                    latitudeField: "lat",
                    longitudeField: "lon",
                    fill: am5.color(0xff0000)
                })
            );

            var circleTemplate = am5.Template.new({});
            pointSeries.bullets.push(function() {
                var bulletCircle = am5.Circle.new(root, {
                    radius: 5,  
                    fill: pointSeries.get("fill"),
                    fillOpacity: 0.8
                }, circleTemplate);
                return am5.Bullet.new(root, {
                    sprite: bulletCircle
                });
            });
            
            pointSeries.set("heatRules", [{
                target: circleTemplate,
                dataField: "value",
                key: "fill"
                min: am5.color(0xff3300),
                max: am5.color(0xffff00),
            }]);

            pointSeries.data.setAll(myPointData);

我的点数据看起来像这样:

[
{lat: -15.4183, lon: 28.287, value: 1.00448108131708},
{lat: -9.7915, lon: 29.0791, value: 1.0057251847281312},
...
]

笔记:

  • 如果我没有在 MapPointSeries.new 中设置填充,则不会绘制任何内容(或者看起来如此)
  • 浏览器控制台(Chrome)中没有错误

预先感谢您对此有任何见解!

这是我的变通方法,但它很难看,因为我基本上写了自己的热图 function。我仍然愿意接受如何让 heatRules 为点正常工作的建议!

    function manualHeatMap(series) {
        if (series.length < 1) {
            return series;
        }
        var min, max;
        min = max = series[0].value;
        for (var i = 1; i < series.length; ++i) {
            if (series[i].value > max) {
                max = series[i].value;
            }
            if (series[i].value < min) {
                min = series[i].value;
            }
        }
        if (min == max) {
            min = 0;
        }
        for (var i = 0; i < series.length; ++i) {
            series[i].settings = {fill: am5.color(heatRuleCalc(min, max, series[i].value))};
        }
        return series;
    }

/* ... */

            var circleTemplate = am5.Template.new({});
            pointSeries.bullets.push(function() {
                var bulletCircle = am5.Circle.new(root, {
                    radius: 7,  
                    templateField: "settings",
                    fillOpacity: 0.8
                }, circleTemplate);
                return am5.Bullet.new(root, {
                    sprite: bulletCircle
                });
            });

            pointSeries.data.setAll(manualHeatMap(myPointData));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM