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
.