ApexCharts card - A highly customizable graph card

Any way to get color threshold fills to work with values below zero?

image

Series config.
yaxis:
  - id: temperature
    show: true
    apex_config:
      tickAmount: 7
      decimalsInFloat: 0
      forceNiceScale: true
      title:
        text: Temperature
        rotate: -90

series:
  - entity: sensor.outdoor_temperature
    name: Temperature
    yaxis_id: temperature
    fill_raw: 'null'
    type: area
    stroke_width: 1
    opacity: 0.5
    color: rgb(255, 179, 0)
    color_threshold: &temp_colors
      - value: -70
        color: rgb(115, 70, 105)
      - value: -55
        color: rgb(202, 172, 195)
      - value: -40
        color: rgb(162, 70, 145)
      - value: -25
        color: rgb(143, 89, 169)
      - value: -15
        color: rgb(157, 219, 217)
      - value: -8
        color: rgb(106, 191, 181)
      - value: -4
        color: rgb(100, 166, 189)
      - value: 0
        color: rgb(93, 133, 198)
      - value: 1
        color: rgb(68, 125, 99)
      - value: 10
        color: rgb(128, 147, 24)
      - value: 21
        color: rgb(243, 183, 4)
      - value: 30
        color: rgb(232, 83, 25)
      - value: 47
        color: rgb(71, 14, 0)

This tool is brilliant! Thanks to RomRider for the effort.

I’ve tried to get the simple bar charts to stack, reducing amount of bars and grouping till nothing was left. After an hour or so, I decided to to a vanilla test by changing the default example to a stacked bar chart… lo and behold, same result, no stacking… will post on github as well:

type: custom:apexcharts-card
apex_config:
  stacked: true
header:
  show: true
  title: ApexCharts-Card
  show_states: true
  colorize_states: true
series:
  - entity: sensor.power_consumption
    type: column
    data_generator: |
      // REMOVE ME
      const now = new Date();
      const data = [];
      for(let i = 0; i <= 24; i++) {
        data.push([now.getTime() - i * 1000 * 60 * 60, Math.floor((Math.random() * 10) + 1)])
      }
      return data.reverse();
  - entity: sensor.power_generation
    type: column
    data_generator: |
      // REMOVE ME
      const now = new Date();
      const data = [];
      for(let i = 0; i <= 24; i++) {
        data.push([now.getTime() - i * 1000 * 60 * 60, Math.floor((Math.random() * 10) + 1)])
      }
      return data.reverse();

Hi!, can someone helpme to make this image
to look like this one image
here is my config

type: custom:apexcharts-card
chart_type: radialBar
experimental:
  color_threshold: true
header:
  show: true
  title: ApexCharts-Card
  show_states: true
  colorize_states: true
apex_config:
  plotOptions:
    radialBar:
      offsetY: 0
      startAngle: 0
      endAngle: 270
      hollow:
        margin: 5
        size: 30%
        background: transparent
        image: false
      dataLabels:
        name:
          show: false
        value:
          show: false
series:
  - entity: sensor.energy_month
    type: column
    name: 'test '
    show:
      in_header: true
      extremas: true
    float_precision: 0
    color_threshold:
      - value: 30
        color: blue
        opacity: 1
      - value: 50
        color: cyan
      - value: 80
        color: green
      - value: 170
        color: orange
  - entity: sensor.gastoelectrico_estimado
    type: column
  - entity: sensor.gastoelectrico_actual
    type: column

i’ve tried this setting Custom Angle Circle Chart in React – ApexCharts.js but no luck at all

Hello everyone,
I am trying to fine tune my apexchart and I would like to achieve two more things:

  1. remove the empty area at the top of the chart (where the title usually is) so I can attach it directly to the button above
  2. add data labels for each state change. Kind of like extremas, but for each plateau. It’s a climate entity so changes are rare and only certain states reached. Setting datalabels: enabled: truedoes not seem to do anything.

image

