2

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).

bart
  • 1,003
  • 11
  • 24
Komal Raj
  • 21
  • 1
  • 5

1 Answers1

3

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.

Samuel Philipp
  • 10,631
  • 12
  • 36
  • 56
  • 1
    You can instead set an adapter for `tooltipText` itself and `return "";` when you want to disable it. A non-blank value for `tooltipText` or `tooltipHTML` is what triggers the tooltip to begin with, so you're basically just undoing that. – notacouch Jul 27 '19 at 06:39