amcharts / amcharts4

The most advanced amCharts charting library for JavaScript and TypeScript apps.
https://www.amcharts.com/
1.16k stars 321 forks source link

"Cannot read property 'downPointers' of undefined" when changing chart.data #983

Closed RobbiesCode closed 5 years ago

RobbiesCode commented 5 years ago

While trying to build a Column Chart Drill Down example I came accross this error message:

Cannot read property 'downPointers' of undefined

I am only replacing data with a new array (to show "drill down" items):

series.columns.template.events.on("hit", function(e){

  // update series datafields
  chart.series.getIndex(0).dataFields.valueY = "value";
  chart.series.getIndex(0).dataFields.categoryX = "category";

  var country = e.target.dataItem.dataContext.country;

  chart.data = sub_data[country];

});

Codepen demo: https://codepen.io/team/amcharts/pen/a501be0585aa103b3df5216b3932db98?editors=1010

martynasma commented 5 years ago

On click, you update categoryX data field of the series, but category data field of the category axis remains old one. Need to update it as well:

chart.xAxes.getIndex(0).dataFields.category = "category";
RobbiesCode commented 5 years ago

Of course, overlooked that completely. Thanks!

RobbiesCode commented 5 years ago

Actually, the error is still there, even after update the category of the X Axis. I think it has to do with the hover or hit event. The columns are replaced, while the mouse is still over the column...

// throws error
series.columns.template.events.on("hit", function(e){
  displayChildData();
});

// no error
series.columns.template.events.on("hit", function(e){
  setTimeout(displayChildData, 100);
});

displayChildData function:

  function displayChildData(){

    // update series datafields
    chart.series.getIndex(0).dataFields.valueY = "value";
    chart.series.getIndex(0).dataFields.categoryX = "category";

    categoryAxis.dataFields.category = "category";

    var country = e.target.dataItem.dataContext.country;

    chart.data = sub_data[country];

  }
martynasma commented 5 years ago

Fixed in 4.2.3.

[4.2.3] - 2019-03-14

Fixed

Full change log.

Make sure you clear your browser cache after upgrading. And feel free to contact us again if you are still experiencing this issue.