javascript 在amchart4中,PieChart的悬停边框颜色未正确更改

b5buobof  于 2023-05-21  发布在  Java
关注(0)|答案(1)|浏览(131)

我试图改变边界颜色悬停的PieChart在amchart4,但它不适用于正确的。在所附的屏幕截图中,您可以看到第一个切片边界应用正常,但其余两个切片无法正常工作。也分享了我面临这个问题的codepen链接。
codepen link

// Create chart instance
    var chart = am4core.create("chartdiv", am4charts.PieChart);

   // Add data
chart.data = [{
  "country": "Lithuania",
  "litres": 30
}, {
  "country": "Czech Republic",
  "litres": 30
}, {
  "country": "Ireland",
  "litres": 40
}];

// Add and configure Series
var pieSeries = chart.series.push(new am4charts.PieSeries());
pieSeries.colors.list = [
      am4core.color("#F18D8D"),
      am4core.color("#EFCA4F"),
      am4core.color("#4DB7F6"),
    ];
pieSeries.dataFields.value = "litres";
pieSeries.dataFields.category = "country";

// Let's cut a hole in our Pie chart the size of 40% the radius
chart.innerRadius = am4core.percent(40);
chart.logo.disabled = true;

// Put a thick white border around each Slice
pieSeries.slices.template.stroke = am4core.color("#506276");
pieSeries.slices.template.fillOpacity = 1;
pieSeries.slices.template.strokeWidth = 2;
pieSeries.slices.template.strokeOpacity = 1;

var hs = pieSeries.slices.template.states.getKey("hover");
hs.properties.stroke = am4core.color("white");
hs.properties.fillOpacity = 1;
hs.properties.strokeWidth = 2;

// Add a legend
chart.legend = new am4charts.Legend();

chart.legend = new am4charts.Legend();
chart.legend.itemContainers.template.togglable = false;
chart.legend.position = "bottom";
chart.legend.fontFamily = "sans";
chart.legend.fontSize = 8;
chart.legend.labels.template.fill = "#ffffff";
chart.legend.labels.template.opacity = "0.6";
chart.legend.valueLabels.template.fill = "#ffffff";
chart.legend.valueLabels.template.opacity = "0";
chart.legend.valueLabels.template.align = "left";
chart.legend.valueLabels.template.textAlign = "end";
chart.legend.itemContainers.template.paddingTop = 5;
chart.legend.itemContainers.template.paddingBottom = 5;
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

#chartdiv {
  width: 100%;
  height: 400px;
  background-color: #555;
}
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<div id="chartdiv"></div>

任何帮助将不胜感激。
这里是截图。

mrphzbgm

mrphzbgm1#

这是因为切片的顺序。你应该把悬停的一个放在前面:

pieSeries.slices.template.events.on("over", function(e){
  e.target.toFront()
})

答案在git上。
git link

相关问题