Komal Raj
Komal Raj

Reputation: 21

In amcharts, is there any way to show tooltips text according to condition?

I want to show tooltips text in the chart according to my condition. If my text value is 0 then I want to hide text otherwise show the text of the tooltip.

Series.columns.template.tooltipText = `{valueY}s`;

It gives value according to {valueY}. but I want to it doesn't show when {valueY} is equal to 0(zero).

Upvotes: 2

Views: 3236

Answers (1)

Samuel Philipp
Samuel Philipp

Reputation: 11040

You can use an adapter for the tooltip disabled property:

var series = chart.series.push(new am4charts.ColumnSeries());
// ...
series.tooltipText = "{valueY.value}s";

series.tooltip.adapter.add("disabled", function(disabled, target) {
  if (target.dataItem && target.dataItem.values.valueY.value === 0) {
    return true;
  }
  return disabled;
});

Alternatively for target.dataItem.values.valueY.value === 0 you can use target.dataItem.dataContext.yourProperty === 0.

Here is a code pen, which shows the result.

Upvotes: 3

Related Questions