Number:Dimensionless in chart legend

Another tricky chart formatter one hoping for @JustinG’s guru-ness (sorry upfront to ping you right away).

Some recent changes to 5.2 also made units appear in chart legends, too. Nice.
However, as “ct” ain’t a valid unit (only EUR is) but I need this scaling to have it fit into the same scale as % items, I’ve turned the last 2 items into Number:Dimensionless type rather than Number:EnergyPrice.

Now I tried to replace the one by ct/kWh but fail, this is what I attempted:

      tooltip:
        - component: oh-chart-tooltip
          config:
            orient: vertical
            show: true
            trigger: axis
            formatter: =(params) => Number.parseFloat(params.value).toFixed(1).toString.replace('.',',').replace('one','ct')
            valueFormatter: =(value) => value.replace('one','ct')

Any better idea?

This has been available for a while through the tooltip’s smartFormatter property (if set to true tooltip values are processed in an item and locale aware way). You’re now seeing the units on charts where you didn’t used to because one of the recent changes to the charts is that the smartFormatter property is set to true by default. This is probably better for beginning users, but that setting overrides custom formatters that you define both in the tooltip and for each individual series. So, now in 5.2 to get custom formatters to work you need to explicitly set smartFormatter: false in the tooltip config.

However, once you do that things get a little more complicated. Because all the units in each of the time series is coming from that smartFormatter that just got turned off. So, setting valueFormatter: =(x)=> x + ' ct' in the tooltip config will set all the units in the entire tooltip to ‘ct’ which is probably not what you want. You’ll need to add:

tooltip:
  valueFormatter: =(x)=> x + ' [desired unit]'

to the configs of all the time series directly instead of just in the oh-cart-tooltip conifg.

Great advice, once more. Thank you!

Nice hint.

An additional question: What about labels of mark points or mark lines? Before it was possible to have user-defined formatters on them too. Now they seem not to work anymore. I already disabled the smartFormatter in the tooltip like described above.

        markLine:
          data:
            - name: Durchschnitt
              type: average
          label:
            formatter: =l=>l.data.value.toFixed(1).toString().replace('.', ',') + ' W'

Sry. Minor adjustment from my side - not the labels of mark points or mark lines but the tooltip for those.

That’s less clear. The same PR that made smartFormatter default to true did add some configuration options for marklines but from what I see those options shouldn’t override your custom settings. @florian-h05 might have to weigh in on this question.

Setting smartFormatter to false should do the trick. See openhab-webui/bundles/org.openhab.ui/web/src/components/widgets/chart/misc/oh-chart-tooltip.ts at 156a73beb75533ea405e2a5295caff79fd208650 · openhab/openhab-webui · GitHub.

mark points don’t appear in tooltip, do they?
Or do you mean the label of averages shown on the right hand side? Formatting these is working with the label formatter entry from your previous post and isn’t affected by smartFormatter.

does anyone know how to set the date line at the top of the tooltip to my DE locale?
(without using smartFormatter which does this, too)

When you’re hovering the markPoint or markLine a tooltip appears. I’m neither asking for the labels inside the bubble of the markPoints nor the labels on the right hand side for the markLine.

An example:

I don’t think this is impossible, but it would be very difficult. You would have to use the formatter property of the tooltip itself again, and build the entire tooltip html, which is very near the limits of what you can do with a single widget expression. Also, with multiple series, the expression would need to be able to handle both arrays of data and a single data object.

I found the solution with the help AI. It is the same like for the series. Both markPoint and markLine accept a tooltip property with valueFormatter. Like this:

        markLine:
          data:
            - name: Durchschnitt
              type: average
          label:
            formatter: =l=>l.data.value.toFixed(1).toString().replace('.', ',') + ' W'
            position: insideEndTop
          tooltip:
            valueFormatter: =(value) => Number(value).toFixed(1).toString().replace('.', ',') + ' W'