如何使用amcharts4使用共享的图例单击来操作多个饼图?

时间:2019-06-20 12:07:10

标签: javascript pie-chart amcharts4

我当前正在显示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个饼图的切片。

0 个答案:

没有答案