Need help - how to graph last value of every month with apexcharts?

Hi,

I would like to have a graph in apex showing the kilometres I drive every month. I have created a utility helper with a state class total_increasing, which has a monthly cycle. This helper collects the values from the odometer of my car.
The graph should show one value per month, i.e. the last recorded for each month, usually the last day, except for the current month for which this is the current day.

I can’t figure out how to select the data to be plotted. Any ideas?

Many thanks
Christian

You would need to use the “statistics” option to pull out long term statistics, along the lines of:

statistics:
  type: state
  period: month

Read this too. I have not done exactly what you’re after, and I suspect by using “total_increasing” you might find the statistics keep increasing beyond the end of month cycle. If this is the case, you could try using “measurement” instead, and change to “type: max”, which would plot the maximum value for the month. You also have to watch out for when the cycle resets, as if this happens even a second after the end of month, the maximum for the new month will be the same as for the old.

Thanks Michael.
I only have data for this month, so I can’t see the result yet.
As to the cycle reset time, this should not be a problem as I’m tracking the monthly mileage of my car and the data source is the odometer of my car which never reset obviously.

Ah yes, you said odometer, but I read trip meter - and I was thinking I wouldn’t remember to reset the trip meter every month :rofl:. BTW long-term statistics can be a bit confusing - the database records mean, min, max, state and sum - but not all get values as it depends on state class. If you pick for example ‘mean’ in apexcharts, you might get nothing because that’s only recorded if the state class is measurement.