- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个包含不同切片的 AmPiechart。我想对每个切片的单独点击执行不同的操作。
PieChart.addListener("clickSlice", handleClickPie);
function handleClickPie(e) {
}
我想做这样的事情:
如果 ClickSliceNo == 1 : Action1
如果 ClickSliceNo == 2 : Action2
如果 ClickSliceNo == 3 : Action3
我如何在 handleClickPie() 函数中处理它?</p>
最佳答案
是的,正如您在评论中指出的那样,您可以访问切片项的属性,然后按照您认为合适的方式处理这些属性。
这是一个例子:
JS
var chart = AmCharts.makeChart("chartdiv", {
"type": "pie",
"theme": "light",
"dataProvider": [{
"country": "Lithuania",
"litres": 501.9
}, {
"country": "Czech Republic",
"litres": 301.9
}, {
"country": "Ireland",
"litres": 201.1
}, {
"country": "Germany",
"litres": 165.8
}, {
"country": "Australia",
"litres": 139.9
}, {
"country": "Austria",
"litres": 128.3
}, {
"country": "UK",
"litres": 99
}, {
"country": "Belgium",
"litres": 60
}, {
"country": "The Netherlands",
"litres": 50
}],
"valueField": "litres",
"titleField": "country",
"balloon": {
"fixedPosition": true
},
"listeners": [{
"event": "clickSlice",
"method": myCustomClick
}]
});
function myCustomClick(e) {
// to see the full api, log out "e"
// console.log(e);
var country = e.dataItem.dataContext.country;
if (country === "Lithunia") {
alert("Lithuania: the home of amCharts.");
} else if (country === "Germany") {
alert("Munich is a city in Germany.");
} else if (country === "Austria") {
alert("Skiing in Austria is awesome.");
} else {
alert("You have clicked " + country + ".");
}
}
CSS
#chartdiv {
width: 100%;
height: 500px;
font-size: 11px;
}
HTML
<div id="chartdiv"></div>
关于javascript - 处理 ampiechart 切片的不同点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36300820/
在 AmChart 中,我可以在没有百分比值和符号的情况下获取饼图旁边的值吗? 这是我指的饼图。 Source: 我想在饼图中显示 (For Czech Republic) 256.9 而不是 31.
有什么方法可以删除 AamPieCharts 中的值和百分比。我想仅在鼠标悬停时显示说明。应该有办法做到这一点。我们可以在 AmPieCharts 中隐藏“valueField”吗?我试图删除它但不起
这是一个示例代码。比如我想拉德国 在页面加载时切片。在这段代码中,它拉取第一个切片。 无功图; var 传说; var chartData = [{ 国家:“立陶宛”, 值:260}, { 国家:“爱
我有一个包含不同切片的 AmPiechart。我想对每个切片的单独点击执行不同的操作。 PieChart.addListener("clickSlice", handleClickPie); func
我是一名优秀的程序员,十分优秀!