ApexCharts Card

repository·master·Indexed 23 days ago

https://github.com/romrider/apexcharts-card

A highly customizable graph card for Home Assistant's Lovelace UI, built on top of the ApexCharts.js library. It enables the creation of advanced data visualizations using Home Assistant entities, supporting various chart types including line, area, column, scatter, pie, donut, and radialBar. Version 2.2.3 provides features such as long-term statistics integration, data grouping functions, custom header actions with confirmation dialogs, and flexible time span configurations.

Tokens
11.8K
Snippets
24
Records
67
Agent score
82%

What's inside apexcharts-card

  1. Hide series by default using hidden_by_default

    master

    The hidden_by_default experimental feature allows you to load a series in a hidden state, simulating a user clicking the legend to disable it.

    Requirements:

    • Must be enabled via experimental: hidden_by_default: true.
    • All series in the card must have a unique name.

    Warning: This may break auto-scaling and auto-column width features.

    type: custom:apexcharts-card
    experimental:
      hidden_by_default: true
    series:
      - entity: sensor.temperature
        show:
          hidden_by_default: true
      - entity: sensor.temperature_office
  2. Use configuration templates to reduce repetition

    master

    You can define reusable configuration templates in your main Lovelace configuration to avoid repeating settings across multiple cards. Templates are applied by name and can be inherited, overloaded, or chained.

    Key behaviors:

    • Overloading: You can override any parameter from a template with a new value in the local card configuration.
    • Array Merging: Arrays are merged by matching their index.
    • Inheritance: A template can inherit from another template. You can also inherit multiple templates at once by providing an array of template names. They are merged in the order defined, and this process is recursive.
    • Scope: Templates must be defined in every dashboard where they are used; they are not shared across different dashboards.

    Implementation based on Dashboard type:

    • managed dashboards: Add the template configuration to the Raw configuration editor (found via the three-dots menu in the dashboard).
    • yaml dashboards: Add the template configuration directly to your dashboard file (e.g., ui-lovelace.yaml).
    # Define templates in your dashboard configuration
    apexcharts_card_templates:
      default:
        color_list: ['red', 'green', 'blue']
    
      bandwidth_chart:
        graph_span: 24h
        config_templates: default
        header:
          show: true
          show_states: true
          colorize_states: true
        all_series_config:
          stroke_width: 2
          opacity: 0.3
          type: area
    
    # Use the template in a card
    - type: custom:apexcharts-card
      config_templates: bandwidth_chart
      header:
        title: WAN Bandwidth
      series:
        - entity: sensor.wan_download
        - entity: sensor.wan_upload
          invert: true
  3. Use the brush experimental feature for time selection

    master

    The brush feature adds a small chart at the bottom of the card that allows users to select a specific time frame to display on the main chart.

    Configuration:

    • Enable via experimental: brush: true.
    • graph_span: Defines the time span represented by the brush.
    • brush.selection_span: (Optional) Defines the default selected span in the brush. Defaults to 1/4 of the graph_span.
    • brush.apex_config: (Optional) Allows custom ApexCharts settings for the bottom brush chart.

    Series Control:

    • Use show.in_brush: true to make a series appear in the bottom brush chart.
    • Use show.in_chart: false if you want a series to only appear in the brush and not the main chart.

    Warnings:

    • Can be compute-heavy with large amounts of history.
    • May have glitches when using columns in either the top or bottom chart.
    type: custom:apexcharts-card
    experimental:
      brush: true
    graph_span: 2h
    brush:
      selection_span: 10m
      apex_config:
        # Custom ApexCharts settings
    series:
      - entity: sensor.random0_100
        type: area
        show:
          in_brush: true
          in_chart: false
  4. Use the color_threshold experimental feature

    master

    The color_threshold feature allows you to change the color of a series based on its value.

    Supported Chart Types:

    • chart_type: radialBar, line, pie, donut
    • series.type: column, area, line

    Important Notes:

    • For type: column, the full bar uses the defined color; gradients are not supported.
    • For type: area, only the filled area supports gradients. It works best with stroke_width: 1 or stroke_width: 0.
    • Enabling this may break apex_config.fill options or cause tooltip color mismatches.
    • If invert: true is used, threshold values remain the same.

    Colors can be names, rgb(r, g, b), #hex, or var(--color-variable). For line and area types, you can also specify opacity (0 to 1).

    type: custom:apexcharts-card
    experimental:
      color_threshold: true
    series:
      - entity: sensor.temperature
        color_threshold:
          - value: -10
            color: blue
            opacity: 1
          - value: 0
            color: cyan
          - value: 15
            color: green
          - value: 25
            color: orange
  5. Add resource reference to Lovelace

    master

    After downloading the card, you must register it as a resource in Home Assistant.

    Via YAML configuration

    If you manage your Lovelace configuration via YAML, add the following to your configuration.yaml:

    resources:
      - url: /local/apexcharts-card.js?v=2.2.3
        type: module

    Via Graphical Editor

    1. Ensure Advanced Mode is enabled in your user profile.
    2. Navigate to Dashboard $\rightarrow$ Edit Dashboard $\rightarrow$ Manage resources.
    3. Click the + Add Resource icon.
    4. Enter URL: /local/apexcharts-card.js.
    5. Select type: JavaScript Module.
    6. Restart Home Assistant.
  6. Install ApexCharts Card via CLI

    master

    You can use the command line to download the card directly into your config/www directory:

    $ wget https://github.com/RomRider/apexcharts-card/releases/download/v2.2.3/apexcharts-card.js

    Note: Ensure the version in the URL matches the version you intend to use.

  7. Configure series chart display and labels

    master

    Control how data points and series appear on the actual chart within the series block:

    • in_chart (boolean): Hides the series from the chart visualization.
    • datalabels (boolean or string): Shows values on points. Use true for values, total for stacked totals (requires stacked: true), or percent for pie/donut charts.
    • extremas (boolean or string): Shows min/max values. Use true for both, or min, max, min+time, or max+time to include timestamps. Note: time display doesn't work with stacked: true.
    • offset_in_name (boolean): Appends offset information to the series name.
  8. Show a 'now' marker on the graph

    master

    The now option displays a vertical marker representing the current time. This is particularly useful when displaying data that spans into the future (via data_generator).

    Options:

    • show (boolean): Enables the marker.
    • color (string): Color of the marker (defaults to var(--primary-color)).
    • label (string): Text to display on the marker label.
  9. Configure data grouping and functions

    master

    The group_by option allows you to bucket data points over specific durations using mathematical functions.

    Group By Options:

    • func (string): The aggregation function. Valid values: raw, avg, min, max, last, first, sum, median, delta, diff.
    • duration (string): The bucket size (e.g., 2h, 1d, 10s, 25min, 1h30). Only used if func is not raw.
    • fill (string): How to handle missing values. Valid values: last, zero, 'null'.
    • start_with_last (boolean): If true, each bucket starts with the last value of the previous bucket (useful for diff).
  10. Configure time span and offsets

    master

    Control the time range displayed on the graph using span options:

    • start (string): Start the graph at the beginning of a period (minute, day, hour, week, month, year, isoWeek).
    • end (string): End the graph at the end of a period (minute, day, hour, week, month, year, isoWeek).
    • offset (string): Shift the graph in time. Use - for past (e.g., -1day, -12h). Valid units include h, min, day. Avoid using month or year for offsets as they can be inconsistent; use days instead.