Any Apex Charts experts out there?

Proud of myself for working out how to link to UK Met Office weather data using Node Red, creating a sensor in HA and displaying a chart on my dashboard using Apex Charts. Only took me 5 minutes.

My chart needs refinement. The X axis shows a rolling 48 hours - showing labels every 3rd hour. Is there a way to highlight each midnight so today / tomorrow / next day are immediately obvious?

And/or: I have a ‘brush’ - brilliant feature - but if I show 24 hours as a default, it shows the last 24 hours rather than first. Is there a simple way to change this? I think some clever people have written work-around code to achieve this, probably a bit complex for me.

Did I say all this took me 5 mins? Typo - meant 5 weeks.

Any advice very much appreciated.

Here’s pic of my chart:

Here’s my chart yaml:

type: custom:apexcharts-card
experimental:
  color_threshold: true
  brush: true
show:
  loading: true
  last_updated: true
graph_span: 2d
brush:
  selection_span: 2d
span:
  start: hour
header:
  title: Risk of Rain
  show: true
yaxis:
  - id: Probability
    show: true
    opposite: false
    min: 0
    max: ~20
    decimals: 0
    apex_config:
      stepSize: 5
  - id: Amount
    show: true
    opposite: true
    min: 0
    max: ~2
    apex_config:
      stepSize: 0.5
apex_config:
  xaxis:
    labels:
      format: HH
  grid:
    show: true
    xaxis:
      lines:
        show: true
series:
  - entity: sensor.forecast
    name: < Feels like C
    yaxis_id: Probability
    data_generator: |
      return entity.attributes.attributes.datetime.map((time, index) =>
      {return[new Date(time).getTime(),
      entity.attributes.attributes.feelslike[index]]});
    color: red
    opacity: 1
    stroke_width: 1
    type: line
    show:
      legend_value: false
      in_brush: true
  - entity: sensor.forecast
    name: < Probability %
    yaxis_id: Probability
    data_generator: |
      return entity.attributes.attributes.datetime.map((time, index) =>
      {return[new Date(time).getTime(),
      entity.attributes.attributes.rainprob[index]]});
    color_threshold:
      - value: 0
        color: yellow
      - value: 25
        color: green
      - value: 50
        color: blue
    opacity: 1
    stroke_width: 2
    type: line
    show:
      legend_value: false
      in_brush: true
  - entity: sensor.forecast
    name: Amount mm >
    yaxis_id: Amount
    data_generator: |
      return entity.attributes.attributes.datetime.map((time, index) =>
      {return[new Date(time).getTime(),
      entity.attributes.attributes.rainamount[index]]});
    color: turquoise
    opacity: 0.2
    stroke_width: 1
    type: area
    show:
      legend_value: false
      in_brush: true

I had to chop about with your config to be able to experiment myself - my weather service does not provide the same values as your entity, however I got something similar up and running. Apex Charts are a great deal of fun to work with, but the challenge is that nothing shows up until/unless you have everything correct…

There is an apex_config ‘annotations’ setting that will annotate text at set values for the x or y axis. Note that the ‘now’ option, which automatically shows ‘now’ has to be disabled for any of your own x axis annotations to show up.
I have already worked out how to add x-axis area shading, using two time values on a time-based graph. You can use dynamic values with the EVAL operator, however as far as I can tell this only permits a single line JS expression, hence the need for something complex so as to use both .setDate and .setHours. The following (added under the configuration main ‘apex_config’) appears to work and shades ‘tomorrow’

  annotations:
    xaxis:
      - x: >-
          EVAL:new Date(new Date().setDate(new Date().getDate()
          +1)).setHours(00,0,0)
        x2: >-
          EVAL:new Date(new Date().setDate(new Date().getDate()
          +2)).setHours(0,0,0)
        label:
          text: Tomorrow
          borderWidth: 0
          style:
            background: '#0000'

Naturally you can use just - x: on its own with setDate +1 setHours(0,0,0) for midnight today, and then add another label likewise with setDate +2 etc for midnight tomorrow, and so on. I like the shading myself, so perhaps today unshaded, tomorrow shaded, the next day unshaded and so on…

As for brushing, this is not something I have previously experimented with, and it would appear that in the HA card integration, the brush window will always default to the far right (where the brush window is smaller than the graph window).

I have found that, within ‘brush’ you can add ‘apex_config’ and use any of the configuration settings to adjust the brush window, however the graph_span and span (start/offset) do not appear to have any effect. The xaxis label does…

brush:
  selection_span: 1d
  apex_config:
    graph_span: 2d
    span:
      start: day
    xaxis:
      labels:
        format: HH

Many thanks for the link. Actually I realise I already used lots of advice from that thread - but finding posts/relies from separate searches as I made progress. It is a great resource - but sadly no solutions to my questions that I could find.

You are a genius! Many many thanks for this - it would have taken me at least another 5 weeks to work this out, if ever.

Going to have a play with your shading solution tonight.

Sorry - this is not correct.
I am not the apexcharts card author - and I have a very little presence in that apexcharts thread. You probably mistook with some other threads which I am trying to run…
This is a card of RomRider.

Noted. Yes, I probably confused this with the flex-table card. Credit where credit is due.

Original post edited to correct my error.

Brilliant!

If only I had known to do a search for ‘annotations’, I might have got on the right track but it would have taken ages for me to work out the JS expression to use.

It only took me 30 seconds to get this to work (not including the 30 minutes tracing my indentation error…)

I’ve given up on the brush feature for the time being.

Thanks again