我当前正在显示3个饼图,并且我只想显示一个可以在3个饼图上切换每个切片的图例。我该怎么办?
function createChart(div, data) {
// Create chart
var chart = am4core.create(div, am4charts.PieChart);
// Add data
chart.data = data;
// Add and configure Series
var pieSeries = chart.series.push(new am4charts.PieSeries());
pieSeries.dataFields.value = "litres";
pieSeries.dataFields.category = "country";
chart.legend = new am4charts.Legend();
};
createChart("chart1",[{
"country": "Lithuania",
"litres": 501
}, {
"country": "Czechia",
"litres": 301
}, {
"country": "Ireland",
"litres": 201
}]);
createChart("chart2",[{
"country": "Lithuania",
"litres": 250
}, {
"country": "Czechia",
"litres": 360
}, {
"country": "Ireland",
"litres": 150
}]);
createChart("chart3",[{
"country": "Lithuania",
"litres": 150
}, {
"country": "Czechia",
"litres": 300
}, {
"country": "Ireland",
"litres": 160
}]);
传奇: -立陶宛 -德意志 -爱尔兰
当我单击图例(立陶宛)时,它将使用(立陶宛)的数据切换3个饼图的切片。