Pie chart - data filter prior to aggregation

I have the following scenario:
Multiple devices with battery% attribute.

I want a pie chart that will group different stages e.g. 100 - 80% = Good, 80 - 60% OK, … etc)
To do this, I need to be able to use an expression to filter out the raw data before it becomes aggregated.
Currently the data transformation only works on the aggregated value so if I apply {{value}} >= 80, if the Count is not above 80 it just won’t appear in the chart.

A couple problems with the approach you’re describing …

  1. Your expression - {{value}} >= 80 - will return true or false, which are then cast as numbers to 1 or 0 respectively.
  2. The expression in the pie chart - as well as in the bar and time series graphs - is applied to the data in the browser. This occurs after the data is aggregated on the server. Therefore, the expression isn’t about filtering out certain results so much as it is transforming a result.

The only way I can think of to get what you’re looking for would be to use a custom HTML block or perhaps a custom chart block, which requires applying your own transformation and building out the visual you seek using a JavaScript charting library.

I’ve tried using custom charts but the aggregation is applied over all devices, rather than per device. So I’m unable to apply a data transform to get a count of how many devices had a status of good (e.g. battery% >= 80) as their last received state.

The only work around is to create additional attributes for each state (e.g. good, ok, poor) and populate it as data comes in, but this feels very inflexible. Is there another method to achieve what I’m looking for?