ApexCharts card - A highly customizable graph card

Thanks again for the tip, I’ve been researching and I think I’m almost there (I’m not 100% sure) but if possible I need help for the last mile. Below the code I’m using and the string format (I’ve made some changes to the sql that generate the string do adjust to json format). From a javascrip console I see the result to be very similar to format required, but since I can not debug on the card it self, is not been easy this last step:

type: 'custom:apexcharts-card'
graph_span: 3d
span:
  end: day
header:
  show: true
  title: Consumo diário
series:
  - entity: sensor.consumo_electricidade_apex
    type: column
    data_generator: |
      return JSON.parse('[{"a":2021-4-19, "b":9.61}, {"a":2021-4-20,
      "b":5.1}]').forEach((obj) => { 
       return [new Date(obj.a), obj.b]; 
      });

Any help will be highly appreciated :slight_smile:
Note - I’m using the string directly, but final goal is to pass a sensor with a string to be converted.
Many thanks in advance for any help.

You can use layout: minimal to do exactly that. There’s an example here.

thank you.
But it has problems filling whole the space:

Playing with card and graphs height I succeeded in PC browsers (Firefox/Chrome) but on iPhone bottom border is always shown, and any graph size modification expands card size vertically.

And one more thing. With layout:minimal, it seems that separate min/max for y-axes don’t work :frowning:

source code:

type: 'custom:mod-card'
style: |
  :host {padding: 0px 13px}
card:
  type: vertical-stack
  cards:
    - type: 'custom:apexcharts-card'
      style: |
        host: {height: 150px !important;
        }
      hours_12: false
      graph_span: 24h
      layout: minimal
      apex_config:
        chart:
          height: 150px
        yaxis:
          - show: true
            min: 15
            max: 30
          - show: true
            min: 40
            max: 70
      series:
        - entity: sensor.pcroom_temperature
          color: var(--accent-color)
          name: temp
          stroke_width: 1
          type: area
          opacity: 0.2
        - entity: sensor.pcroom_humidity
          color: '#3498db'
          name: hum
          stroke_width: 1
          type: area
          opacity: 0.2 

Hey and thanks for this feature.

I’m just struggling with the column width. I did a

group_by: 
duration: 1d

so i expected that the column will be wide as the whole day is on x axis. But this did not happend.
I would like to show a max value on HA utility meter of rain precipitation. My setup look like this.

Thank you for help.
Jan

Hello,

I have the following graph:

type: 'custom:apexcharts-card'
update_interval: 5min
graph_span: 2d
span:
  end: hour
header:
  show: false
series:
  - entity: sensor.1og_mobium2_scd30_co2
    type: line
    name: Küche CO2
    group_by:
      func: avg
      duration: 10min
  - entity: sensor.1og_mobium2_formaldehyd_ug_m3
    type: line
    name: Küche Formaldehyd
    group_by:
      func: avg
      duration: 10min
  - entity: sensor.1og_mobium2_sgp30_eco2
    type: line
    name: Küche eCO2
    group_by:
      func: avg
      duration: 10min

I would like to show extremas in my graph. Is this possible?
I tried like this:

type: 'custom:apexcharts-card'
update_interval: 5min
graph_span: 2d
span:
  end: hour
header:
  show: false
series:
  - entity: sensor.1og_mobium2_scd30_co2
    type: line
    name: Küche CO2
    group_by:
      func: avg
      duration: 10min
    series.show:
     extremas: true
  - entity: sensor.1og_mobium2_formaldehyd_ug_m3
    type: line
    name: Küche Formaldehyd
    group_by:
      func: avg
      duration: 10min
  - entity: sensor.1og_mobium2_sgp30_eco2
    type: line
    name: Küche eCO2
    group_by:
      func: avg
      duration: 10min

But than I get this error:

/// apexcharts-card version 1.8.2 /// value.series[0] is not a ChartCardSeriesExternalConfig; value.series[0].series.show is extraneous

should be formatted like…

series:
  - entity: sensor.octopus_electricity_agile_cost_30days
    show:
      extremas: true

Thank you very much!
Works !

Best regards,
Stefan

I would like to format the Y axis with a leading currency symbol. According too Options (Reference) > yaxis – ApexCharts.js the following should work, but the ApexChart card is blank. Any ideas?

type: 'custom:apexcharts-card'
series:
  - entity: octopusagile.monthly_cost
apex_config:
  yaxis:
    labels:
      formatter: |
        function (val, index) {return "£" + val}

You’ll have to use the latest beta for this to work, and the format is also slightly different:

Thanks - what’s the best way to try the beta? Overwrite /config/www/community/apexcharts-card/apexcharts-card.js with pexcharts-card.js. I see there is also a .gz file in that directory.

I’d like to make a chart (change the existing bar-card) to display the current power consumption / room (some kind of realtime data). I have the sensors for it but I can’t make it to work. Have no clue how to do it to display only current sensor values and not the historical data. How can I achieve this? Thank you.

