ApexCharts card - A highly customizable graph card

In an earlier version of this card, I was able to set the position of the tooltip, but that is not working anymore. Anyone know how to set it to a fixed position?

type: 'custom:apexcharts-card'
series:
  - entity: sensor.nordpool_kwh_krsand_nok_5_095_025
    name: Pris
    type: area
    curve: stepline
    extend_to_end: false
    float_precision: 4
  - entity: sensor.nordpool_kwh_krsand_nok_5_095_025
    name: Pris
    type: area
    curve: stepline
    extend_to_end: false
    float_precision: 4
    data_generator: |
      return entity.attributes.raw_today.map((p) => {
        return [new Date(p.start), p.value];
      });
  - entity: sensor.nordpool_kwh_krsand_nok_5_095_025
    name: Pris
    type: area
    curve: stepline
    extend_to_end: false
    float_precision: 4
    data_generator: |
      return entity.attributes.raw_tomorrow.map((p) => {
        return [new Date(p.start), p.value];
      });
y_axis_precision: 4
now:
  show: true
  label: Nå
graph_span: 3d
span:
  start: day
  offset: '-1d'
apex_config:
  chart:
    zoom:
      enabled: true
    toolbar:
      show: true
      tools:
        zoom: true
        zoomin: false
        zoomout: false
        pan: false
        reset: true
    type: area
    height: 300
    locales:
      - name: nb
        options:
          months:
            - Januar
            - Februar
            - Mars
            - April
            - Mai
            - Juni
            - Juli
            - August
            - September
            - Oktober
            - November
            - Desember
          shortMonths:
            - Jan
            - Feb
            - Mar
            - Apr
            - Mai
            - Jun
            - Jul
            - Aug
            - Sep
            - Okt
            - Nov
            - Des
          days:
            - Søndag
            - Mandag
            - Tirsdag
            - Onsdag
            - Torsdag
            - Fredag
            - Lørdag
          shortDays:
            - Sø
            - Ma
            - Ti
            - 'On'
            - To
            - Fr
            - Lø
          toolbar:
            exportToSVG: Last ned SVG
            exportToPNG: Last ned PNG
            exportToCSV: Last ned CSV
            menu: Menu
            selection: Velg
            selectionZoom: 'Zoom: Velg'
            zoomIn: Zoome inn
            zoomOut: Zoome ut
            pan: Skyving
            reset: Start på nytt
    defaultLocale: nb
  stroke:
    show: true
    width: 2
  legend:
    show: false
  dataLabels:
    enabled: false
  yaxis:
    min: 0
  xaxis:
    type: datetime
    labels:
      datetimeFormatter:
        month: ddd
        day: ddd
  tooltip:
    fixed:
      position: bottomLeft
  fill:
    type: gradient
    gradient:
      shadeIntensity: 1
      inverseColors: false
      opacityFrom: 0.45
      opacityTo: 0.05
      stops:
        - 20
        - 100
        - 100
        - 100

Hello,

I’ve started with the whole HomeAssistant-thing maybe 2 or 3 weeks ago. I’ve found this card and love the possibilities of customization. Thank you for your work !

Now I have a (maybe stupid) question:
Is there a way to put 3 different entities (with different units) into one single chart/graph ?
I thought I could put my Netatmo Weatherstation with humidity, C02 and actual temperature into one chart. Because of the different scale these three units have, the graph looks nearly flat for temperature and humidity. C02 defines the y-axis.

Thanks, Tobi

You have to add enabled: true to the fixed section of the tooltip config.

Note: also locales support (including nb) has been added to the latest beta, no need to define those locales anymore.

Yes, there are several examples of multi-y axis on the forum here, but it’s not very intuitive.
What you’ll want to do is:

apex_config:
  yaxis:
    # axis 1 (maps to the first entity in the series)
    - min: xx
      max: yy
      show: true/false
      decimalsInFloat: 1
      title: #optional
        text: title of the axis
      opposite: true/false
    # axis 2 (maps to the second entity in the series)
    - min: xx
      max: yy
      show: true/false
      decimalsInFloat: 1
      title: #optional
        text: title of the axis
      opposite: true/false
    # axis 3 (maps to the third entity in the series)
    - min: xx
      max: yy
      show: true/false
      decimalsInFloat: 1
      title: #optional
        text: title of the axis
      opposite: true/false
1 Like

Great, that worked for me. Thanks a lot !

Is it possible to fix this only to the top and let the tooltip only jump horizontal?
When using the chart in a browser_mod popup, the bottom of the tooltip sometimes isn’t visible.
Auswahl_440

I’m afraid that is not a feature of ApexCharts. :frowning:

You could try with https://apexcharts.com/docs/options/tooltip/ --> followCursor: true to see if it works better for you

2 Likes

I would like to create a graph from the octopusagile.rates entity created by https://github.com/markgdev/home-assistant_OctopusAgile#octopusagilerates as shown in the screen shot. The entity has a a series of attributes consisting of time stamp and values.

The data_generator option https://github.com/RomRider/apexcharts-card#data_generator-option requires a [timestamp, value][] return type, but I can’t figure out the JavaScript to convert these attributes into this return type.

That’s an awesome piece of work. I have couple of flex-horseshoe-card on my dashboard which was not updated in the last 3 months and I’d like to change them to apexcharts-card.
The problem is that my existing cards are showing the current power consumption in Watts (not %) and they have gradient colors (green-yellow-red).
Is it possible to achieve the same visual result with apexchart-card? I’ve tried several times but I’ve failed every time. Thank you.

I am trying to define some apexcharts_card_templates in ui-lovelace.yaml. However, this does not seem to be working and keeps giving me an error when I use a template. What am I doing wrong?

