[英]AmCharts: How to access values showing in legend
我試圖用ChartCursor將鼠標懸停在圖表上時處理圖例中顯示的值(我已經為其連接了一個偵聽器函數,但似乎無法找到每個對象如何顯示圖例中的每個當前值):
我嘗試使用valueText訪問
chart.legend.valueText
但是,如果我替換valueText,則圖例中的每個對象都會發生值設置。 我希望能夠到達圖例中的每個對象,並能夠操縱每個對象的valueText。
偵聽器在chartCursor中實現:
"chartCursor": {
"categoryBalloonEnabled": false,
"listeners": [{
"event": "changed",
"method": cursorChanged
}]
},
有人知道如何做到這一點嗎?
謝謝。
要訪問圖例值,必須在圖例對象內部創建一個valueFunction
:
"legend": {
// ...
"valueFunction": function(graphDataItem, valueText) {
//check if valueText is empty.
//this only occurs when you're not currently hovered over a value
//and if you don't have a periodValueText set.
if (valueText !== " ") {
//access the current graph's value through the graph.valueField
//inside the graphDataItem parameter,
//or the string version of the value in valueText and manipulate it accordingly
return graphDataItem.dataContext[graphDataItem.graph.valueField]; //current hovered value
} else {
return valueText;
}
}
},
每個具有可見圖例標記的圖形對象都會調用valueFunction
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.