What were you going to say?

Enable the beta versions in HACS for apexcharts-card and you’ll see the beta version:
In HACS → Frontend → look for apexcharts-card → click the 3 dots on the card → reinstall → show beta versions

1 Like

Thanks - new EVAL works great as seen below.
Is there a way to get use the sensor ‘unit_of_measurement’ attribute in the JavaScript? I could then make this more generic and use it in templates.

apex_config:
  yaxis:
    labels:
      formatter: |
        EVAL:function (val) {
          return "£" + val.toFixed(0);
        }

How do you have data for the past 30days, is your recorder history 30days long? Or is this using some other data source? I would love to have history like this for a few things for charts, but right now I only have 3 days of history to limit the database size.

I wanted to keep electricity usage and cost long term so decided to put it into InfluxDB. I use the InfluxDB dashboard and charts to dig into the data, and query the trailing 30 days into a sensor for a quick glance on HA dashboard. Setup so far:

An alternative approach would be to query InfluxDB from within data_generator via REST API but felt it would be cumbersome to hard-code connection URL, username, password, database name, query etc + manipulating the data + error checking all into the card.

2 Likes

Today I lost my complete Lovelace setup :roll_eyes: and I don’t have it backed up.
My chance to create a new one… :rage:
Some questions regarding the screenshot below:

  • Diagram background: How could I make the backgroud of the diagram (the red area) be not transparent. I assume, transparency comes from the day and night theme…

  • Hover box: I would like to have only day and month in the box header - no year and time

  • Values shown: Today is April 22nd, but the diagram shows a value for tomorrow, April 23rd. What to do that the diagram end today and not tomorrow?

  • Y-Axis: How could I force the numbers to be something more even. Maybe 50, 100, 150 … 250 or 75, 100, 125, … 225. But I don’t want to fix the min and max of the axis i.e. to 50 till 250…

Here my code:

type: 'custom:apexcharts-card'
card_mod:
  class: top-level-graph
graph_span: 4w
update_interval: 1h
span:
  end: day
header:
  show: true
  title: '7-Tage Inzidenz [4w]'
  show_states: true
  colorize_states: true
apex_config:
  yaxis:
    decimalsInFloat: 0
    seriesname: seriesname
  labels:
    show: boolean
    labels:
      format: dd-MM
  markers:
    size: 2
    colors: white
    strokeColors: black
    strokeWidth: 2
    hover:
      size: 7
  stroke:
    width: 3
  annotations:
    position: back
    yaxis:
      - 'y': 0
        y2: 50
        fillColor: '#ADFF2F'
      - 'y': 50
        y2: 100
        fillColor: '#FFA500'
      - 'y': 100
        y2: 2000
        fillColor: '#FF0000'
  legend:
    show: false
series:
  - entity: sensor.rki_covid_germany_incidence
    type: line
    color: red
    float_precision: 0
    name: Deutschland
    group_by:
      func: last
      duration: 1d
  - entity: sensor.rki_covid_nrw_incidence
    type: line
    color: blue
    float_precision: 0
    name: NRW
    group_by:
      func: last
      duration: 1d
  - entity: sensor.rki_covid_koln_incidence
    type: line
    color: green
    float_precision: 0
    name: Köln
    group_by:
      func: last
      duration: 1d
style: |
  ha-card {
    font-size: 20px;
  }

The can be set using the following - see tooltip – ApexCharts.js

apex_config:
  tooltip:
    x:
      format: ddd dd MMM
1 Like

Wow, yeah that is a good implementation. I have tried to create cards with a Grafana chart from InfluxDB but could never get it to work reliably due to some ingress issue with Grafana. But your method skips all that mumbojumbo and gets the data back into HA directly. If you could put the script on GitHub I’d love to take a look, I have a few charts I’d like to use this method for including exactly what you have for electricity.

Does someone know how to put this into a type: column graph?
The bars with a gray background for workdays.

type: 'custom:apexcharts-card'
graph_span: 2w
span:
  end: day
header:
  show: true
  title: 'Neue Fälle - NRW [2w]'
series:
  - entity: binary_sensor.workday_sensor
    transform: 'return x === "on" ? 1 : 0;'
    name: ' '
    type: area
    color: grey
    opacity: 0.2
    stroke_width: 0
    curve: stepline
    group_by:
      func: min
    show:
      legend_value: true
      in_header: false
      name_in_header: false
      datalabels: false

type: 'custom:apexcharts-card'
graph_span: 2w
span:
  end: day
header:
  show: true
  title: 'Neue Fälle - NRW [2w]'
series:
  - entity: sensor.rki_covid_nrw_deltacases
    color: blue
    type: column
    group_by:
      func: max
      duration: 24h

When I just add the source, it look’s like this: