I'm using Vega-Lite to create a simple line chart to plot stock prices.
The problem with the chart is the zones marked in grey, which correspond to week-ends. The market is only open on week-days so I don't want the horizontal axis (date) to show week-ends as it becomes "false" from a finance point of view. Basically a business hour is 9am to 16pm (week-end excluded) and I would like the x-axis to reflect that.
How can I skip
the non-business days (here Saturday/Sunday) on a temporal axis?
Here is the underlying data:
Symbol,Date,Close
AMZN,2020/08/10 10:00,3170
AMZN,2020/08/10 11:00,3104.11
AMZN,2020/08/10 12:00,3134.05
AMZN,2020/08/10 13:00,3140.38
AMZN,2020/08/10 14:00,3138.15
AMZN,2020/08/10 15:00,3149.16
AMZN,2020/08/10 16:00,3149.87
AMZN,2020/08/10 17:00,3137.6
FB,2020/08/10 10:00,267.75
FB,2020/08/10 11:00,260.75
FB,2020/08/10 12:00,264.32
FB,2020/08/10 13:00,263.24
FB,2020/08/10 14:00,262.08
FB,2020/08/10 15:00,262.38
FB,2020/08/10 16:00,263
FB,2020/08/10 17:00,263.09
AMZN,2020/08/11 10:00,3121
AMZN,2020/08/11 11:00,3123.5
AMZN,2020/08/11 12:00,3135.33
AMZN,2020/08/11 13:00,3143.11
AMZN,2020/08/11 14:00,3135.1
AMZN,2020/08/11 15:00,3121.76
AMZN,2020/08/11 16:00,3080.67
AMZN,2020/08/11 17:00,3085.99
FB,2020/08/11 10:00,260
FB,2020/08/11 11:00,263.95
FB,2020/08/11 12:00,263.83
FB,2020/08/11 13:00,264.59
FB,2020/08/11 14:00,263.78
FB,2020/08/11 15:00,260.29
FB,2020/08/11 16:00,256.11
FB,2020/08/11 17:00,256.6
AMZN,2020/08/12 10:00,3151.62
AMZN,2020/08/12 11:00,3143.74
AMZN,2020/08/12 12:00,3152.53
AMZN,2020/08/12 13:00,3153.75
AMZN,2020/08/12 14:00,3167.69
AMZN,2020/08/12 15:00,3158.09
AMZN,2020/08/12 16:00,3158.7
AMZN,2020/08/12 17:00,3160.51
FB,2020/08/12 10:00,261.8
FB,2020/08/12 11:00,262.27
FB,2020/08/12 12:00,261.44
FB,2020/08/12 13:00,260.1
FB,2020/08/12 14:00,261.68
FB,2020/08/12 15:00,260.73
FB,2020/08/12 16:00,259.83
FB,2020/08/12 17:00,259.7
AMZN,2020/08/13 10:00,3181
AMZN,2020/08/13 11:00,3201.73
AMZN,2020/08/13 12:00,3209.34
AMZN,2020/08/13 13:00,3195.99
AMZN,2020/08/13 14:00,3198.41
AMZN,2020/08/13 15:00,3181.06
AMZN,2020/08/13 16:00,3170.61
AMZN,2020/08/13 17:00,3161.02
FB,2020/08/13 10:00,261.8
FB,2020/08/13 11:00,262.88
FB,2020/08/13 12:00,264.13
FB,2020/08/13 13:00,262.36
FB,2020/08/13 14:00,262.11
FB,2020/08/13 15:00,261.06
FB,2020/08/13 16:00,259.98
FB,2020/08/13 17:00,261.49
For comparison, here is how it looks like on Google Finance (single step between Fri/Mon, same as Thu/Fri)
Thanks in advance for the help!
You can do this by using an ordinal x-axis encoding with an appropriate timeUnit. This will result in an axis that only reflects values actually present in your data.
For example (open in editor):