How to set label precission (decimal places) in a bar chart

Is it possible to set a fixed number of decimal places for the label in a bar chart (echart)?
I found a way for the “markLine” (series-bar.markLine.precision ), but I didn’t figure out a possibility for the label itself. I want to get rid of the decimal places in my bar chart.

Screenshot 2022-10-18 125327

Thank you!

If you haven’t found the answer looking around on the eCharts docs, then it is likely that the only thing you can do try and set the precision on the data before you send it to the chart.

OK, thanks. Do you have a hint how I can do this? I’m using influxdb as a persistence service. I’m not sure how the data is sent to the chart and if there is a possibility to change the precision there.

I meanwhile found out, that echart is providing a callback function which allows data manipulation. I’m not sure if it is possible to use it with the yaml code.

In the eChart sandbox I can do the following:

      label: {
        show: true,
        formatter: function(param) {
          return param.data.toFixed(2);
        }
      },
    }

How can I translate this callback function to yaml code in openhab?

No one has yet gotten the eCharts callback functions to work via the yaml. It seems that after the initial conversion to the yaml string is performed to pass the info to openHAB it is never re-parsed as anything but a string so eCharts just interprets it as a string literal as well. This would likely require OH to make some sort of broad eval() call on the yaml value which is, of course, a colossally bad idea in general.

Sorry, I’ve never used influxdb so I can’t help you there at all.

IMHO this should work, at least in latest snapshots …

formatter: =v=>v.toFixed(2)

Did try only on a gauge, but probably should work for all …

EDIT: syntax for bar is a bit different:

label:
  show: true
  formatter: =v=>Number.parseFloat(v.data[1]).toFixed(1)

this did the trick for me

or with toFixed(3):

2 Likes

Honestly, I’m surprised that works, but, that’s great to know.

Thanks a lot for your help. It’s still not working for me, but I guess it’s because I don’t use the latest snapshot. Very good to know, that I will have a solution after updating, thanks!

IMHO you’ll need this change in order to make it work, which was merged ~9 days ago, so any snapshot containing this should work …

Hello, I am on 3.4.1 and none of the both suggestions works for. Any other experiences?