2016-03-30 13 views
5

Farklı dilimleri olan bir AmPiechart'ım var. Her dilimin tek tek tıklamaları için farklı eylemler gerçekleştirmek istiyorum.Ampiechart dilimlerinin farklı tıklamalarını yönetme

PieChart.addListener("clickSlice", handleClickPie); 

function handleClickPie(e) { 

     } 

ben böyle bir şey yapmak istiyorum:

Eğer ClickSliceNo == 1: ACTION1

Eğer ClickSliceNo == 2: ACTION2

ClickSliceNo == 3 ise: Action3

Bunu, handleClickPie() işlevinde nasıl kullanırım?

+0

It Bulunan: e.dataItem.value == "SliceName" –

cevap

1

Evet, yaptığınız yorumda da belirtildiği gibi, dilim öğesinin özelliklerine erişebilir ve ardından bu özellikleri uygun gördüğünüz gibi kullanabilirsiniz.


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

0123: İşte

bir örnektir
#chartdiv { 
    width: 100%; 
    height: 500px; 
    font-size: 11px; 
} 

HTML

<div id="chartdiv"></div> 
İlgili konular