0

I have this code in JS and I need to make it work in TypeScript.

   series2.events.on("dataitemsvalidated", function() {
      var data = [];
      series2.dataItems.each(function(dataItem) {
        data.push({ name: dataItem.categoryY +": " + dataItem.valueX + "%", fill: dataItem.column.fill, seriesDataItem: dataItem })
      })
      chart.legend.data = data;


      chart.legend.itemContainers.template.events.on("toggled", function(event) {
        var seriesDataItem = event.target.dataItem.dataContext.seriesDataItem;
        console.log(seriesDataItem)
        if (event.target.isActive) {
          seriesDataItem.hide(series2.interpolationDuration, 0, 0, ["valueX"]);
        }
        else {
          seriesDataItem.show(series2.interpolationDuration, 0, ["valueX"]);
        }
      })
    })

This function i used in Amchart and it has an issue with this line event.target.dataItem.dataContext.seriesDataItem

Praveen
  • 1,772
  • 3
  • 24
  • 42

2 Answers2

0

Changing the type of event to any should work:

chart.legend.itemContainers.template.events.on("toggled", function(event:any) {})
zhulien
  • 5,145
  • 3
  • 22
  • 36
Mashoor
  • 1
  • 1
0

This should do it.

const ctx = event.target.dataItem.dataContext as any;
const seriesDataItem = ctx && ctx.seriesDataItem;

So you can then use the right interface for your event, see amcharts4 or amcharts5.

Christopher
  • 592
  • 9
  • 31