65
65
- **max_value** (*Optional*): Specifies the maximum Y-axis value.
66
66
- **min_value** (*Optional*): Specifies the minimum Y-axis value.
67
67
- **traces** (*Optional*): Use this to specify more than a single trace.
68
+ - **legend** (*Optional*): Configures a legend for the graph traces. See [Legend Options](#legend-options).
68
69
69
70
Trace specific fields:
70
71
@@ -74,15 +75,60 @@ Trace specific fields:
74
75
- **continuous** (*Optional*): connects the individual points to make a continuous line. Defaults to `false`.
75
76
- **color** (*Optional*): Sets the color of the sensor trace.
76
77
78
+ # # Legend Options
79
+
80
+ The legend displays trace names, current values, units, and line style samples. Only one legend per graph is supported.
81
+
82
+ - **name_font** (**Required**, [Font](#display-fonts)): Font used for trace names.
83
+ - **value_font** (*Optional*, [Font](#display-fonts)): Font used for current values. If not specified, values are not displayed.
84
+ - **width** (*Optional*, int): Legend width in pixels. If not specified, width is automatically calculated.
85
+ - **height** (*Optional*, int): Legend height in pixels. If not specified, height is automatically calculated.
86
+ - **border** (*Optional*, boolean): Draw a border around the legend. Defaults to `true`.
87
+ - **show_lines** (*Optional*, boolean): Display line style samples. Defaults to `true`.
88
+ - **show_values** (*Optional*): Position of current values. Can be `NONE`, `AUTO`, `BESIDE`, `BELOW`. Defaults to `AUTO`.
89
+ - **show_units** (*Optional*, boolean): Include units with values. Defaults to `true`.
90
+ - **direction** (*Optional*): Layout direction. Can be `AUTO`, `HORIZONTAL`, `VERTICAL`. Defaults to `AUTO`.
91
+
92
+ Example with legend :
93
+
94
+ ` ` ` yaml
95
+ graph:
96
+ - id: temperature_graph_with_legend
97
+ duration: 1h
98
+ width: 151
99
+ height: 51
100
+ traces:
101
+ - sensor: indoor_temp
102
+ name: "Indoor"
103
+ line_type: SOLID
104
+ color: my_red
105
+ - sensor: outdoor_temp
106
+ name: "Outdoor"
107
+ line_type: DASHED
108
+ color: my_blue
109
+ legend:
110
+ name_font: legend_font
111
+ value_font: value_font
112
+ show_values: BELOW
113
+ border: true
114
+ show_lines: true
115
+ show_units: true
116
+
117
+ font:
118
+ - file: "arial.ttf"
119
+ id: legend_font
120
+ size: 10
121
+ - file: "arial.ttf"
122
+ id: value_font
123
+ size: 8
124
+ ` ` `
125
+
77
126
And then later in code :
78
127
79
128
` ` ` yaml
80
129
display:
81
130
- platform: ...
82
131
# ...
83
- pages:
84
- - id: page1
85
- lambda: |-
86
132
pages:
87
133
- id: page1
88
134
lambda: |-
@@ -92,6 +138,11 @@ display:
92
138
lambda: |-
93
139
// Draw the graph at position [x=10,y=20]
94
140
it.graph(10, 20, id(multi_temperature_graph), my_yellow);
141
+ - id: page3
142
+ lambda: |-
143
+ // Draw graph and legend
144
+ it.graph(10, 20, id(temperature_graph_with_legend));
145
+ it.graph_legend(170, 20, id(temperature_graph_with_legend), my_yellow);
95
146
96
147
color:
97
148
- id: my_red
@@ -117,6 +168,8 @@ Here are some things to note:
117
168
118
169
- Setting `y_grid` will expand any specified range to the nearest multiple of grid spacings.
119
170
- Axis labels are currently not possible without manually placing them.
120
- - The grid and border color is set with it.graph(), while the traces are defined separately.
171
+ - The grid and border color is set with `it.graph()`, while the traces are defined separately.
172
+ - Legends are drawn separately using `it.graph_legend()` and can be positioned independently of the graph.
173
+ - Legend dimensions are automatically calculated if not specified, based on font sizes and trace count.
121
174
122
175
{{< /note >}}
0 commit comments