apexcharts.js icon indicating copy to clipboard operation
apexcharts.js copied to clipboard

Ability to exclude zero-values from tooltip

Open xobotyi opened this issue 2 years ago • 13 comments

Summary

A have a dynamic data with unknown amount of series for a given time range. As apexcharts not allowing to draw null vlaues as 0 - i had to transform missing data to be 0, but now 0 values appear in tooltip.

API Changes

Add an undefined as tooltip value formatter that means - do not display this item in tooltip.

Or maybe add ability to draw null values as some others values (0 for me).

Intended Use Case

As for now i was not able to find how to exclude zero-values from tooltip of area charts (or, actually, draw missing values as 0). This leads to very high tooltip that occasionally causes page to have a scrollbar and this triggers tooltip to hide.

image

After trying to make nulls work figured that nulls are also displayed within tooltip🤔 image

xobotyi avatar Mar 13 '23 18:03 xobotyi

This can be easy resolved using the tooltip formatter:

tooltip: { y: { formatter: function(value, { series, seriesIndex, dataPointIndex, w }) { if(value){ return value } } } }

pvh-archifact avatar Mar 22 '23 12:03 pvh-archifact

The type of a formatter function does not expect undefined to be returned. There is an issue in types then.

xobotyi avatar Mar 22 '23 12:03 xobotyi

Can you show your example by forking this codepen? https://codepen.io/PlippiePlop/pen/zYJMYYE?editors=0010

pvh-archifact avatar Mar 22 '23 13:03 pvh-archifact

Your codepen is JS-only, im talking about issue with types.

https://github.com/apexcharts/apexcharts.js/blob/main/types/apexcharts.d.ts#L940

It is clearly typed that it always expects a value to be returned.

xobotyi avatar Mar 22 '23 16:03 xobotyi

But even within your codepen the issue persists https://codepen.io/xobotyi/pen/KKxrVzo image

xobotyi avatar Mar 22 '23 16:03 xobotyi

Change 'Y' to 'X'

pvh-archifact avatar Mar 23 '23 08:03 pvh-archifact

what for? x is time and i want to hide some series that has y equals 0

xobotyi avatar Mar 23 '23 08:03 xobotyi

I do not know why you see undefined, if i test it, it either displays 0 or null not 'undefined'

pvh-archifact avatar Mar 23 '23 08:03 pvh-archifact

because i do return it (just like your yesterday example) once again - the goal is to exclude zero\null values from tooltip

xobotyi avatar Mar 23 '23 08:03 xobotyi

Hey, we also experienced this issue when we upgraded to latest version. this is working on version "apexcharts": "3.24.0", "react-apexcharts": "1.3.7", image

but not on version "apexcharts": "3.37.2", "react-apexcharts": "1.4.0", image

melbertdp avatar Mar 23 '23 09:03 melbertdp

Is this what you are looking for? Chart without 0 or null series in tooltip

pvh-archifact avatar Mar 23 '23 11:03 pvh-archifact

yes, but im definely don't want to create my own custom tooltip for that purpose =)

xobotyi avatar Mar 23 '23 11:03 xobotyi

CSS solution:

.apexcharts-tooltip-series-group:has(.apexcharts-tooltip-text-y-value:empty) { display: none !important; }

plonke avatar Apr 24 '24 18:04 plonke

options = {
  tooltip: {
    hideEmptySeries: true
  }
}

As tested on 4.4.0, the above property works well in hiding zero values in a tooltip.

junedchhipa avatar Feb 13 '25 18:02 junedchhipa