Not Sure How Apex Chart "Statistics" Function

According to the information here…

Apex Charts custom card can be told to use HA Statistics for the graphs, but I don’t see an example of how to do that. What I’d like is to have a year long monthly graph showing the DIFFERENCE in data used month to month. I can’t figure it out.

Here’s what I have without using statistics…

type: custom:apexcharts-card
graph_span: 1month
update_interval: 1d
header:
  show: true
  title: Monthly Internet Data Consumption
  show_states: true
  colorize_states: true
series:
  - entity: sensor.freebsd_router_b_received
    color: rgb(10, 55, 58)
    type: column
    name: Received
    group_by:
      func: diff
      duration: 1w
  - entity: sensor.freebsd_router_b_sent
    color: rgb(255, 152, 0)
    type: column
    name: Transmitted
    group_by:
      func: diff
      duration: 1w

This shows one month, stacked by week, but if I try to expand the chart past that, it crashes the card. I’m thinking because I don’t have history that long. I’d like to convert that to use statistics, and show the increase each month for the last year. This is easy on the statistics graph card, but there are no configuration options to speak of for that card.

Any ideas what I’m doing wrong?

Thanks!

Example:

series:
  - entity: sensor.havingstatistics
    offset: '-10d'
    statistics:
      type: sum
      period: hour
      align: start
1 Like

Thanks!

Here is what I have now…

type: custom:apexcharts-card
graph_span: 1y
update_interval: 1d
header:
  show: true
  title: Monthly Internet Data Consumption
  show_states: true
  colorize_states: true
series:
  - entity: sensor.freebsd_router_b_received
    color: rgb(10, 55, 58)
    type: column
    name: Received
    statistics:
      type: sum
      period: month
      align: start
  - entity: sensor.freebsd_router_b_sent
    color: rgb(255, 152, 0)
    type: column
    name: Transmitted
    statistics:
      type: sum
      period: month
      align: start

This seems to be grouping everything correctly. I just reset the HA database, so there isn’t anything except the current month to report on just yet. I left out the “offset” in your example. I’m not sure if that matters.

Since I have you, are you aware if it’s possible to convert the number displayed from bytes (what it’s stored as) to megabytes? To shorten the number displayed?

Thanks for your help!

Just an update…

The “transform” option allows you divide the results and shorten the number, but it still shows that the result is in bytes. So although the number gets smaller as it’s transformed into kb or mb, it lists that smaller number as bytes which is wrong.

Getting closer though…

Never did this before but a bit of digging in below HUGE thread helped

ApexCharts card - A highly customizable graph card - Share your Projects! / Dashboards & Frontend - Home Assistant Community (home-assistant.io)

THIS is just me fiddling around, the values/lables make no sense

type: custom:apexcharts-card
header:
  title: TEST
  show: true
  floating: false
  show_states: true
apex_config:
  legend:
    show: false
  show_states:
    formatter: |
      EVAL:function(value, opts) {
        u = Math.floor(value);
        m = Math.floor((value - u) * 60);
        result = "";
        if (u > 0)
          result = u + "u ";
        if (m > 0)
          result += m + "m";
        return result;
      } 
  yaxis:
    - id: temperature
      labels:
        formatter: |
          EVAL:v => `${Math.round(v)}°C`
  dataLabels:
    formatter: |
      EVAL:v => `${Math.round(v)}°C`          
series:
  - entity: weather.home
    name: Accuweather
    type: column
    show:
      as_duration: hour
      datalabels: true
    data_generator: |
      return entity.attributes.forecast.map((entry) => {
            return [new Date(entry.datetime), entry.temperature];
          });
1 Like

For those following along at home, you can add a “unit:” line and specify what you want displayed…

series:
  - entity: sensor.freebsd_router_b_received
    color: rgb(10, 55, 58)
    type: column
    name: Received
    statistics:
      type: sum
      period: month
      align: start
    transform: return x / 1073741824;
    unit: GB