简体   繁体   中英

AmCharts: How to access values showing in legend

I'm trying to manipulate the values that are shown in the legend while hovering over the chart with ChartCursor (i have connected a listener function for it but can't seem to find how each object shows each current value in the legend):

在此处输入图片说明

I have tried accessing with valueText using

chart.legend.valueText

But if i replace the valueText the value set will occur for every object in the legend. I would like to be able to reach every single object in the legend and be able to manipulate each objects' valueText.

The listener is implemented in chartCursor:

"chartCursor": {
        "categoryBalloonEnabled": false,
        "listeners": [{
          "event": "changed",
          "method": cursorChanged
        }]
      },

Does someone know how to accomplish this?

Thanks.

To access the legend values, you have to create a valueFunction inside the legend object:

    "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; 
          }
        }
    },

The valueFunction is called for each graph object that has a visible legend marker.

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM