Filtering data conditionally within ApexCharts?

Hi
I have some lightning data from a Tempest weather station that I want to display as scatter plot on a ApexChart card. The issue is that the sensor sometimes sends a 0 when there was no lightning so I want to only show the data values greater than 0. Something like

transform: “return x > 0;”

(I already tried it but filtered out all the values)

Is it possible to create it within the transform option of ApexCharts?

type: custom:apexcharts-card
graph_span: 24h
header:
  show: true
  title: Rayos
  show_states: true
  colorize_states: true
all_series_config:
  stroke_width: 1
  show:
    extremas: true
color_list:
  - orange
yaxis:
  - id: rad
    decimals: 1
    opposite: false
chart_type: scatter
series:
  - entity: sensor.st_...._lightning_average_distance
    yaxis_id: rad
    name: Distancia (km)
    opacity: 0.5

Thanks!

Try

series:
  - entity: sensor.mb_solar_power
    transform: "return x >0  ? x : null;"

The transform is just JavaScript, has access to ‘x’ as the data value, and must return a number, float, or ‘null’.

Your test code, as given, just returns a boolean value dependent on x>0

The short conditional test

boolean ? true : false

works as: where x>0 return x, otherwise return ‘null’, and ‘null’ data points are not plotted.

1 Like