apexcharts_card_templates:
  2d_stepline_chart:
    apex_config:
      chart:
        height: 200px
    all_series_config:
      extend_to_end: false
      stroke_width: 2
      curve: stepline
      show:
        legend_value: false
    graph_span: 2d
- type: custom:apexcharts-card
  config_templates: 2d_stepline_chart
  y_axis_precision: 0
  series:
    - entity: sensor.wind_speed_kilometre
    - entity: sensor.gust_speed_kilometre

This is the error I keep getting.

/// apexcharts-card version 1.6.0 /// value.config_templates is not an array
type: 'custom:apexcharts-card'
config_templates: 2d_stepline_chart
y_axis_precision: 0
series:
  - entity: sensor.wind_speed_kilometre
  - entity: sensor.gust_speed_kilometre

Try something like:

let res = [];
for (const [key, value] of Object.entries(entity.attributes)) {
  res.push([new Date(key).getTime(), value]);
}
return res.sort((a, b) => { return a[0] - b[0] })

Not so far, see here

That’s a bug on my part. In the meantime to make it work you can transform it into an array:

# convert
config_templates: 2d_stepline_chart
#to
config_templates:
  - 2d_stepline_chart

Do you mind opening a bug on github so that I don’t forget please?

2 Likes

Thankyou very much - that worked first time. I have now included two entities, one to show the current price sensor history, the other to show the upcoming rates as can be seen in the screen shots.

One question about the card header. The “Next Rate” value shows 10.4 which is the value of the last known value in the future ie. 16 Feb 2021 at 22:30. Ideally I’d like it to show 29.6 which is the value 15 Feb 2021 at 17:00. Not sure if this is a bug or I need to work around it.


Card configuration
type: 'custom:apexcharts-card'
header:
  show: true
  show_states: true
  colorize_states: true
  title: Octopus Agile rates
span:
  start: day
graph_span: 48hours
all_series_config:
  stroke_width: 2
  type: area
  extend_to_end: false
  curve: stepline
experimental:
  color_threshold: true
now:
  show: true
  label: now
  color: orange
color_list:
  - orange
  - grey
y_axis_precision: 0
series:
  - entity: sensor.octopus_agile_current_rate
    name: Current rate
    group_by:
      func: max
      duration: 30min
  - entity: octopusagile.rates
    name: Next Rate
    unit: p/kWh
    data_generator: |
      let res = [];
      for (const [key, value] of Object.entries(entity.attributes)) {
        res.push([new Date(key).getTime(), value]);
      }
      return res.sort((a, b) => { return a[0] - b[0] });
apex_config:
  legend:
    show: false
  grid:
    borderColor: '#7B7B7B'
  chart:
    foreColor: '#7B7B7B'
    zoom:
      type: x
      enabled: true
      autoScaleYaxis: true
    toolbar:
      show: true
      autoSelected: zoom
      tools:
        zoom: true
        zoomin: false
        zoomout: false
        pan: false
        reset: true
1 Like

The header always shows the last data from the chart and if I understand correctly, you’d want to display the first one for the data in the future. I guess I could offer that option :slight_smile:.

Please open a feature request and I’ll look into it.

Love the idea of showing extremas that you are working on :slight_smile:

Any plans to, similar to mini graph card, have a setting for “points per hour”?

Also, is there a way to control the width of each column?

Points per hour is the equivalent of group_by with a duration and a func (if you want the same as mini-graph-card, it’s avg) .
Column width is determined by the number of data you want to display. Use group_by and it will increase the colum width.

1 Like

Thanks. I have opened issue #87.

@RomRider I am still LOVING this card!
Is there a way to combine multiple entities into one legend, but still have it display all entities separately on the graph?

i.e.: I have 5 thermometers. I’d like to have them all grouped into one legend marker for ease of hiding all at once in one click, but still see all 5 lines on the graph.

Been looking thru the git and apex docs but can’t for the life of me find a way to do it within the card.

That is not possible unfortunately. And there’s no such option in ApexCharts to make it happen. :frowning:

Attempting to use the template feature, but I just can’t make it work. Likely missing something obvious…? (No issues with my button card templates which follow the same syntax.)

I also tried pasting the example config defining just colors, but got the same error.

Example with simplified card just to see if it take effect. No matter what I do I get the same error.

apexcharts_card_templates:
  test:
    header:
      show: false

This is fixed in the upcoming version which is 2min away from being released :wink:

:tada::tada: New Release :tada::tada:

1.7.0 (2021-02-16)

Highlights

  • :arrow_down::arrow_up: Show extremas on your chart with (doesn’t work yet with multi-y axis):

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

    image

  • :earth_americas: Language support with automatic detection

  • :warning: Deprecate hours_12 in favor of automatic detection using HA’s configured language or what is set in the locale config option.

Features

  • datalabels: Option to display total when chart is stacked (#75) (e1c5b01), closes #73
  • experimental: Header color can now follow color_threshold (#88) (074bfc3), closes #78
  • locale: Inherit locale from Home-Assistant, deprecate hours_12 (#70) (af2d201), closes #68
  • series.show: Display your serie’s extremas on the chart (#85) (f64169a)
  • series.show: Option to show the raw data in the header (#76) (87b56f5), closes #69
  • transform: Provide the full state as entity to the function (#77) (9919c10), closes #71

Bug Fixes

  • config_templates: Was supposed to support a string (f36d9b1), closes #87
  • color with alpha would render area opaque (100b6d4)
  • Support for rgba colors (7ecfafd)
  • truncate floats in total datalabels (917a20a), closes #73
  • Wrong labels in tooltip in some cases (8f0aca1)

Documentation

  • Better info about month and year as offset units (c194f87), closes #65
  • config_templates: Fix wrong config example (ea1fef4)
  • Card is now available in HACS by default (1200abd)
2 Likes