AmCharts:如何访问图例中显示的值
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
。
我试图在使用 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
。