Filter nordpool values in apexcharts

I currently collect day ahead prices via the nordpool integration.
In an apaxchart I show the future values.
I want the y-axis to range from the lowest future value to the highest future value.
However when deciding the range also values in the past are considered. How can I solve this.
Screenshot_20240407_215557

type: custom:config-template-card
variables:
  dayend: new Date().setHours(23,30,0,0)
entities: sensor.electricityprice_by_hour_2
card:
  type: custom:apexcharts-card
  experimental:
    color_threshold: true
  graph_span: 33h
  span:
    start: hour
    offset: +1h
  yaxis:
    - id: first
      decimals: 1
      apex_config:
        tickAmount: 9
  header:
    show: true
    title: Electricity price today (cent/kwh)
  series:
    - entity: sensor.nordpool_kwh_nl_eur_3_10_021
      float_precision: 1
      type: column
      opacity: 1
      data_generator: |
        let td = entity.attributes.raw_today;
        let tm = entity.attributes.raw_tomorrow;
        let dataset = [
          ...td.map((data, index) => {
            return [data["start"], 100 * data["value"]];
          }),
          ...tm.map((data, index) => { 
            return [data["start"], 100 * data["value"]];
          })
        ];
        return [...dataset];
      color_threshold:
        - value: 15
          color: lightgreen
        - value: 20
          color: green
        - value: 25
          color: black
        - value: 30
          color: orange
        - value: 35
          color: red
        - value: 40
          color: darkred
  apex_config:
    annotations:
      position: front
      xaxis:
        - x: ${{ dayend }}
          strokeDashArray: 0
    xaxis:
      labels:
        datetimeFormatter:
          hour: HH

I managed to get a filter in the data_generator.
This seems to solve the issue.

type: custom:config-template-card
variables:
  dayend: new Date().setHours(23,30,0,0)
entities: sensor.electricityprice_by_hour_2
card:
  type: custom:apexcharts-card
  experimental:
    color_threshold: true
  graph_span: 34h
  span:
    start: hour
  yaxis:
    - id: first
      decimals: 1
      apex_config:
        tickAmount: 9
  header:
    show: true
    title: Electricity price today (cent/kwh)
  series:
    - entity: sensor.nordpool_kwh_nl_eur_3_10_021
      float_precision: 1
      type: column
      opacity: 1
      data_generator: |
        let td = entity.attributes.raw_today;
          const d = new Date();
          let hour = d.getHours();
          const tdfuture = td.filter(tarif => tarif.start.substring(11,13) >= hour);
        let tm = entity.attributes.raw_tomorrow;
        let dataset = [
          ...tdfuture.map((data, index) => {
            return [data["start"], 100 * data["value"]];
          }),
          ...tm.map((data, index) => { 
            return [data["start"], 100 * data["value"]];
          })
        ];
        return [...dataset];
      color_threshold:
        - value: 15
          color: lightgreen
        - value: 20
          color: green
        - value: 25
          color: black
        - value: 30
          color: orange
        - value: 35
          color: red
        - value: 40
          color: darkred
  apex_config:
    annotations:
      position: front
      xaxis:
        - x: ${{ dayend }}
          strokeDashArray: 0
    xaxis:
      labels:
        datetimeFormatter:
          hour: HH

1 Like