简体   繁体   中英

amCharts pie chart how to customize the balloon text

I am using amCharts pie chart (v3) and I want to customize the pop up balloon that comes on mouseover on a slice: in addition to routine text like [[value]] [[percent]] ,

  • (a) a text that depends on the data item, and

  • (b) provide different click options to the user depending on data item. Every data row might not have these possibilities in which case the options should not appear.

For example, the pie chart might show wine consumption by country. On hover, I want to provide the user two different click options - one to see consumption by season if available, plus another to see consumption by age group if available.

Is it possible to do so in amCharts? I saw an exit for event clickSlice() here http://docs.amcharts.com/3/javascriptcharts/AmPieChart but nothing on how to modify the balloon text on the fly and add behavior to the balloon that comes on hover.

Will greatly appreciate your help.

You can use the following tags: [[title]], [[description]], [[value]] and [[percent]]. says the documentation.

I have used description for a custom field, it works fine.

You can add any custom field to your data provider and then display it in your balloon in the same way as value:

{value:15, title:"slice title", someCustomField:"some custom data"}

and then:

chart.balloonText = "[[someCustomField]]";

For writing dynamic text in the balloon you can also do the folowing:

"graphs": [{
    "balloonFunction": function(graphDataItem, graph) {
      var value = graphDataItem.values.value;
      if (value < 500) {
        return value + "<br>(Little)";
      } else {
        return value + "<br>(A Lot)";
      }
    }
  }],

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