我使用 amchart 4 创建了一个XYChart,更准确地说是一个堆积柱形图,我想让列标签可点击。这是我所做的(用一点树枝):
var chart = am4core.create("chartdiv", am4charts.XYChart);
chart.data = [
{
'CategoryAxis' : 'Column label 1',
{% for valueAxis in listValueAxes %}
'{{ valueAxis.name }}': {{ valueAxis.numericalValue }},
{% endfor %}
},{
'CategoryAxis' : 'Column label 2',
{% for valueAxis in listValueAxes %}
'{{ valueAxis.name }}': {{ valueAxis.numericalValue }},
{% endfor %}
}
];
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "CategoryAxis";
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.renderer.labels.template.disabled = true;
var label = categoryAxis.renderer.labels.template;
function createSeries(field) {
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueY = field;
series.dataFields.categoryX = "CategoryAxis";
series.stacked = true;
return series;
}
{% for valueAxis in listValueAxes %}
series = createSeries('{{ valueAxis.name }}');
// Clickable cells
series.columns.template.url = "{{path('viewValueAxis', {'id':valueAxis.id})}}";
{% endfor %}
该url
属性的最后一行允许单击列的“单元格”并重定向到专用于所表示值的页面。我想让列的标签也可以点击。我试图做这样的事情:
{% for categoryAxis in listCategoryAxes %}
label.events.on("hit", function(){
window.location.href = "{{path('viewCategoryAxis', {'id':categoryAxis.id})}}";
}, this);
{% endfor %}
问题是标签没有被独立处理,它们重定向到同一页面。我想使用该url
属性,但点击的目标是在标签上而不是列本身。我会使用类似的东西series.columns.template.labels.url
或者可能是该urlTarget
属性,但这些似乎都不起作用。