RomRider / apexcharts-card

📈 A Lovelace card to display advanced graphs and charts based on ApexChartsJS for Home Assistant
MIT License
1.15k stars 78 forks source link

group_by historical values are volatile/fluctuate (show different historical values - affected by time the chart is rendered) #652

Open d123456temp opened 8 months ago

d123456temp commented 8 months ago

Checklist

Describe the bug Depending on the time (during the day) when I run/display the chart card, the historical chart entries are different. See the attached screenshot of the same bar chart top left of the screenshot - every time the values shown are different. What I noticed is that the popup shows date and time and the time part equals to the time of the rendering. Yes, I'm sure the data are not altered, the only thing that fluctuate is the rendered bar chart.

See chart definition below.

Version of the card Version: latest release

To Reproduce This is the configuration I used:

- type: custom:apexcharts-card
        graph_span: 10d
        update_interval: 1d
        header:
          show: true
          title: Person count
        series:
          - entity: sensor.zoom_person_count
            type: column
            name: zoom
            group_by:
              func: sum
              duration: 1day
          - entity: sensor.second_person_count
            type: column
            name: fixed
            group_by:
              func: sum
              duration: 1day

Screenshots If applicable, add screenshots to help explain your problem. charts_20240111_133601 chart_20240111_215619 2024-01-10

Expected behavior Historical data presentation should be stable and exactly the same no matter when chart is rendered.

Desktop (please complete the following information):

edwardhorsford commented 7 months ago

@d123456temp I came across it too - I agree it's not ideal. If not default, it would be good if the group by had an option to align to some period that relates to the group duration.

As a temporary solution, if you set a start or end time, that 'pins' the grouping to that period.

Example:

span:
  end: hour
benkrejci commented 5 months ago

+1

It's hard to imagine a use-case in which this is the desired behavior for grouping (align the buckets to the current time, rather than a static value that would be stable over time).

  1. One option would be to always align the last bucket end to the soonest future multiple of the group_by.duration (if the series is grouped). E.g. if the duration is 1m and the current time is 10:21:48, align the end of the last bucket to 10:22:00
  2. ~Another option would be to overload the span option so that if you provide a start or end value that is less than the graph_span, you would get this behavior of snapping the start/end of the graph to the nearest multiple of the provided span value. This is actually what I thought span was for until I read it more carefully. E.g. if you provide a span.end value of 1m and it is less than the graph_span value of 30m, then the whole graph would just line up to the nearest minute.~

Update: I had tried the span.start and it did not produce a desired result, but hadn't tried span.end. I Agree with @edwardhorsford that somewhat counterintuitively, this does do what I want. I still think maybe the default bucket alignment for grouped series should be updated.

github-actions[bot] commented 3 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

edwardhorsford commented 3 months ago

Commenting to keep alive.

RomRider commented 2 months ago

There's no default alignment with bucketing, that's what end and start are made for.

github-actions[bot] commented 2 weeks ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

edwardhorsford commented 2 weeks ago

It feels counterintuitive and not ideal that in effect over time graphs using this will fluctuate as the bucket moves. I wonder if this default is worth changing or adding guidance for?