我正在try 更改悬停在amchart4中的Piehart的边框 colored颜色 ,但它不能正确apply.在附件的屏幕截图中,你可以看到第一个切片的边框应用正常,但剩下的两个切片不能正常工作.还分享了我面临这个问题的代码链接.

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>

任何帮助都将不胜感激.

以下是屏幕截图.

enter image description here

enter image description here

for this slice its working properly

推荐答案

发生这种情况是因为切片的顺序.你应该把悬停的那个放在前面:

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

答案可在GIT上找到.

git link

Javascript相关问答推荐

想要检测字符串中的所有单词

如何保持子画布元素的1:1宽高比?

JS生成具有给定数字和幻灯片计数的数组子集

使用json文件字符串来enum显示类型字符串无法按照计算的enum成员值的要求分配给类型号

在React中获取数据后,如何避免不必要的组件闪现1秒?

通过嵌套模型对象进行Mongoose搜索

使用复选框在d3.js多折线图中添加或删除线条

使用javascript将Plotly Expandable Sparkline转换为HighCharter Plot在bslib卡中

当试图显示小部件时,使用者会出现JavaScript错误.

处理时间和字符串时MySQL表中显示的日期无效

如何在coCos2d-x中更正此错误

当我点击一个按钮后按回车键时,如何阻止它再次被点击

如何找到带有特定文本和测试ID的div?

JWT Cookie安全性

ReferenceError:无法在初始化之前访问setData

react 路由DOM有条件地呈现元素

按特定顺序将4个数组组合在一起,按ID分组

我为什么要使用回调而不是等待?

TypeORM QueryBuilder限制联接到一条记录

在传单的图像覆盖中重新着色特定 colored颜色 的所有像素