amcharts / amcharts5

The newest, fastest, and most advanced amCharts charting library for JavaScript and TypeScript apps.
328 stars 90 forks source link

Adding custom tooltip and legend in amcharts 5 #1609

Closed ankurssharma96 closed 2 weeks ago

ankurssharma96 commented 2 weeks ago

Hello,

I am using amCharts 5 to create a simple tree map. I would like to define a custom tooltip when the user hover over chart And would also like to add a legend to enable/disable different category fields

martynasma commented 2 weeks ago

Please refer to these tutorials: https://www.amcharts.com/docs/v5/charts/hierarchy/#Tooltips https://www.amcharts.com/docs/v5/charts/hierarchy/#Legend

ankurssharma96 commented 2 weeks ago

Hi @martynasma, The above reference helped in adding the legends, Thank You! For tooltip, tooltipText is working but I am looking to add tooltipHTML. Can you please provide some reference for tooltipHTML.

ankurssharma96 commented 2 weeks ago

Hi @martynasma, I am trying to add adapter for tooltip but its not working: series.nodes.template.adapters.add("tooltipHTML", (_, data) => { return tooltipText(get(data, "dataItem.dataContext")); });

Any help or suggestion would be really appreciated. Thanks!

martynasma commented 2 weeks ago

You need to set tooltipHTML on a node before adapters would kick in. It can be set to anything - it will be modified by an adapter anyway:

series.nodes.template.set("tooltipHTML", "  ");
series.nodes.template.adapters.add("tooltipHTML", (_, data) => {
  return tooltipText(get(data, "dataItem.dataContext"));
});
ankurssharma96 commented 2 weeks ago

hi @martynasma, this did not help. Adapter is not getting added, have tried the above reference. Tooltip is only getting set to empty string from first line.

martynasma commented 2 weeks ago

Make sure that adapter is added before data is set on the series.

ankurssharma96 commented 2 weeks ago

It worked, thanks a lot!