Skip to content

Commit c82a679

Browse files
Main add graph unit (#632)
* Add the Unit field to Graph Panels * Update changelog for Graph Panel
1 parent 1a0a0e8 commit c82a679

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Changelog
1010
.. _`docs`: https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/manage-dashboard-links/#dashboard-links
1111

1212
* Added ...
13+
* Add Unit option for Graph panel
1314
* Added Minimum option for Timeseries
1415
* Added Maximum option for Timeseries
1516
* Added Number of decimals displays option for Timeseries

grafanalib/core.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ class Graph(Panel):
21042104
:param stack: Each series is stacked on top of another
21052105
:param percentage: Available when Stack is selected. Each series is drawn as a percentage of the total of all series
21062106
:param thresholds: List of GraphThresholds - Only valid when alert not defined
2107-
2107+
:param unit: Set Y Axis Unit
21082108
"""
21092109

21102110
alert = attr.ib(default=None)
@@ -2138,6 +2138,7 @@ class Graph(Panel):
21382138
validator=instance_of(Tooltip),
21392139
)
21402140
thresholds = attr.ib(default=attr.Factory(list))
2141+
unit = attr.ib(default='', validator=instance_of(str))
21412142
xAxis = attr.ib(default=attr.Factory(XAxis), validator=instance_of(XAxis))
21422143
try:
21432144
yAxes = attr.ib(
@@ -2157,6 +2158,11 @@ def to_json_data(self):
21572158
'aliasColors': self.aliasColors,
21582159
'bars': self.bars,
21592160
'error': self.error,
2161+
'fieldConfig': {
2162+
'defaults': {
2163+
'unit': self.unit
2164+
},
2165+
},
21602166
'fill': self.fill,
21612167
'grid': self.grid,
21622168
'isNew': self.isNew,

0 commit comments

Comments
 (0)