javascript - AmCharts:如何访问图例中显示的值

标签 javascript charts amcharts

我试图在使用 ChartCursor 将鼠标悬停在图表上时操纵图例中显示的值(我已为其连接了一个监听器函数,但似乎无法找到每个对象如何显示图例中的每个当前值):

enter image description here

我尝试使用 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

Demo

关于javascript - AmCharts:如何访问图例中显示的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41000354/

相关文章:

c# - Windows Form C# Graph Axes Label on both X & Y axes

javascript - 将 PHP 与 JavaScript 结合使用时出现意外的 token 错误

javascript - CSS 媒体打印查询

angular - amcharts 堆叠条形图 - 响应事件突出显示值(更改 alpha)

AMCharts Maps v4 - 有没有办法在 heatLegend 中拥有两种以上的颜色?

javascript - JSON 和二进制数

javascript - 如何将目标 ="blank"添加到 Pinboard.in Linkroll 小部件?

javascript - 页面上每个事件的 JS : Is that possible to show empty browser status line,

javascript - 以 block 的形式运行 HTTP 请求

charts - 在圆环图内显示 "data"的值 - AmCharts