Current Code
type: custom:layout-card
layout_type: custom:grid-layout
layout:
  grid-template-columns: 70% 30%
  grid-template-rows: auto
  grid-template-areas: |
    "position1 position2"
cards:
  - type: vertical-stack
    view-layout:
      grid-area: position1
    cards:
      - type: custom:slider-entity-row
        entity: climate.eq_3_living_room
        name: Living Room
        min: 4.5
        max: 23
        step: 0.5
        hide_state: false
        icon: mdi:fire
      - type: custom:apexcharts-card
        layout: minimal
        graph_span: 24h
        experimental:
          color_threshold: true
        update_interval: 10 s
        now:
          show: false
          color: red
          label: Now
        yaxis:
          - show: false
            max: 20
            min: 0
        header:
          title: Living Room Temperature
          show: false
          show_states: true
          colorize_states: true
        apex_config:
          datalabels:
            enabled: true
          grid:
            show: false
          chart:
            height: 200px
        series:
          - entity: sensor.eq_3_temperature_lr
            stroke_width: 2
            group_by:
              func: last
            fill_raw: zero
            color_threshold:
              - value: 4.5
                color: blue
              - value: 16
                color: yellow
              - value: 18
                color: orange
              - value: 20
                color: red
            type: line
            opacity: 1
  - type: vertical-stack
    view-layout:
      grid-area: position2
    cards:
      - type: custom:button-card
        entity: climate.eq_3_living_room
        name: 'Off'
        show_name: true
        show_icon: false
        show_state: false
        state:
          - operator: template
            value: '[[[ return entity.attributes.temperature == 4.5; ]]]'
            color: rgb(255, 0, 0)
        tap_action:
          action: call-service
          service: climate.set_temperature
          service_data:
            temperature: 4.5
            entity_id: climate.eq_3_living_room
      - type: custom:button-card
        entity: climate.eq_3_living_room
        name: 18 °C
        show_name: true
        show_icon: false
        show_state: false
        state:
          - operator: template
            value: '[[[ return entity.attributes.temperature == 18; ]]]'
            color: rgb(255, 0, 0)
        tap_action:
          action: call-service
          service: climate.set_temperature
          service_data:
            temperature: 18
            entity_id: climate.eq_3_living_room
      - type: custom:button-card
        entity: climate.eq_3_living_room
        name: 20 °C
        show_name: true
        show_icon: false
        show_state: false
        state:
          - operator: template
            value: '[[[ return entity.attributes.temperature == 20; ]]]'
            color: rgb(255, 0, 0)
        tap_action:
          action: call-service
          service: climate.set_temperature
          service_data:
            temperature: 20
            entity_id: climate.eq_3_living_room

Bonus question for another graph:
Is it possible to remove the legend at the bottom for an entity?
To be able to use color_threshold I simply created to entitiesentries, one as line and one as area. But of course now I have each entity listed twice in the legend and only need the one.

Example
type: custom:config-template-card
entities:
  - input_select.days_back_to_show
variables:
  span: states['input_select.days_back_to_show'].state+'d'
  days: |
    -states['input_select.days_back_to_show'].state+'d'+'1d'
card:
  type: vertical-stack
  cards:
    - type: custom:auto-entities
      filter:
        include:
          - entity_id: sensor.eq_3_temperature*
            options:
              entity: this.entity_id
              stroke_width: 0
              group_by:
                func: last
              fill_raw: zero
              type: area
              opacity: 0.05
              curve: stepline
              color_threshold:
                - value: 4.5
                  color: blue
                - value: 20
                  color: red
          - entity_id: sensor.eq_3_temperature*
            options:
              entity: this.entity_id
              stroke_width: 2
              group_by:
                func: last
              fill_raw: zero
              opacity: 1
              curve: stepline
      card:
        type: custom:apexcharts-card
        graph_span: ${span}
        span:
          start: day
          offset: ${days}
        experimental:
          color_threshold: true
        update_interval: 10 s
        now:
          show: true
          color: lightblue
          label: Now
        yaxis:
          - min: 0
        apex_config:
          grid:
            show: false

