我试图在使用 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
。
关于javascript - AmCharts:如何访问图例中显示的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41000354/