Hello Everyone,
I try to create a widget to display the realtime power consumption in my house.
The result I would like to achieve is something like that:
But what I would also like, is to dynamically construct the oh-data-series so configuration of the widget is simple.
I first give a try with oh-repeater, but hit the problems that oh-repeater don’t work with echart (Oh-repeater not working for oh-time-series in oh-chart).
The idea was to pass a group of items as a parameter, and iterate it with oh-repeater.
I also try by feeding directly JSON from an item to the oh-data-series. The idea was to construct the Json from a rule.
The following code is working well, giving the result show above.
uid: widget_1dcd9ac689
tags: []
props:
timestamp: May 8, 2024, 7:17:40 PM
component: f7-card
config:
title: "TestJSon"
content: =@@'TestJSon'
slots:
default:
- component: oh-list
slots:
default:
- component: oh-chart
config:
label: Power
legend:
top: 5%
left: center
show: true
slots:
series:
- component: oh-data-series
config:
type: pie
avoidLabelOverlap: false,
labelLine:
length: 30
radius:
- 40%
- 60%
label:
show: true
formatter: "{b} {c}"
backgroundColor: "#F6F8FC"
borderColor: "#8C8D8E"
borderWidth: 1
borderRadius: 4
padding: 20
data:
[{'value':'20','name':'Hoven'},{'value':'30','name':'Dishwasher'},{'value':'50','name':'Light'}]
But if I replace the code by an item state:
uid: widget_1dcd9ac689
...
data:
=item.TestJSon.state
I’ve got the following results:
It seems because oh-data-series in this case interprete the data as a string, and not as a Json.
I get the same results if I put into data the following code:
data:
"[{'value':'20','name':'Hoven'},{'value':'30','name':'Dishwasher'},{'value':'50','name':'Light'}]"
Does someone has any idea how to make this working ?
Thanks,
Laurent.