0

This the sample code of my AmChartjs, the whole code of the chart is so long.

  // check if drill-down data is avaliable
  if ( event.item.dataContext.data !== undefined) {

    // save for back button
    mostSoldChart.drillLevels.push(event.item.dataContext);

    // replace data
    mostSoldChart.dataProvider = event.item.dataContext.data;

    // replace title
    mostSoldChart.titles[0].text = event.item.dataContext.category;

    // add back link
    // let's add a label to go back to yearly data
    event.chart.addLabel(
      70, 10, 
      "< Go back",
      undefined, 
      13, 
      undefined, 
      undefined, 
      undefined, 
      true, 
      'javascript:mostSoldDrillUp();'); // <------------------------------------

    // take in data and animate
    mostSoldChart.validateData();
    mostSoldChart.animateAgain();
  }
});

function mostSoldDrillUp() { // <----------------------------------------------

  // get level
  mostSoldChart.drillLevels.pop();
  var level = mostSoldChart.drillLevels[mostSoldChart.drillLevels.length - 1];

  // replace data
  mostSoldChart.dataProvider = level.data;

  // replace title
  mostSoldChart.titles[0].text = level.category;

  // remove labels
  if (mostSoldChart.drillLevels.length === 1) {
    mostSoldChart.clearLabels();
  mostSoldChart.titles[0].text = 'Most Sold Products';
  }


  // take in data and animate
  mostSoldChart.validateData();
  mostSoldChart.animateAgain();
}

           }   

        }
    }]);

I have a mostSoldDrillUp function that is from the example in AmCharts site, it is for drillUp purposes or going back to the previous display of chart.

Upon clicking that, error prints in console's browser:

Uncaught ReferenceError: mostSoldDrillUp is not defined at :1:1

Additional Info:

I put the chart in AngularJS directive.

Emjey23
  • 339
  • 1
  • 4
  • 16
  • 1
    You should make sure that your mostSoldDrillUp method is accessible. Has to do with Angular's $scope design. You might find this thread helpful: https://stackoverflow.com/questions/16881478/how-to-call-a-method-defined-in-an-angularjs-directive – Robbert Oct 16 '17 at 05:04
  • Thanks for your comment. I got it. You're right it has to with Angularjs scope. – Emjey23 Oct 16 '17 at 10:12

0 Answers0