【问题标题】:How to set different colors on circles in amcharts map如何在amcharts地图中的圆圈上设置不同的颜色
【发布时间】:2020-07-29 16:24:40
【问题描述】:

我已经在amchartsplugin 中实现了一个地图,并在我有服务器的位置绘制了圆圈。

我想根据业务需求根据可用性Green、Yellow 和Red 在服务器上显示不同的颜色。我已经在首选位置实现了圈子,并且我能够仅分配一个color。

这是我的代码

public ServerMap()
{
    this.mapChart = am4core.create("chartdiv", am4maps.MapChart);
    this.mapChart .geodata = am4geodata_worldLow;

    //Set projection
    this.mapChart .projection = new am4maps.projections.Miller();
    //Create map polygon series
    this.polygonSeries = this.mapChart .series.push(new am4maps.MapPolygonSeries());
    this.polygonSeries.exclude = ["AQ"];
    this.polygonSeries.useGeodata = true;
    this.polygonSeries.nonScalingStroke = true;
    this.polygonSeries.calculateVisualCenter = true;

    let imageSeries = this.mapChart .series.push(new am4maps.MapImageSeries());
    imageSeries.dataFields.value = "value";

    var place = imageSeries.mapImages.template;
    place.nonScaling = true;
    place.propertyFields.latitude = "latitude";
    place.propertyFields.longitude = "longitude";   
    
    imageSeries.data=
    [
    {
        "latitude": 17.3850,
        "longitude": 78.4867,
        "name": "Miam",
        "value": 123,    
      },
    {
        "latitude":49.619446,
        "longitude": -128.695623,
        "name": "Washingto DC",
        "value": 123,
    },
    {
        "latitude": 41.8278767,
        "longitude": -87.9986114,
        "name": "Chicago",
        "value": 123,
    }  
    ]

    //Here creating circle
    var circle = place.createChild(am4core.Circle);
    circle.radius = 12;
    circle.fill = am4core.color("#e33");
    circle.strokeWidth = 1;
    circle.fillOpacity = 0.7;
    circle.propertyFields.fill = "color";
    circle.tooltipText = "{name}: [bold]{value}[/]";

    imageSeries.heatRules.push({
      "target": circle,
      "property": "radius",
      "min": 6,
      "max": 15,
      "dataField": "value",
      })
}

如何根据条件在圆圈上设置单独的颜色?

这是我的输出屏幕

【问题讨论】:

    标签: javascript angular typescript amcharts


    【解决方案1】:

    你已经有了 "circle.propertyFields.fill = "color";"已定义。

    在数据中包含“颜色”属性应该可以工作。

    imageSeries.data=
        [
        {
            "latitude": 17.3850,
            "longitude": 78.4867,
            "name": "Miam",
            "value": 123,    
            "color": 'red' // or rgb() or Hexa
          },
          {
             "latitude":49.619446,
             "longitude": -128.695623,
             "name": "Washingto DC",
             "value": 123,
             "color": 'blue'
           },
    

    【讨论】:

    • 谢谢。是否可以根据if else 条件更改颜色?
    猜你喜欢
    • 2023-01-26
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-19
    • 2015-04-28
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多