You haven’t really provided enough information here to really answer.
The chart shows the Item’s actual state. This Item is a Number:Power and it’s unit is set to W. So the values stored in the database is in W and that is what gets charted.
If want these values charted in kW, the easiest thing to do would be to simply change the unit on the Item to kW.
However, this is only going to affect the persistence going forward. It will not change the values already stored in persistence. In fact, it’s going to assume those values are actually kW. So be careful when changing the units of an Item. Often it is a good idea to delete the old data after changing the unit like that. For rrd4j that’s as simple as deleting the file for the Item in $OH_USERDATA/persistence/rrd4j.
You can of course create new Items linked to the same Channel and set the unit metadata to kW instead of W.
Thanks for the quick answer which I fully understand. Though I like to have the values in W because I use them like this more often. So changing the unit is no option.
I could create double items to store the same values just with an other unit. But this doesn’t feel correct as this is redudant data.
Therefore I would like to know If I can just change the uni for the chart view.
To provide more information I add the code of my widget.
If you are using them in rules you can choose what unit you use. So the Item’s unit can be kW but you do all the math and comparisons in your rules using W.
In UI widgets, if you want to see W instead of kW you can set the State Description pattern to %.0f W and the kW carried by the Item’s state will be converted to W for display.
Unit conversions are not supported by charts. Except for the label on the axis, the charts are completely oblivious of the units. Whatever is saved is what gets charted. What gets saved and charted is the value in the units of the Item as defined by the unit metadata or the system default which is W for Number:Power.
Despite what you feel about it, your options are to set the Item’s unit to kW and adjust your rules and state description to use W, or create separate Items with the unit set to kW.
Note that I’m using Number.parseFloat(v) here, while ehorvat1 uses Number.parseFloat(v.data[1]). Frankly, I have no idea, why. Found this by trial and error.
For the markPoint in the same chart I had to use Number.parseFloat(v.value) to see the value, otherwise it would just show NaN.
Example: