amCharts adding listener for "clickGraphItem" for a specific graph (not the whole chart)

StackOverflow https://stackoverflow.com/questions/23676350

  •  23-07-2023
  •  | 
  •  

Frage

Using amCharts, I need to differentiate between multiple graphs when a "clickGraphItem" event occurs. That means having a distinct listener for each graph, so that I can call a function with a different parameter (the graphs name) depending on which graphs' bullet is clicked.

The common example for amCharts "clickGraphItem" listeners is adding this listener to the whole chart. However, one cannot get the origin graph of the bullet that has been clicked, because the event triggers for all graphs in the chart.

I tried changing this example to use graph.addListener(...) instead of chart.addListener(...), however this doesn't quite work as expected. The event somehow only triggers on the first graph created (graph) and does not work on graph2, graph3, etc.

Does anyone know an alternative way of doing this with amCharts? Any help would be greatly appreciated.

best regards,

daZza

Current Code (inside amCharts .ready function):

AmCharts.ready(function() {

// In between the chart is created

graph.addListener("clickGraphItem", function (event) {
var date = dateFormat(event.item.category, "mmm dd yyyy hh:MM:ss");
 getDetails(date, "graph");
});

graph1.addListener("clickGraphItem", function (event) {
var date = dateFormat(event.item.category, "mmm dd yyyy hh:MM:ss");
 getDetails(date, "graph1");
});

graph2.addListener("clickGraphItem", function (event) {
alert("graph2");
var date = dateFormat(event.item.category, "mmm dd yyyy hh:MM:ss");
 getDetails(date, "graph2");
});

}
War es hilfreich?

Lösung

Strange, it should work like this. Can you show full source code? However, you can simply add this event listener to the chart and then check bullet of which graph was clicked. the event which is fired has a reference to graph object:

{type:"clickGraph", graph:AmGraph, chart:AmChart, event:MouseEvent}

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top