I have tried to use offsets to move the line, without luck, managed to get the data to be the right place according to the line, but then there is a large empty space to the left in the chart.
Any suggestions to how I can get Now to actually indicate now?
Now is being plotted at ‘now’. You just have your data plotted at midnight, not the middle of the day at 12:00.
Using d.setHours(0, 0, 0) puts the plot time at midnight. Try d.setHours(12,0,0).
If, then, you don’t like having the label ‘Sat’ at 00:00 (which is correctly the start of the day) then you will have to leave the label at 00:00, and the data at 00:00, and then plot your own ‘now’ 12 hours earlier than it really is.
If you turn off the in-built ‘now’ (set ‘show’ to false) you can easily add your own annotation 12 hours earlier than it really is
apex_config:
annotations:
xaxis:
- x: EVAL:Date.now()-(12*60*60*1000)
label:
text: Now
position: top
borderWidth: 1
A negative offset makes the space larger, a positive offset makes the space smaller.
The problem there is that as soon as I put a positive offset in, the name for the current day disappear.
Getting exactly what you want in an Apex Chart graph is often a matter of experimenting and making adjustments with several of the various settings. The one you probably need now is span ‘offset’ which shifts the anchor point of the graph start.
I don’t have your sensor, so I made the data up. I have set the graph_span to 6 days, set the span start to ‘day’ and added an offset of -2 hours. This setting often requires experimentation to get the graph and the x-axis labels to show what you wish.
For myself, the annotation works perfectly, and adds a new ‘now’ line, leaving the label plotted at midnight, and the data plotted at midnight, and the “now” line showing at an arguably more appropriate point in the ‘day’ (it now being 10:30 in the morning for me)
Only problem left now is to make the annoration red. I expected color: to do it, but nothing happened.
After looking a bit at annotations – ApexCharts.js I tried some of the references from there, and borderColor: changed the color of the border, but fillColor: had no effect.
The extra apex configs are very tricky, and I find that most of them don’t always work.
We have switched off the standard included ‘now’ and we are doing our own annotation (the standard now conflicts with annotations, and we want to move ‘now’ by 12 hours as well).
Annotations have fillColour and borderColour options, and these apply firstly to the annotation line or area defined, then when used under “label” to the label text, and then when used under “style” to the label box itself.
I can’t get all of the options to work, however this does give a red-filled box for the label text. Quite why in most places a colour red is defined as ‘red’ or ‘#ff0000’ but in style I have to use just ‘#f00’ I have no idea. There comes a time when my patience for experimenting runs out and I need to stop.
Why not move the “Bar”, so the bar is “between” Sun/Mon, sunday starts at 00 till 24, i prefer the Bar “inbetween” so the x-marker Sun is the breakpoint
I spend most of the evening last night just trying to get it to show the bars correct, and when I finally got that, Now was out of position. Ending up running in circles with always one thing being off.