Javascript 处理ampiechart切片的不同点击

Javascript 处理ampiechart切片的不同点击,javascript,pie-chart,amcharts,Javascript,Pie Chart,Amcharts,我有一个不同切片的安培哈特。我想对每个片段的单独单击执行不同的操作 PieChart.addListener("clickSlice", handleClickPie); function handleClickPie(e) { } 我想做一些类似的事情: 如果ClickSliceNo==1:Action1 如果ClickSliceNo==2:Action2 如果单击SliceNo==3:操作3 如何在handleClickPie()函数中处理这些属性?是的,正如您在注释中

我有一个不同切片的安培哈特。我想对每个片段的单独单击执行不同的操作

PieChart.addListener("clickSlice", handleClickPie);

function handleClickPie(e) {

        }
我想做一些类似的事情:

如果ClickSliceNo==1:Action1

如果ClickSliceNo==2:Action2

如果单击SliceNo==3:操作3


如何在handleClickPie()函数中处理这些属性?

是的,正如您在注释中所指出的,您可以访问切片项目的属性,然后根据需要处理这些属性

以下是一个例子:


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 + ".");
    }
}
#chartdiv {
    width: 100%;
    height: 500px;
    font-size: 11px;
}
CSS

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 + ".");
    }
}
#chartdiv {
    width: 100%;
    height: 500px;
    font-size: 11px;
}
HTML

<div id="chartdiv"></div>

找到它:e.dataItem.value==“SliceName”