Year as oh-aggregate-series name

Hello

Is it possible to automatically display the year as the serial name?

config:
  chartType: year
  label: linkyPapp
slots:
  grid:
    - component: oh-chart-grid
      config: {}
  xAxis:
    - component: oh-category-axis
      config:
        gridIndex: 0
        categoryType: year
        monthFormat: short
        weekdayFormat: short
  yAxis:
    - component: oh-value-axis
      config:
        gridIndex: 0
        name: W
  series:
    - component: oh-aggregate-series
      config:
        name: 2021
        item: linkyPapp
        gridIndex: 0
        xAxisIndex: 0
        yAxisIndex: 0
        type: bar
        dimension1: month
        offsetUnit: year
        offsetAmount: 2
    - component: oh-aggregate-series
      config:
        name: 2022
        item: linkyPapp
        gridIndex: 0
        xAxisIndex: 0
        yAxisIndex: 0
        type: bar
        dimension1: month
        offsetUnit: year
        offsetAmount: 1
    - component: oh-aggregate-series
      config:
        name: 2023
        item: linkyPapp
        gridIndex: 0
        xAxisIndex: 0
        yAxisIndex: 0
        type: bar
        dimension1: month
  tooltip:
    - component: oh-chart-tooltip
      config:
        confine: true
  legend:
    - component: oh-chart-legend
      config:
        bottom: 3

I would like
name: 2021
name: 2022
name: 2023
to be updated automatically

Use dayjs in the expression:

name: =dayjs().year()
name: =dayjs().year()-1
name: =dayjs().year()-2

it doesn’t work

for other elements in a widget it works but in the chart it doesn’t work

I’m using openHAB 3.4.4. Is it working on OH 4?

Capture d’écran du 2023-09-10 09-52-13

And if I understand correctly, it takes “today’s” year, not the year on the chart.
Capture d’écran du 2023-09-10 09-57-44

So in principle it works on oh4. The migration is planned, so problem 1 has been solved.

But is it possible to recover the date selected in the graph ?

Sorry, somehow I missed your previously reply. Yes, the expression works just fine in OH4.

That I don’t think is possible. The widget expressions are not full javascript engines, each one is run in it’s own context by a js-like expression parser so there are limitations to the information available in expressions.

Off the top of my head, I would say that to achieve something like this you would need to develop your own custom widget with a chart that is linked to another widget for selection of the year. Then you would be able to pass a widget variable with the year to both the chart and the chart labels.

It seems complicated. I’m just going to use dayjs as a first step anyway, for the moment I don’t have any data for more than 3 years.

Thanks a lot!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.