Is there a way to connect groupby data to an amcharts map?

Currently, I am encountering an issue with binding data to a map.

In the past, my data binding process involved using JSON data in records format as shown below:

{
    "latitude":39.7645187,
    "longitude": -104.9951976,
    "name": "ORCL",
    "value":32,
    "activeProducts":"127", 
},
{
    "latitude":49.619446,
    "longitude": -128.695623,
    "name": "RCXC",
    "value":72,
    "activeProducts":"789",
},

Previously, I used the lat and long directly from the data to display circles on the map, while name, value, and activeProducts were utilized for tooltips.

Now, I have grouped the data based on the name field after applying the reduce clause:

CDFN: (26) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}
HCDR: (33) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}
HVBL: (87) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}
PCMD: (16) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}

Each group contains similar data including lat, long, and name. The value (as seen in the first JSON data) represents the count of records in each group (CDFN: (26)). After expansion, the data appears like this:

{
    "latitude":39.7645187,
    "longitude": -104.9951976,
    "name": "CDFN",
    "activeProducts": "127",
    "totalproducts": "140"   
},
{
    "latitude": 49.619446,
    "longitude": -128.695623,
    "name": "HCDR",
    "activeProducts": "789",
    "totalproducts": "810"   
},

My current query is:

  1. How can I extract the lat and long of a single record from groups like CDFN, HCDR, HVBL, etc., to bind it to the map?

The code I am presently utilizing is provided below:

