Oh-value-axis in chart values divided by 1.000? Show kW instead of W?

Hi,
I would like to optimize the following widget so that on the y-axis “kW” is shown instead of “W”.

image

Is there another way to create five new items whose values are divided by 1.000?
Can’t I somehow define a scaling factor “value /1000” in my widget?

Thank you for any advice and your time.

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.

uid: solar-graph
tags: []
props:
  parameters:
    - context: item
      default: SolaxH15_FeedInPower
      description: GRID Power Item
      label: GRID Power
      name: gridPower
      required: true
      type: TEXT
    - context: item
      default: SolaxH15_PvTotalPower
      description: SOLAR Power Item
      label: SOLAR Power
      name: PvTotalPower
      required: true
      type: TEXT
    - context: item
      default: SolaxH15_PowerUsage
      description: CONSUMPTION Item
      label: CONSUMPTION Item
      name: consumption
      required: true
      type: TEXT
    - context: item
      default: SolaxH15_BatteryPower
      description: BATTERY Power
      label: Battery Power
      name: batteryPower
      required: true
      type: TEXT
  parameterGroups: []
timestamp: Jun 6, 2024, 1:26:57 PM
component: f7-card
config:
  class:
    - padding-bottom
  style:
    --f7-popover-width: 760px
slots:
  default:
    - component: f7-row
      config:
        style:
          height: 100%
          top: 0px
          width: 100%
      slots:
        default:
          - component: f7-col
            config:
              width: 100
            slots:
              default:
                - component: oh-chart
                  config:
                    chartType: ""
                    label: Power
                    period: 4h
                  slots:
                    dataZoom:
                      - component: oh-chart-datazoom
                        config:
                          type: inside
                    grid:
                      - component: oh-chart-grid
                        config:
                          containLabel: false
                    legend:
                      - component: oh-chart-legend
                        config:
                          bottom: 3
                          type: scroll
                    series:
                      - component: oh-time-series
                        config:
                          color: orange
                          gridIndex: 0
                          item: =props.PvTotalPower
                          name: Solar
                          type: line
                          xAxisIndex: 0
                          yAxisIndex: 0
                      - component: oh-time-series
                        config:
                          color: "#6cbe58"
                          gridIndex: 0
                          item: =props.batteryPower
                          name: Batterie Leistung
                          type: line
                          xAxisIndex: 0
                          yAxisIndex: 0
                      - component: oh-time-series
                        config:
                          color: blue
                          gridIndex: 0
                          item: =props.gridPower
                          name: Grid
                          type: line
                          xAxisIndex: 0
                          yAxisIndex: 0
                      - component: oh-time-series
                        config:
                          color: "#e64a19"
                          gridIndex: 0
                          item: =props.consumption
                          name: Verbrauch
                          type: line
                          xAxisIndex: 0
                          yAxisIndex: 0
                    tooltip:
                      - component: oh-chart-tooltip
                        config:
                          confine: true
                          smartFormatter: true
                    xAxis:
                      - component: oh-time-axis
                        config:
                          gridIndex: 0
                    yAxis:
                      - component: oh-value-axis
                        config:
                          gridIndex: 0
                          name: W

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.

1 Like

Actually, what you want is possible, thanks to what @ehorvat1 shows in this post:

You can add a formatter to your Y-Axis and divide all values by 1000 to convert from W to kW:

  yAxis:
    - component: oh-value-axis
      config:
        axisLabel:
          formatter: =v=>Number.parseFloat(v)/1000

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:

        markPoint:
          label:
            formatter: '=v=>Number.parseFloat(v.value)/1000 + " kW"'
3 Likes

Thank you so much. That helped a lot!