1 Like

I have a question about this cool chart:

Do you know how to change format of the y-axis from numeric scale to hours/minutes?

masterbedroom_window_statistics

You see on the second day in the blue bar for example 15.67.

This is the code:

type: custom:apexcharts-card
apex_config:
  chart:
    height: 140%
  dataLabels:
    background:
      enabled: false
    style:
      colors:
        - var(--primary-text-color)
graph_span: 1w
span:
  end: day
header:
  show: true
  title: Masterbedroom raam status
experimental:
  color_threshold: true
yaxis:
  - id: left
    min: ~0
    apex_config:
      forceNiceScale: true
series:
  - entity: sensor.masterbedroom_raam_open_vandaag_stats
    type: column
    name: Open
    yaxis_id: left
    float_precision: 2
    show:
      datalabels: true
    group_by:
      func: last
      duration: 1d
  - entity: sensor.masterbedroom_raam_gesloten_vandaag_stats
    type: column
    name: Gesloten
    yaxis_id: left
    float_precision: 2
    show:
      datalabels: true
    group_by:
      func: last
      duration: 1d
  - entity: sensor.masterbedroom_raam_ventilatie_vandaag_stats
    type: column
    name: Ventilatie
    yaxis_id: left
    float_precision: 2
    show:
      datalabels: true
    group_by:
      func: last
      duration: 1d
card_mod:
  class: top-level-chart

Is it possible to use a template for the state headers? Or show a series only in the header (not affecting the graphs) I currently have this:

image

But I also have a sensor which gives me the EUR amount for that value, which I would like to show as well.

If I add it to the series, my Y axis is way to big (EUR amount a lot bigger than HNT), if I fix the max of the yaxis I loose my dynamic scaling.

Maybe I missunderstood you but you can use the following if you just want the header value and not the graph:

show:
  in_chart: false
1 Like

That’s it, thanks! :slight_smile:

image

Any way to color the header values too? Nevermind, color:

1 Like

Hi all,
first of all @RomRider: extremely useful und advanced card, excellent job. Many thanks, it just pushes Home-Assistant to the next level. (and sorry for the typo… :slightly_smiling_face:)

I’am playing around with it now for a few day, but cannot get one thing done.
Here ist what I have, a nice comparison of the past, present and future temperature:
Bildschirmfoto 2021-11-23 um 19.31.20

I succeeded in highlighting a fixed area on the y-axis with an annotation (purple area):

apex_config:
  annotations:
    yaxis:
      - y: -20 
        y2: 0
        opacity: 0.15
        fillColor: '#775DD0'

but I fail in highlighting a dynamic area on the x-axis like “from sun.sunrise to sun.sunset”.
Is it possible to access the value of a sensor like sun.sun and paste it to these attributes?

apex_config:
  annotations:
    xaxis:
      - x: '2021-11-23 13:00:00' #here should go a sensor value
        x2: '2021-11-23 15:00:00' #here should go a sensor value
        fillColor: '#FEB019'

Any help is greatly appreciated. Thanks in advance.
Max

complete YAML-Config
type: custom:apexcharts-card
graph_span: 1d
span:
  start: day
all_series_config:
  fill_raw: last
  extend_to_end: false
  stroke_width: 2
  show:
    extremas: true
    legend_value: false
    offset_in_name: false
series:
  - entity: sensor.outside_temperature
    name: gestern
    offset: -1d
    opacity: 0.6
    color: var(--primary-color)
  - entity: sensor.outside_temperature
    name: heute
    color: var(--paper-toggle-button-checked-button-color)
    stroke_width: 3
    show:
      legend_value: true
  - entity: sensor.temperature_ak_stuttgart_2
    name: später
    data_generator: |
      return entity.attributes.data.map((entry) => {
        return [new Date(entry.datetime), entry.value];
      });
    color: var(--paper-toggle-button-checked-button-color)
    opacity: 0.8
  - entity: sensor.temperature_ak_stuttgart_2
    name: morgen
    offset: +1d
    data_generator: |
      return entity.attributes.data.map((entry) => {
        return [new Date(entry.datetime), entry.value];
      });
    color: green #var(--paper-item-icon-active-color)
    opacity: 0.6
apex_config:
  stroke: { show: true, lineCap: "square", dashArray: [0, 0, 5, 5] }
  dataLabels: { enabled: true }
  #legend: { show: false }
  annotations:
    yaxis:
      - y: -20 
        y2: 0
        opacity: 0.15
        fillColor: '#775DD0'
yaxis:
  - decimals: 0
    apex_config:
      forceNiceScale: true
now:
  show: true
  color: var(--paper-toggle-button-checked-button-color)
show:
  last_updated: true
header:
  show: true
  title: Temperatur
  floating: true

Should be RomRider. :slightly_smiling_face:

oh thanks for the hint…bad typo…

I was wondering, is it possible to reduce the large space between top of the chart and the start of the header? Especially for small charts it wastes a lot of space. So when I want to show 20 charts on one dashboard, it would become too crowded.

image

As you can see, the gap between the maximum y-value (100) and the start of the header (eQ-3 Valve Kitchen) is around 20-30 % of the total chart card.

Is it a bug that apexcharts is not showing lines when all values are 0?

If I set the span to 1 hour and the sensor had a value of 0 for that entire hour, I see no line at all. If I set it to 2 hours and the sensor had values !=0 then I see a line including 0 values. So 0 can be displayed but the line is omitted if all values are 0.
This IMHO is a bug.

Can anybody confirm?

i made this donut for my energy consumption. But I want round the total value without any decimal with the unit. How can I do that?
image

when I click in one portion of the donut, value also shown in the middle has many decimal points!
image

Not sure about the apexchart card but if it is implemented, I think you can round the values. Syntax might be similar in this card.

yaxis: {
      labels: {
        formatter: (value) => {
          return value.toFixed()
        },
      }
    },

If it works in HA, you can set toFixed(x) with x=amount of decimals to show.
But not sure if this is supported. If not, it would probably be Jinja, so something like
{{ value | round | int }}

I really like ApexCharts, thanks for this card!

I have a question relating to the X axis formatting for times. Presumably it is related to the apexcharts library, but maybe nevertheless someone here knows a solution.

It seems for a time axis, the axis ticks are not always aligned with midnight. It also seems if a label gets wide, the tick spacing is not regular. Here is an example:

image

Because the label “27 Nov” is too wide, there is a three-hour interval afterwards, and for the next day midnight is skipped and the ticks are at 23:00 and then 01:00.

I looked through the apexcharts options and found the hideOverlappingLabels options, but if I set these to false I get far too many labels. And for datetime axes, the tickAmounts option seem to be disabled.

I thus wonder if there is any other “trick” that leads to a regular spacing of the ticks? If not, I can for sure live with the way it is now.

1 Like

Hi,

I understood a few releases ago, the donut chart behavior changed to show the value instead of the percentage. However, I really liked the percentage :smiley:, but I can’t get it back. When this behavior changed, the release notes said the old behavior could be enabled with datalabels: percent, however this doesn’t work for me. Does anyone know how to show the percentages in the different donut parts?

header:
  show: true
  title: Consumption of load
  show_states: true
  colorize_states: true
chart_type: donut
series:
  - entity: sensor.pv_total_solar_use
    name: Solar use
  - entity: sensor.pv_total_buy
    name: Grid buy
apex_config:
  datalabels: percent
  legend:
    show: false

image

After using the following code
image
i got this output
image

as for individuals, i get 225 as expected.
image

how can I do some operation on value?

But is the problem now the value or the state? Sorry, I may be completely off base here, but would you not need to format the state? Not sure if the state value is automatically formatted identical to in-graph values.

I think I am formating the value of the state :-/