ApexChart not displaying correctly. Monthly Offset Issue

Hi,
I have a custom:apexcharts-card chart that is not displaying correctly. The issue appears to be that the start of the month is offset by 3 days, the results of the electricity billing cycle which starts on the 4th of each month. I have included the coding for the graph and for the utility meters that generate the results, plus images of the results. The issue is:

The issue is the difference in the values displayed and collected:

Monthly Grid Import Energy General:

Chart

type: custom:apexcharts-card
header:
  show: true
  title: Energy last 4 months
  show_states: false
  colorize_states: true
graph_span: 4month
section_mode: false
update_interval: 1d
span:
  end: month
  offset: +3d
apex_config:
  chart:
    height: 300
series:
  - entity: sensor.monthly_grid_import_energy_general
    name: General
    type: column
    statistics:
      type: state
    group_by:
      func: last
      duration: 1month
    color: "#4269D0"
    float_precision: 2
  - entity: sensor.monthly_grid_import_energy_ev_saver
    name: EV Saver
    type: column
    statistics:
      type: state
    group_by:
      func: last
      duration: 1month
    color: "#F4BD4A"
    float_precision: 2
  - entity: sensor.monthly_solar_energy
    name: Solar
    type: column
    statistics:
      type: state
    group_by:
      func: last
      duration: 1month
    color: "#FF725C"
    float_precision: 2
  - entity: sensor.monthly_solar_to_grid_energy
    name: Export
    type: column
    statistics:
      type: state
    group_by:
      func: last
      duration: 1month
    color: "#6CC5B0"
    float_precision: 2

Utility Meters

monthly_grid_import_energy:
  name: Monthly Grid Import Energy
  unique_id: monthly_grid_import_energy
  source: sensor.grid_import_energy
  cron: 0 0 4 * *
  delta_values: false
  net_consumption: false
  periodically_resetting: false
  always_available: true
  tariffs: [General, EV Saver]
monthly_solar_energy:
  name: Monthly Solar Energy
  unique_id: monthly_solar_energy
  source: sensor.solar_energy
  cron: 0 0 4 * *
  delta_values: false
  net_consumption: false
  periodically_resetting: false
  always_available: true
monthly_solar_to_grid_energy:
  name: Monthly Solar to Grid Energy
  unique_id: monthly_solar_to_grid_energy
  source: sensor.solar_to_grid_energy
  cron: 0 0 4 * *
  delta_values: false
  net_consumption: false
  periodically_resetting: false
  always_available: true

I hope the solution is something that I have overlooked in the chart settings. Any help greatly appreciated.

Regards,
Craig

It appears that the duration in group_by for the series does not work for months. This would be the issue in this case.
Craig

Indeed, the doc mentions this (not too clear but it is there). The alternative is to use statistics which can come grouped by month (is based on HA func.). I am working on a PR to improve the monthly-grouping in Apex but it takes time :slight_smile:

EDIT: and I can recommend to search & post in the large/huge one, which gets more attention, I myself only bumped into yours by coïncidence.
ApexCharts card - A highly customizable graph card - Share your Projects! / Dashboards & Frontend - Home Assistant Community

Thanks for the reply. The reason for apexchart in lieu of statistical is that statistical does NOT offer offset values for the start/end of the month. In other words, both types of graph fail to meet my requirements in some manner.

edit: spelling

I meant: use apex with statistics, check in the link for examples, the docs are thin on this

Thanks. I was using apex with statistics, as can be seen in the attached chart code.

    statistics:
      type: state

Thanks for your attention to this issue.
Craig

Add period: month to the stats and remove the group_by?

Wonderful!

type: custom:apexcharts-card
header:
  show: true
  title: Energy last 4 months
  show_states: false
  colorize_states: true
graph_span: 4month
section_mode: false
update_interval: 1d
span:
  end: month
  offset: +3d
apex_config:
  chart:
    height: 300
series:
  - entity: sensor.monthly_grid_import_energy_general
    name: General
    type: column
    statistics:
      type: state
      period: month
      align: end
    color: "#4269D0"
    float_precision: 2
  - entity: sensor.monthly_grid_import_energy_ev_saver
    name: EV Saver
    type: column
    statistics:
      type: state
      period: month
      align: end
    color: "#F4BD4A"
    float_precision: 2
  - entity: sensor.monthly_solar_energy
    name: Solar
    type: column
    statistics:
      type: state
      period: month
      align: end
    color: "#FF725C"
    float_precision: 2
  - entity: sensor.monthly_solar_to_grid_energy
    name: Export
    type: column
    statistics:
      type: state
      period: month
      align: end
    color: "#6CC5B0"
    float_precision: 2

is returning the correct results.
Craig