public productsLocMap()
{
  this.mapChart = am4core.create("stationsMap", am4maps.MapChart);
  this.mapChart .geodata = am4geodata_worldLow;
  this.mapChart .projection = new am4maps.projections.Miller();
  this.polygonSeries = this.mapChart .series.push(new am4maps.MapPolygonSeries());
  this.polygonSeries.useGeodata = true;
  this.polygonSeries.strokeWidth = 0.5;

  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=Stations.Stations;     
  
  var circle = place.createChild(am4core.Circle);
  circle.fillOpacity = 0.7;
  circle.propertyFields.fill = "color";
  circle.tooltipText = "[bold]{name}:[/]\nCompliance Devices: {activeDevices}\nTotal devices:{totalDevice}";

  place.events.on("hit", (ev)=>{
    console.log(ev.target.dataItem.dataContext.title)
  })

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

The following lines are crucial where data binding occurs:

imageSeries.data=Stations.Stations;  
imageSeries.heatRules.push({
    "target": circle,
    "property": "radius",
    "max": 15,
    "dataField": "value",
})

I attempted to use the following code but was unsuccessful in displaying anything on the map:

imageSeries.data=group;

Answer №1

When using AmCharts, make sure to pass an array for the data property in a series or chart object, rather than an object or map that references an array. Be sure to directly assign an array to it. To work with multiple image series and group them accordingly, you can follow this example:

series1.data = group.CDFN;
// ...
series2.data = group.HCDR;
// ...
// etc

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue encountered while declaring a variable as a function in TSX

Being new to TS, I encountered an interesting issue. The first code snippet worked without any errors: interface Props { active: boolean error: any // unknown input: any // unknown onActivate: Function onKeyUp: Function onSelect: Function onU ...

Is there a way to manage null JSON data?

Upon receiving JSON data from the server, I proceed to send a post request for deletion. If the JSON data matches this format, there are no issues and I can easily parse it: {"tables":[{"id":"1","number":"4"},{"id":"2","number":"1"},{"id":"3","number":"2 ...

I'm looking for an open-source solution in Angular/Ionic that can generate public and private keys

Although I'm not entirely certain if this is a suitable question for Stack Overflow, I have been exploring options for a library in angular and ionic that can generate public/private keypairs. My goal is to build an end-to-end encrypted application us ...

Securely import TypeScript modules from file paths that are dynamically determined during execution

Imagine you have a structure of TypeScript code and assets stored at a specific URL, like between a CDN and a debug location. You want to import the main module and ensure the rest of the structure is imported correctly only when needed, without repeating ...

Steps to simulate a TouchEvent programmatically using TypeScript

Is there a way to manually trigger the touch event in TypeScript? In JavaScript, it was possible but I am struggling to achieve the same in TypeScript. For example: let touchStart: TouchEvent = document.createEvent('TouchEvent'); touchStart.i ...

Verify if the Contact Number and Email provided are legitimate

Is it possible to determine if the phone number or email entered by a user is valid or not? Using Angular 7 and Firebase? ...

What is the best approach to handle an incorrect JSON format? (simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0))

1) My previously functioning script suddenly stopped working a few days ago. It seems to have trouble parsing JSON correctly now, even though it had been running smoothly for months. 2) The servicing website made some changes that caused the JSON data to ...

Tips on how to properly format a DateTime String

I need help with formatting a DateTime string retrieved from an API where it is in the format of YYYY-MM-DDTHH:MM:SS +08:00 and I want to change it to DD-MM-YY HH:MM getDataFromApi(res) { this.timestamp = this.timestamp.items[0].timestamp; console ...

Understanding data contract serialization in JSON format for WCF

Currently, I am facing an issue with deserializing a DataContract from JSON data received from a WCF service. While I can successfully deserialize the root DeviceID and TimeStamp, I'm encountering problems with deserializing the nested elements like G ...

Get Java8 Instant by Jackson deserializing date-time formatted in ISO8601

My current challenge involves the deserialization of an ISO8601 formatted date into Java8's java.time.Instant using Jackson. To address this, I activated the JavaTimeModule with the ObjectMapper and disabled the WRITE_DATES_AS_TIMESTAMPS setting. Des ...

How do you properly include a new property in an Object using Typescript?

I am currently delving into the world of typescript. After exploring various sources like this one and that one, as well as trying out multiple solutions, I have encountered a challenge. I have a variable named incomingArticleObject which needs to be of ty ...

Obtain log records in Azure and save them as a JSON object

Is there a recommended method to export logs from Azure in JSON format and what are the best practices for doing so? While using direct Kusto queries to export logs to CSV is an option, unfortunately there is no built-in option for exporting logs in JSON ...

Error message for invalid form control not displayed when value is assigned to form control in Angular

I am currently working with this editor: <div id="editor"></div> which sets its value to a form control. this.FrmGroup.get("name").setValue(this.quill.root.innerHTML)` <div *ngIf="FrmGroup.get('name').inv ...

Learn the process of extracting keys and values from a response in Python and then adding them to a list

I have utilized Python code to fetch both the key and values in a specific format. def test() data={u'Application': u'e2e', u'Cost center': u'qwerty', u'Environment': u'E2E', u'e2e3': u ...

Decoding a JWT Base64 string into JSON format

While attempting to convert a base64 encoded JWT header into a string, I encountered an unexpected output: {"alg":"RS256","typ":"JWT","kid":"1234" The output seems to be missing the closing bracket. However, when I decode the same base64 string usi ...

What is the best way to optimize reactive values using the Vue composition API?

Imagine I have a block of code like this... const computedStyle = computed(() => normalizeStyle([undefined, styleProp, undefined]) ); const computedClass = computed(() => normalizeClass([ "button", classProp, { "b ...

Encountering issues with MediaSession.setPositionState() and seekto functionalities not functioning properly

Having trouble with MediaSession.setPositionState() not displaying the audio time and seekbar not behaving as expected. const sound= document.querySelector('sound'); function updatePositionState() { if ('setPositionState' in navigato ...

Leveraging the .reduce method to perform specific calculations and generate an object containing the results of an array

After successfully achieving the desired results, here is the data manipulation I have done: const days = [ { date: '2016-12-13T00:00:00.000Z', stats: [ { name: 'Soft Drinks', sold: 34, }, { name: 'Snacks&apo ...

Transfer dynamically generated table data to the following page

Seeking guidance on a common issue I'm facing. I am creating a table using data from Firebase upon page load, and I want users to click on a row to view specific details of that item. It may sound confusing, but it will make more sense with the code p ...

Leveraging gzip files in production with Angular 2

I have recently implemented angular-cli to compile my application. After running `ng build --prod`, I noticed that the gzip bundle files are generated, but the index.html is still referencing the full-sized files. I attempted using `ng build --prod --aot ...