- Notifications
You must be signed in to change notification settings - Fork104
📈 A Lovelace card to display advanced graphs and charts based on ApexChartsJS for Home Assistant
License
RomRider/apexcharts-card
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ApexCharts Card by@RomRider
This is higly customizable graph card forHome-Assistant's Lovelace UI.
It is based onApexCharts.js and offers most of the features of the library.
It is also inspired by the greatmini-graph-card
by@kalkih
However, some things might be broken 😁
- Installation
- Data processing steps
- Using the card
- Main Options
series
Options- series'
show
Options header_actions
ortitle_actions
options*_action
optionsconfirmation
optionsstatistics
options- Main
show
Options header
Optionsnow
Optionsgroup_by
Optionsfunc
Optionschart_type
Optionsspan
Optionstransform
Optiondata_generator
Optionyaxis
Options. Multi-Y axis- Apex Charts Options Example
- Layouts
- Configuration Templates
- Experimental features
- Known issues
- Roadmap
- Examples
This card is available inHACS (Home Assistant Community Store).HACS is a third party community store and is not included in Home Assistant out of the box.
Download and copy
apexcharts-card.js
from thelatest release into yourconfig/www
directory.Add the resource reference as decribed below.
Move into your
config/www
directory.Grab
apexcharts-card.js
:
$ wget https://github.com/RomRider/apexcharts-card/releases/download/v2.1.2/apexcharts-card.js
- Add the resource reference as decribed below.
If you configure Lovelace via YAML, add a reference toapexcharts-card.js
inside yourconfiguration.yaml
:
resources: -url:/local/apexcharts-card.js?v=2.1.2type:module
Else, if you prefer the graphical editor, use the menu to add the resource:
- Make sure, advanced mode is enabled in your user profile (click on your user name to get there)
- Navigate to Configuration -> Lovelace Dashboards -> Resources Tab. Hit orange (+) icon
- Enter URL
/local/apexcharts-card.js
and select type "JavaScript Module". - Restart Home Assistant.
This diagrams shows how your data goes through all the steps allowed by this card:
The card stricly validates all the options available (but not for theapex_config
object). If there is an error in your configuration, it will tell you where and display a red error card.
✅means required.
Name | Type | Default | Since | Description |
---|---|---|---|---|
✅type | string | v1.0.0 | custom:apexcharts-card | |
✅series | array | v1.0.0 | Seeseries | |
config_templates | array | v1.6.0 | Define a configuration once and reuse it multiple times. Seeconfig_templates | |
color_list | array | v1.6.0 | Define the array of colors applied to the series. Will be overriden by each serie's color if defined. Usefull forconfig_templates mainly. | |
all_series_config | object | v1.6.0 | If something is defined here it will apply this config to all the series. It accepts the same options as a serie minusentity . It is useful to avoid repetition but the same thing can be achieve in each serie individually. Seeseries andall_series_config for an example | |
chart_type | string | line | v1.4.0 | Seechart_type |
update_interval | string | v1.1.0 | By default the card updates on every state change. Setting this overrides the behaviour. Valid values are any time string, eg:1h ,12min ,1d ,1h25 ,10sec , ... | |
update_delay | string | 1500ms | v1.4.0 | If the chart doesn't display the last state but the one before, you'll want to increase this value, don't go over10s , it's not necessary. You'll also want to increase this value if you are usingattribute in theseries . Valid values are any time strings. This is because of how Home-Assistant works with history, seehere |
graph_span | string | 24h | v1.1.0 | The span of the graph as a time interval. Valid values are any time string, eg:1h ,12min ,1d ,1h25 ,10sec , ... |
span | object | v1.2.0 | Seespan | |
show | object | v1.0.0 | Seeshow | |
hours_12 | boolean | v1.8.0 | If undefined, it will follow Home-Assistant's user time format. Iftrue , it will force time to be displayed in 12h format. Iffalse it will force the time to be displayed in 24h format. | |
cache | boolean | true | v1.0.0 | Use in-browser data caching to reduce the load on Home Assistant's server |
stacked | boolean | false | v1.0.0 | Enable if you want the data to be stacked on the graph |
layout | string | v1.0.0 | Seelayouts | |
header | object | v1.0.0 | Seeheader | |
now | object | v1.5.0 | Seenow | |
y_axis_precision | 1 | DEPRECATED since v1.10.0yaxis is undefined. | ||
yaxis | array | v1.9.0 | Seeyaxis | |
apex_config | object | v1.0.0 | Apexcharts API 1:1 mapping. You call see all the optionshere -->Options (Reference) in the Menu. SeeApex Charts | |
experimental | object | v1.6.0 | Seeexperimental | |
locale | string | v1.7.0 | Default is to inherit from Home-Assistant's user configuration. This overrides it and forces the locale. Eg:en , orfr . Reverts toen if locale is unknown. | |
brush | object | v1.8.0 | Seebrush |
Name | Type | Default | Since | Description |
---|---|---|---|---|
✅entity | string | v1.0.0 | Theentity_id of the sensor to display | |
attribute | string | v1.4.0 | Instead of retrieving the state, it will retrieve anattribute of the entity. Make sure you increaseupdate_delay if the chart doesn't reflect the last value of the attribute | |
name | string | v1.0.0 | Override the name of the entity | |
stack_group | string | v2.1.0 | Whenstacked istrue , groups the different series with the namestack_group together. Only works fortype: column . All series' names need to be be unique because of a bug in apexcharts.js | |
color | string | v1.1.0 | Color of the serie. Supported formats:yellow ,#aabbcc ,rgb(128, 128, 128) orvar(--css-color-variable) | |
opacity | number | 0.7 forarea else 1 | v1.6.0 | The opacity of the line or filled area, between0 and1 |
stroke_width | number | 5 | v1.6.0 | Change the width of the line. Only works forarea andline |
stroke_dash | number | 0 | v2.1.0 | Creates a dashed line. The higher the number, the bigger the dash. |
type | string | line | v1.0.0 | line ,area orcolumn are supported for now |
curve | string | smooth | v1.0.0 | smooth (nice curve),straight (direct line between points) orstepline (flat line until next point then straight up or down),monotoneCubic (create a monotone cubic spline) |
extend_to_end | true | DEPRECATED since v2.0.0line andarea types. | ||
extend_to | boolean or string | end | v2.0.0 | If value isend , it will extend the line/area to the end of the chart. Withnow , it will extend it to the current time (usefull for chart showing current and future data). Iffalse it will not do anything. Only available forline andarea types. |
unit | string | v1.0.0 | Override the unit of the sensor | |
float_precision | number | 1 | v1.2.0 | The precision used to display data in the legend and the tooltip. It doesn't impact how the data is displayed on the graph |
fill_raw | string | 'null' | v1.5.0 | If there is any missing value in the history,last will replace them with the last non-empty state,zero will fill missing values with0 ,'null' will fill missing values withnull . This is applied beforegroup_by options |
group_by | object | v1.0.0 | Seegroup_by | |
invert | boolean | false | v1.2.0 | Negates the data (1 ->-1 ). Usefull to display opposites values like network in (standard)/out (inverted) |
transform | string | v1.5.0 | Transform your raw data in any way you like. Seetransform | |
data_generator | string | v1.2.0 | Seedata_generator | |
statistics | object | v2.0.0 | Use HA statistical data (long-term). Seestatistics | |
offset | string | v1.3.0 | This is different from the mainoffset parameter. This is at the series level. It is only usefull if you want to display data from for eg. yesterday on top of the data from today for the same sensor and compare the data. The time displayed in the tooltip will be wrong as will the x axis information. Valid values are any negative time string, eg:-1h ,-12min ,-1d ,-1h25 ,-10sec , ...month (365.25 days / 12) andyear (365.25 days) as unit will generate inconsistent result, you should use days instead. | |
time_delta | string | v2.0.0 | This applies a time delta to all the datapoints of your chartafter fetching them. You can cumulate it withoffset . Valid values are any time strings starting with+ or- , eg:-30min ,+2h ,-2d , ... | |
min | number | 0 | v1.4.0 | Only used whenchart_type = radialBar , seechart_type. Used to convert the value into a percentage. Minimum value of the sensor |
max | number | 100 | v1.4.0 | Only used whenchart_type = radialBar , seechart_type. Used to convert the value into a percentage. Maximum value of the sensor |
color_threshold | object | v1.6.0 | Seeexperimental | |
yaxis_id | string | v1.9.0 | The identification name of the y-axis which this serie should be associated to. Seeyaxis | |
show | object | v1.3.0 | Seeserie's show options | |
header_actions | object | v1.10.0 | Seeheader_actions |
Name | Type | Default | Since | Description |
---|---|---|---|---|
legend_value | boolean | true | v1.3.0 | Show/Hide the state in the legend. Will still display the name |
as_duration | string | v1.3.0 | Will pretty print the states as durations. Doesn't affect the graph, only the tooltip/legend/header display. You provide the source unit of your sensor. Valid values aremillisecond ,second ,minute ,hour ,day ,week ,month ,year .Eg: if the state is 345 andas_duration is set tominute then it would display5h 45m | |
in_header | boolean or string | true | v1.4.0 | Ifshow_states is enabled, this would show/hide this specific serie in the header. If set toraw (introduced in v1.7.0), it would display the latest raw state of the entity in the header bypassing any grouping/transformation done by the card. If the graph spans into the future (usingdata_generator ):before_now would display the value just before the current time andafter_now would display the value just after the current time (Introduced in v1.8.0) |
name_in_header | boolean | true | v1.8.0 | Only valid ifin_header: true . Iffalse , it will hide the name of the serie under the its state in the header |
header_color_threshold | boolean | false | v1.7.0 | Iftrue andcolor_threshold experimental mode is enabled, it will colorize the header's state based on the threshold (ignoring opacity). |
in_chart | boolean | true | v1.4.0 | Iffalse , hides the serie from the chart |
datalabels | boolean or string | false | v1.5.0 | Iftrue will show the value of each point for this serie directly in the chart. Don't use it if you have a lot of points displayed, it will be a mess. If you set it tototal (introduced in v1.7.0), it will display the stacked total value (only works whenstacked: true ). If you set it topercent , it will display the percentage of the serie instead of the value in the case of apie ordonut chart. |
hidden_by_default | boolean | false | v1.6.0 | Seeexperimental |
extremas | boolean or string | false | v1.7.0 | Iftrue , will show the min and the max of the serie in the chart. If the value istime , it will display also the time of the min/max value on top of the value. From v2.0.0,min ormax will display the min or the max only andmin+time ormax+time will display the time of the min or the max. Displaying the time doesn't work withstacked: true . |
in_brush | boolean | false | v1.8.0 | Seebrush |
offset_in_name | boolean | true | v1.8.0 | Iftrue , appends the offset information to the name of the serie. Iffalse , it doesn't |
Name | Type | Default | Since | Description |
---|---|---|---|---|
tap_action | object | v1.10.0 | Action to perform on tap. Seeaction options | |
hold_action | object | v1.10.0 | Action to perform on hold. Seeaction options | |
double_tap_action | object | v1.10.0 | Action to perform on double tap. Seeaction options |
Name | Type | Default | Since | Description |
---|---|---|---|---|
action | string | more-info | v1.10.0 | Action to perform. Valid values are:more-info ,toggle ,call-service ,none ,navigate ,url |
entity | string | v1.10.0 | Only valid formore-info . Overrides themore-info target entity. Default is to use the serie's entity | |
navigation_path | string | v1.10.0 | Path to navigate to (e.g./lovelace/0/ ) when action isnavigate | |
url_path | string | v1.10.0 | URL to open on click when action isurl . The URL will open in a new tab | |
service | string | v1.10.0 | Any valid Home-Assistant service | |
service_data | object | v1.10.0 | Service data to include (e.g.entity_id: media_player.bedroom ) whenaction defined ascall-service | |
confirmation | object | v1.10.0 | Display a confirmation popup. Seeconfirmation |
Example:
type:custom:apexcharts-cardseries: -entity:sensor.indoor_temperatureheader_actions:tap_action:action:call-serviceservice:climate.turn_onservice_data:entity_id:climate.heater
This will popup a dialog box before running the action.
Name | Type | Default | Since | Description |
---|---|---|---|---|
text | string | v1.10.0 | This text will be displayed in the popup | |
exemptions | array | v1.10.0 | Any user declared in this list will not see the confirmation dialog. Formatuser: USER_ID |
Example:
type:custom:apexcharts-cardseries: -entity:sensor.indoor_temperatureheader_actions:tap_action:action:call-serviceservice:script.toggle_climateservice_data:entity:climate.heaterconfirmation:text:Are you sure?exemptions: -user:befc8496799848bda1824f2a8111e30a
Name | Type | Default | Since | Description |
---|---|---|---|---|
type | string | mean | v2.0.0 | Type of long term statistic to pull. Can be one ofmin ,max ,mean ,sum state orchange |
period | string | hour | v2.0.0 | Period of statistics to pull. Can be one of5minute ,hour ,day ,week ormonth |
align | string | middle | v2.0.0 | Align the data points to thestart ,end ormiddle of the period of the statistics |
Name | Type | Default | Since | Description |
---|---|---|---|---|
loading | boolean | true | v1.0.0 | Displays a spinning icon while the data is loading/updating |
last_updated | boolean | false | v1.10.0 | Show the last time the chart was updated on the bottom right |
Name | Type | Default | Since | Description |
---|---|---|---|---|
show | boolean | false | v1.0.0 | Show or hide the header |
title | string | v1.1.0 | The title of the chart you want to display | |
title_actions | object | v2.0.0 | Actions to perform while tapping the title of the chart. Seetitle_actions | |
floating | boolean | false | v1.0.0 | Makes the header float above the graph. Positionning will be supported later |
show_states | boolean | false | v1.1.0 | Show or hide the states in the header |
colorize_states | boolean | false | v1.1.0 | Colorize the states based on the color of the serie |
standard_format | boolean | false | v1.8.0 | Display the title using the standard Home-Assistant card format |
disable_actions | boolean | false | v1.10.0 | Iftrue , disable all header actions |
The position of the marker will only update when the card updates (state change orupdate_interval
).
Name | Type | Default | Since | Description |
---|---|---|---|---|
show | boolean | false | v1.5.0 | Shows a vertical marker for the current time on the graph. Only useful if displaying data from the future |
color | string | var(--primary-color) | v1.5.0 | Color of the marker. The color of the text is computed automatically. |
label | string | v1.5.0 | Text to display on the label. No label if not defined |
Name | Type | Default | Since | Description |
---|---|---|---|---|
func | string | raw | v1.0.0 | Seefunc |
duration | string | 1h | v1.0.0 | Iffunc isnotraw only. It builds buckets of states overduration period of time. Doesn't work for months. Eg of valid values:2h ,1d ,10s ,25min ,1h30 , ... |
fill | string | last | v1.0.0 | Iffunc isnotraw only. If there is any missing value in the buckets of history data (grouped by duration),last will replace them with the last non-empty state,zero will fill missing values with0 ,'null' will fill missing values withnull |
start_with_last | boolean | false | v1.8.0 | Iftrue , each bucket of data will start with the last value from the previous bucket of data. Mostly useful only withfunc: diff |
Name | Since | Description |
---|---|---|
raw | v1.0.0 | Displays all the state history as known by Home Assistant |
avg | v1.0.0 | Will return the average of all the states in each bucket |
min | v1.0.0 | Will return the smallest state of each bucket |
max | v1.0.0 | Will return the biggest state of each bucket |
last | v1.0.0 | Will return the last state of each bucket |
first | v1.0.0 | Will return the first state of each bucket |
sum | v1.0.0 | Will return the sum of all the states in each bucket |
median | v1.0.0 | Will return the median of all the states in each bucket |
delta | v1.0.0 | Will return the delta between the biggest and smallest state in each bucket |
diff | v1.4.0 | Will return the difference between the last and the first entry in the bucket |
Name | Since | Description |
---|---|---|
line | v1.0.0 | This is the default and will show a timeline. It is compatible withseries.type =column ,line andarea |
scatter | v1.4.0 | Displays a cloud of points without a line between the values |
pie | v1.4.0 | This will display a pie chart with the last value computed of each sensor |
donut | v1.4.0 | This will display a donut chart with the last value computed of each sensor, same as pie but with a hole in the center |
radialBar | v1.4.0 | This will display a radial bar chart with the last value computed of each sensor. The value is represented in percentage only. It is required to providemin andmax for each series displayed as it requires to convert the value into percentage. The default value formin is0 and formax it is100 . This graph works well if you want to display sensors natively in percentages |
Name | Since | Description |
---|---|---|
start | v1.2.0 | Display the graph from the begining of theminute ,day ,hour ,week ,month ,year ,isoWeek .isoWeek is the start of the week according to ISO 8601 |
end | v1.2.0 | Display the graph from the end of theminute ,day ,hour ,week ,month ,year ,isoWeek .isoWeek is the end of the week according to ISO 8601 |
offset | v1.2.0 | Offset the graph by an amount of time. To offset in the past, start with- . Eg. of valid values:-1day ,-12h ,12h ,30min , ...month (365.25 days / 12) andyear (365.25 days) as unit will generate inconsistent result, you should use days instead. |
Span enables you to:
- Offset the graph by an amount of time
start
: Display the graph from the begining of theminute
,day
,hour
,week
,month
,year
. In this case,graph_span
should be in most cases<=
to 1 unit of the unit defined in start.end
: Display the graph from the end of theminute
,day
,hour
,week
,month
,year
- Combined with
group_by
in a serie, the group will begin at the tick of thestart
unit (+/-offset
if defined) - Only one of
start
orend
is supported at the same time
graph_span:If start is defined, it should be <= to 1 unit of the one defined in `start`span:start:minute, day, hour, week, month or yearend:minute, day, hour, week, month or yearoffset:To offset in the past, prefix with `-` Timerange like 1day, 12h, 10min, -12h, -1d, ...
Eg:
- Display 24h from the start of the current day (00:00 -> 23:59)
type:custom:apexcharts-cardgraph_span:24hspan:start:day
- Display 24h from the start of the previous day (00:00 -> 23:59, -1 day)
type:custom:apexcharts-cardgraph_span:24hspan:start:dayoffset:-1d
- Display 12h between 06:00 and 18:00 of the current day
type:custom:apexcharts-cardgraph_span:12hspan:start:dayoffset:+6h
- Display the last 7 days, the end of the graph is the end of the current day
type:custom:apexcharts-cardgraph_span:7dspan:end:day
With transform, you can modify raw data comming from Home-Assistant's history using a javascript function.
Some of the things you can do:
- Transform any state into a number (for eg. for binary_sensors)
- Apply a different scale to your data (eg: divide by 1024 to convert bits into Kbits)
- Do anything that javascript allows with the value
Your javascript code will receive:
x
: a state or a value of the attribute if you defined one (it can be astring
,null
or anumber
depending on the entity type you've assigned)hass
: the fullhass
object (hass.states['other.entity']
to get the state object of another entity for eg.)entity
: the full state object of the entity from the history entry currently being transformed
And should return anumber
, afloat
ornull
.
Some examples:
Convert
binary_sensor
to numbers (1
ison
,0
isoff
)type:custom:apexcharts-cardupdate_delay:3supdate_interval:1minseries: -entity:binary_sensor.heatingtransform:"return x === 'on' ? 1 : 0;"
Scale a sensor:
type:custom:apexcharts-cardupdate_delay:3supdate_interval:1minseries: -entity:sensor.bandwidthtransform:"return x / 1024;"
Before we start, to learn javascript, google is your friend or ask for help on theforum 🙂
data_generator
is an advanced feature. It enables you to build your own data out of the last state of a sensor. It completely bypasses the history retrieval and caching mecanism.
You'll need to write a javascript function which returns a[timestamp, value][]
:
timestamp
is the timestamp of the data in msvalue
is the value of the data as a number or a float, make sure you parse it if it's a string.
Inside your javascript code, you'll have access to those variables:
entity
: the entity objectstart
(Date object): the start Date object of the graph currently displayedend
(Date object): the end Date object of the graph currently displayedhass
: the completehass
objectmoment
: theMoment.JS object to help you manipulate time and dates
Let's take this example:
My sensor (
sensor.test
) has this state as its last state:FirstPeak:HighPeakTimes: -'2021-01-27 03:43:00' -'2021-01-27 10:24:00' -'2021-01-27 16:02:00' -'2021-01-27 22:38:00' -'2021-01-28 04:21:00' -'2021-01-28 11:06:00' -'2021-01-28 16:40:00' -'2021-01-28 23:18:00' -'2021-01-29 05:00:00' -'2021-01-29 11:45:00' -'2021-01-29 17:19:00' -'2021-01-29 23:58:00' -'2021-01-30 05:39:00' -'2021-01-30 12:25:00' -'2021-01-30 17:59:00'PeakHeights: -4.99 -1.41 -4.96 -1.33 -5.22 -1.19 -5.15 -1.14 -5.42 -1.01 -5.3 -0.99 -5.57 -0.87 -5.39unit_of_measurement:mfriendly_name:Tides
This is data in the future, but I want to display them so I need to build them myself using
data_generator
:type:custom:apexcharts-cardgraph_span:4d# I have 4 days worth of data in the future in the attributesspan:start:hour# I want to display from the start of the current hours 4 days into the futureseries: -entity:sensor.testdata_generator:|# This is what builds the data return entity.attributes.PeakTimes.map((peak, index) => { return [new Date(peak).getTime(), entity.attributes.PeakHeights[index]]; });
The result of this function call would be something like:
[[1611718980000, 4.99], [1611743040000, 1.41], [1611763320000, 4.96], ...]
And this is all you need 🎉
yaxis
in the mainapex_config
option as it will be overriden.
You can have as many y-axis as there are series defined in your configuration or less.
Name | Type | Default | Since | Description |
---|---|---|---|---|
id | string | v1.9.0 | Required if you define multiple yaxis. The identification name of the yaxis used to map it to a serie. Needs to be unique. | |
show | boolean | true | v1.9.0 | Whether to show or not the axis on the chart |
opposite | boolean | false | v1.9.0 | Iftrue , the axis will be shown on the right side of the chart |
min | auto , number or string | auto | v1.9.0 | If undefined orauto , themin of the yaxis will be automatically calculated based on the min value of all the series associated to this axis. Seebelow for other formats. |
max | auto , number or string | auto | v1.9.0 | If undefined orauto , themin of the yaxis will be automatically calculated based on the max value of all the series associated to this axis. Seebelow for other formats. |
decimals | number | 1 | v1.10.0 | Number of decimals to show on this y-axis |
apex_config | object | v1.9.0 | Any configuration fromhttps://apexcharts.com/docs/options/yaxis/, exceptmin ,max ,show andopposite | |
align_to | number | v1.10.0 | Aligns the yaxis extremas to the closest multiple ofalign_to . Only valid ifmin ormax are not fixed values. |
min
andmax
support multiple types of format:
- not set or
auto
(this is the default): if it is set toauto
, the min or max will be automatically calculated - any number: if a number is set, the min or max will be fixed on the y-axis
~90
: if the format is~
followed by a number, the min or max will be defined as a soft boundsmin: ~90
and the min of the data in the series is120
: the y-axis min value will be90
min: ~90
and the min of the data in the series is60
: the y-axis min value will be60
'|+20|'
or'|-20|'
: This will add/remove the value between| |
from the min/maxmin: '|-20|'
: The min of the data in the series is32
, the y-axis min will be12
(=32 - 20
)max: '|+10|'
: The max of the data in the series is32
, the y-axis max will be42
(=32 + 10
)
Simple example with one y-axis:
type:custom:apexcharts-cardheader:show:truetitle:Max Soft Bounds + Min Fixed Boundgraph_span:20minseries: -entity:sensor.random0_100yaxis:# only 1 yaxis, no need for id or yaxis_id -min:0# if the sensor doesn't go above 50, the max of the axis will be 50# else the max will be the maximum value of the sensormax:~50decimals:0apex_config:tickAmount:4
In this example, we have 2 sensors:
sensor.random0_100
: goes from0
to100
sensor.random_0_1000
: goes from0
to1000
The
min
andmax
of both y-axis are auto calculated based on the spread of the data associated with each axis.type:custom:apexcharts-cardgraph_span:20minyaxis: -id:first# identification name of the first y-axisdecimals:0apex_config:tickAmount:4 -id:second# identification name of the second y-axisopposite:true# make it show on the right sidedecimals:0apex_config:tickAmount:4all_series_config:stroke_width:2series: -entity:sensor.random0_100yaxis_id:first# this serie will be associated to the 'id: first' axis. -entity:sensor.random_0_1000yaxis_id:second# this serie will be associated to the 'id: second' axis. -entity:sensor.random0_100yaxis_id:first# this serie will be associated to the 'id: first' axis.transform:'return Number(x) + 30;'# We make it go fom 30 to 130 -entity:sensor.random0_100yaxis_id:first# this serie will be associated to the 'id: first' axis.transform:'return Number(x) - 30;'# We make it go from -30 to 70
This is how you could change some options from ApexCharts as described on theOptions (Reference)
menu entry.
Hundreds of options are available and it is not possible to describe them all here so check over there and ask on theforum if you need help with using them.
⚠️ Some options might not work in the context of this card.⚠️ Everything which is available through the default config of this card shouldn't be defined inapex_config
. If you do, it might break.
type:custom:apexcharts-cardseries: -...apex_config:dataLabels:enabled:truedropShadow:enabled:true
Some options in ApexCharts can take a javascript function as an argument. To make this possible, you'll have to prefix your function withEVAL:
.
EVAL:
feature, there is no safeguard so use at your own risk.
Here is an example:
apex_config:yaxis:labels:formatter:| EVAL:function(value) { return "42"; }
For now, onlyminimal
is supported: It will remove the grid, the axis and display the legend at the top. But you can use theapex_config
to do whatever you want.
For code junkies, you'll find the default options I use insrc/apex-layouts.ts
Define your config template in the main lovelace configuration and then use it in your cards. This will avoid a lot of repetitions! It's basically YAML anchors, but without using YAML anchors and is very useful if you split your config in multiple files 😄
You can overload any parameter with a new one
Arrays will be merged by matching the index
You can also inherit another template from within a template.
You can inherit multiple templates at once by making it an array. In this case, the templates will be merged together with the current configuration in the order they are defined. This happens recursively.
type:custom:apexcharts-cardconfig_templates: -template1 -template2# ortype:custom:apexcharts-cardconfig_templates:template1
The card templates will be applied in the order they are defined:template2
will be merged withtemplate1
and then the local config will be merged with the result. You can still chain templates together (ie. define template in a apexcharts-card template. It will follow the path recursively).
Make sure which type of lovelace dashboard you are using before changing the main lovelace configuration:
managed
changes are managed by lovelace UI - add the template configuration to configuration in raw editor- go to your dashboard
- click three dots and
Edit dashboard
button - click three dots again and click
Raw configuration editor
button
yaml
- add template configuration to your dashboard file (ui-lovelace.yaml
for eg.)
Note: Templates have to be defined in all dashboards, they are not shared.
To give you an idea where to put those (in your dashboard file/RAW editor):
apexcharts_card_templates:default:color_list:['red', 'green', 'blue']bandwidth_chart:graph_span:24hconfig_templates:defaultheader:show:trueshow_states:truecolorize_states:trueall_series_config:stroke_width:2opacity:0.3type:areaviews: -title:Mainpanel:truecards:[...]
And then where you define your card, you can consume those templates, and/or overload it:
-type:custom:apexcharts-cardconfig_templates:bandwidth_chartheader:title:WAN Bandwidthseries: -entity:sensor.wan_download -entity:sensor.wan_uploadinvert:true
In the end, this would produce the same result as but it's shorter and you can reuse that template elsewhere:
-type:custom:apexcharts-cardgraph_span:24hheader:title:WAN Bandwidthshow:trueshow_states:truecolorize_states:trueall_series_config:stroke_width:2opacity:0.3type:areacolor_list:['red', 'green', 'blue']series: -entity:sensor.wan_download -entity:sensor.wan_uploadinvert:true
This will allow you to apply some settings to all the series avoiding repetition. It's just syntaxic sugar and doesn't add more features.
Eg:
-type:custom:apexcharts-cardgraph_span:24hall_series_config:stroke_width:2type:areatransform:return x / 1024;unit:Mb/sseries: -entity:sensor.wan_download -entity:sensor.wan_uploadinvert:true
Generates the same result as repeating the configuration in each series:
-type:custom:apexcharts-cardgraph_span:24hseries: -entity:sensor.wan_downloadstroke_width:2type:areatransform:return x / 1024;unit:Mb/s -entity:sensor.wan_uploadinvert:truestroke_width:2type:areatransform:return x / 1024;unit:Mb/s
Name | Type | Default | Since | Description |
---|---|---|---|---|
color_threshold | boolean | false | v1.6.0 | Will enable the color threshold feature. Seecolor_threshold |
disable_config_validation | boolean | false | v1.6.0 | Iftrue , will disable the config validation. Useful if you have cards adding parameters to this one. Use at your own risk. |
hidden_by_default | boolean | false | v1.6.0 | Will allow you to use thehidden_by_default option. Seehidden_by_default |
brush | boolean | false | v1.8.0 | Will display a brush which allows you to select a portion time to display on the main chart. Seebrush |
color_threshold
is an experimental feature for now since enabling it will break some other default features.
If enabled, it might:
- display the wrong serie color in the tooltip in some cases (series with datapoints not aligned mostly)
- display thin columns instead of the standard size
- completely render
apex_config.fill
options unusable, and if you do, it will break the card
Now that you are warned, it works with:
chart_type
:radialBar
,line
,pie
,donut
series
'stype
:column
,area
,line
Some notes:
- For
series
'stype: column
, the full bar will be of the color defined. Gradient is not possible - For
series
'stype: area
:- only the filled area will be displayed with the gradient. It is not possible to do so for the line.
- It works better with
stroke_width: 1
orstroke_width: 0
- If using
invert: true
, the values incolor_threshold
should stay the same as withinvert: false
.
And this is how to use it:
type:custom:apexcharts-cardexperimental:color_threshold:trueseries: -entity:sensor.temperaturecolor_threshold: -value:-10# color can be a color name, rgb(r, g, b), '#0000ff' or var(--color-variable)# default is: the default color of the seriecolor:blue# optional opacity, value from 0 to 1.# only for line and area# Default is 1 for 'type: line' and 0.7 for `type: area`opacity:1 -value:0color:cyan -value:15color:green -value:25color:orange
Enabling this experimental feature might/will break the auto-scaling and auto-column width feature. Don't open an issue for that. It only works if all the series have a unique name.
This option is useful if you want to hide a serie from the chart by default when it's loaded as if you had clicked on the legend to disable this serie.
This is how to use it:
type:custom:apexcharts-cardexperimental:hidden_by_default:trueseries: -entity:sensor.temperatureshow:hidden_by_default:true -entity:sensor.temperature_office
brush
will allow you to display a small chart on the bottom of the card to select a time frame to display on the main chart.
Things to know:
- You might have some glitches if you are using colums in either the top or the bottom of the chart. There's nothing I can do about it.
- All the features from normal series can be applied to the brush series
- You can configure the bottom chart the way you want with another specific
apex_config
also - It might be compute heavy and slow with a lot of history data points
- It is recommended to not show too much data on the bottom chart for the sake of lisibility
Here is how to use it (this represents the chart above):
type:custom:apexcharts-cardexperimental:color_threshold:truebrush:true# This is requiredgraph_span:2h# This will represent the span of the brushbrush:# selection_span: optional# defines the default selected span in the brush# Defaults to 1/4 of the `graph_span`selection_span:10m# apex_config: optionalapex_config:# Any ApexCharts settings you want to apply to the brush# Same as the standard apex_configseries: -entity:sensor.random0_100color:bluetype:areastroke_width:1color_threshold: -value:0color:red -value:50color:yellow -value:100color:green -entity:sensor.random0_100color:bluestroke_width:1float_precision:0show:# in_brush: set it to true and the serie will show up in the brushin_brush:true# add this also if you want your serie to only show up in the brushin_chart:false
- Sometimes, if
smoothing
is used alongsidearea
and there is missing data in the chart, the background will be glitchy. Seeapexcharts.js/#2180 binary_sensor
is not yet supported.- Bars will span left and right of the data point. Not so great if you use
func
to aggregate your data. Seeapexcharts.js/#1688
Not ordered by priority:
Support more types of charts (pie, radial, polar area at least)Support forbinary_sensors
Support for aggregating data with exact boundaries (ex: aggregating data with1h
could aggregate from2:00:00am
to2:59:59am
then3:00:00am
to3:59:59
exactly, etc...)Display the graph from start of day, week, month, ... with support for "up to now" or until the "end of the period"- Support for any number of Y-axis
- Support for logarithmic
Support for state mapping for non-numerical state sensorsSupport for simple color threshold (easier to understand/write than the ones provided natively by ApexCharts)Support for graph configuration templates à labutton-card
type:custom:apexcharts-cardseries: -entity:sensor.temperature
type:custom:apexcharts-cardgraph_span:6hheader:show:falseseries: -entity:sensor.humiditytype:linename:Outside Humiditygroup_by:func:avgduration:30min -entity:sensor.random0_100type:columnname:Office Humiditygroup_by:func:avgduration:30min
type:custom:apexcharts-cardgraph_span:1hheader:show:falseseries: -entity:sensor.random0_100name:AVGcurve:smoothtype:linegroup_by:duration:10minfunc:avg -entity:sensor.random0_100curve:smoothname:MINtype:linegroup_by:duration:10minfunc:min -entity:sensor.random0_100curve:smoothname:MAXtype:linegroup_by:duration:10minfunc:max -entity:sensor.random0_100curve:smoothname:LASTtype:linegroup_by:duration:10minfunc:last -entity:sensor.random0_100curve:smoothname:FIRSTtype:linegroup_by:duration:10minfunc:first
type:custom:apexcharts-cardgraph_span:1dspan:start:dayheader:show:falseseries:# data from today -entity:sensor.temperature# data from yesterday offsetted to be displayed today -entity:sensor.temperatureoffset:-1d
Change all lines thickness
type:custom:apexcharts-cardgraph_span:1dall_series_config:stroke_width:2series: -entity:sensor.temperature -entity:sensor.humidity
Selective line thickness modification
type:custom:apexcharts-cardgraph_span:1dseries: -entity:sensor.temperaturestroke_width:2 -entity:sensor.humiditystroke_width:6
This requires theauto-entities card
type:custom:auto-entitiesfilter:include: -entity_id:sensor.temperature*options:entity:this.entity_idcard:type:custom:apexcharts-card
This is described in the ApexCharts.js documentationhere where you can find way more options.
type:custom:apexchart-cardapex_config:chart:height:250pxseries: -entity:sensor.temperature
About
📈 A Lovelace card to display advanced graphs and charts based on ApexChartsJS for Home Assistant