![enter image description here](https://i.stack.imgur.com/vmq8n.png)
У меня круговая диаграмма с легендами, созданными с использованием диаграмм Am4, но мне нужно отобразить только 5 лучших значений легенды. Я написал следующий код:
var chart = am4core.create("chartdiv2", am4charts.PieChart);
chart.hiddenState.properties.opacity = 0; // this creates initial fade-in
// Add data
chart.data = [{
"country": "Lithuania",
"litres": 501.9
}, {
"country": "Czech Republic",
"litres": 301.9
}, {
"country": "Ireland",
"litres": 201.1
}, {
"country": "Germany",
"litres": 165.8
}, {
"country": "Belgium",
"litres": 60
}, {
"country": "The Netherlands",
"litres": 50
}];
// Set inner radius
chart.innerRadius = am4core.percent(50);
//Add label
var label = chart.seriesContainer.createChild(am4core.Label);
label.text = "200";
label.horizontalCenter = "middle";
label.verticalCenter = "middle";
// label.fontSize = 50;
// Add and configure Series
var pieSeries = chart.series.push(new am4charts.PieSeries());
pieSeries.dataFields.value = "litres";
pieSeries.dataFields.category = "country";
pieSeries.slices.template.stroke = am4core.color("#fff");
pieSeries.slices.template.strokeWidth = 2;
pieSeries.slices.template.strokeOpacity = 1;
pieSeries.ticks.template.disabled = true;
pieSeries.labels.template.disabled = true;
// This creates initial animation
pieSeries.hiddenState.properties.opacity = 1;
pieSeries.hiddenState.properties.endAngle = -90;
pieSeries.hiddenState.properties.startAngle = -90;
pieSeries.legendSettings.labelText = '{category}';
pieSeries.legendSettings.valueText = null;
pieSeries.labels.template.text = "{category}: {value}";
pieSeries.slices.template.tooltipText = "{category}: {value}";
chart.legend = new am4charts.Legend();
chart.legend.fontSize = 10;
chart.legend.markers.template.width = 10;
chart.legend.markers.template.height = 10;
Мне нужны только Литва, Чехия, Ирландия, Германия и Бельгия, чтобы появиться в легенде, но в настоящее время они все появляются. На рисунке я выделил значения легенды, которые не должны отображаться.
Я пытался использовать массив legend.data, но он всегда возвращает пустой массив.
Как мне решить эту проблему?