我正在Angular6中使用amCharts4创建一个堆叠的条形图,我想在categoryX(标签)上添加一个点击侦听器,但找不到任何内容。
我已经按照他们的文档中的值在valueY上添加了点击监听器,但标签方面没有任何内容。
let chart = am4core.create("chart-id", am4charts.XYChart);
// Create axes
let categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "category";
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.renderer.minGridDistance = 30;
let valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
// Create series
for (const key in chartData.categories) {
if (chartData.categories.hasOwnProperty(key)) {
let series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueY = key;
series.dataFields.categoryX = "category";
series.name = key;
series.columns.template.tooltipText = "{name}: [bold]{valueY}[/]";
series.columns.template.fillOpacity = .8;
series.stacked = true;
series.columns.template.events.on("hit", (ev)=>{
let item:any = ev.target.tooltipDataItem
console.log("clicked on ", item.component.name, item.categoryX);
}, this);
if(this.get_category_color(key)){
series.columns.template.fill = am4core.color(this.get_category_color(key));
}
}
}
// chart.add
chart.cursor = new am4charts.XYCursor();
chart.data = chartData.dataProvider