AmCharts, click event capture for period selection

I am using AmCharts 3 and I was wondering if there is a way to capture an event for pressing the period selector buttons?

Docs state I can add a listener to a period selector of type 'changed', but then the event fires almost anytime

There is a listener for β€œscaling”, but it starts every time I zoom in on the chart, regardless of whether I clicked the period switch

Here is my attempt:

chart = AmCharts.makeChart(scope.vm.chartId, chartSettings);
    AmCharts.addInitHandler(function () {
    // add events to item
    _.each(chart.panels, function (item) {
    //item.addListener("zoomed", onZoomed);
    item.addListener("changed", function(e) {
    console.debug("changed " + e.periodString);
   });
 });
});
+4
source share
2 answers

, "listeners", AmCharts, periodSelector chartSettings. .

+1

selector changed.

:.

var chart = AmCharts.makeChart( "chartdiv", {
  "type": "stock",

  // ...

  "periodSelector": {
    "position": "left",
    "periods": [ {
      "period": "MM",
      "selected": true,
      "count": 1,
      "label": "1 month"
    }, {
      "period": "YYYY",
      "count": 1,
      "label": "1 year"
    }, {
      "period": "YTD",
      "label": "YTD"
    }, {
      "period": "MAX",
      "label": "MAX"
    } ],
    "listeners": [ {
      "event": "changed",
      "method": function( event ) {
        if ( event.predefinedPeriod !== undefined ) {
          console.log( event.predefinedPeriod, event.count );
        }
      }
    } ]
  },

  // ...
} );

, , event.predefinedPeriod.

, , init. , , - .

.

+4

Source: https://habr.com/ru/post/1611178/


All Articles