p45cal: I think I can close this thread, I added the following code to
1.) Delete lower x-axis
2.) Set upper axis to NOT show a time, e.g. it was showing 2/10/19 3:50 PM but with that addition, it now shows only whole days 2/10/19 for example above each tick mark
3.) Round down date/timestamp of leftmost x-axis and round up rightmost x-axis point so that even with whole days for tick marks, no points are cut off
4.) Always show ~15 major tick marks regardless of duration of plot (since user can plot 1 week to up to years of data)
I only tried this on the fixed dataset, I will plug into dynamic retrieval to make sure tick mark code works -- it may need some tweaking to endpoints to be Roundup or Down + or minus the TickInterval parameter, until I see what it does I can't say for sure on that minor detail, but obviously it is very easy to implement.
The only other thing I'd like to do is move the upper/secondary x-axis back to bottom of plot after deleting lower/primary one, not sure how to accomplish that but it's not a huge big deal.
In Peltier's example (non-VBA), he only creates TWO pairs to plot stacked area bars/bands across plot, so I also don't think I needed to include any intermediate points to plot the area bars, as I have done, but it works so probably won't change that!
I can post the full version if it is of use to anybody.
Thanks again for your assistance.
chtObj.Chart.Axes(xlCategory, xlPrimary).AxisBetweenCategories = False ' Set axis position on tick marks, thanks to p45cal @ Excelfox for figuring out!
chtObj.Chart.Axes(xlCategory).Delete ' Delete lower x-axis
chtObj.Chart.Axes(xlCategory, xlSecondary).TickLabels.NumberFormat = "m/d/yyyy" ' Set x-axis to show date only, no time
' Set first/leftmost x-value on an even day (round datetimestamp down -- could also use INT function)
chtObj.Chart.Axes(xlCategory, xlSecondary).MinimumScale = Application.WorksheetFunction.RoundDown(chtObj.Cha rt.Axes(xlCategory, xlSecondary).MinimumScale, 0)
' Set second/rightmost x-value on an event day (round datetimestamp UP -- could alternately use -INT(-x) but that is harder to read)
chtObj.Chart.Axes(xlCategory, xlSecondary).MaximumScale = Application.WorksheetFunction.RoundUp(chtObj.Chart .Axes(xlCategory, xlSecondary).MaximumScale, 0)
' Calculate number of days across x-axis to determine number of tick marks (plot width will vary so this must be set progamatically)
DaysAcross = chtObj.Chart.Axes(xlCategory, xlSecondary).MaximumScale - chtObj.Chart.Axes(xlCategory, xlSecondary).MinimumScale
If DaysAcross < 15 Then ' 1-day intervals on tick marks for < 15 day plots
TickInterval = 1
ElseIf DaysAcross > 15 And DaysAcross < 32 Then ' 2 days between tick marks for 15-32 day duration plots
TickInterval = 2
ElseIf DaysAcross > 32 And DaysAcross < 60 Then ' for 32-60 day plots set tick interval to 4 days
TickInterval = 4
Else
TickInterval = Application.WorksheetFunction.RoundUp(DaysAcross / 15, 0) ' Set tick mark interval such that it provides ~15 divisons along x-axis
End If
chtObj.Chart.Axes(xlCategory, xlSecondary).MajorUnit = TickInterval
Next Series
Code:
chtObj.Chart.Axes(xlCategory, xlPrimary).AxisBetweenCategories = False ' Set axis position on tick marks, thanks to p45cal @ Excelfox for figuring out!
chtObj.Chart.Axes(xlCategory).Delete ' Delete lower x-axis
chtObj.Chart.Axes(xlCategory, xlSecondary).TickLabels.NumberFormat = "m/d/yyyy" ' Set x-axis to show date only, no time
' Set first/leftmost x-value on an even day (round datetimestamp down -- could also use INT function)
chtObj.Chart.Axes(xlCategory, xlSecondary).MinimumScale = Application.WorksheetFunction.RoundDown(chtObj.Chart.Axes(xlCategory, xlSecondary).MinimumScale, 0)
' Set second/rightmost x-value on an event day (round datetimestamp UP -- could alternately use -INT(-x) but that is harder to read)
chtObj.Chart.Axes(xlCategory, xlSecondary).MaximumScale = Application.WorksheetFunction.RoundUp(chtObj.Chart.Axes(xlCategory, xlSecondary).MaximumScale, 0)
' Calculate number of days across x-axis to determine number of tick marks (plot width will vary so this must be set progamatically)
DaysAcross = chtObj.Chart.Axes(xlCategory, xlSecondary).MaximumScale - chtObj.Chart.Axes(xlCategory, xlSecondary).MinimumScale
If DaysAcross < 15 Then ' 1-day intervals on tick marks for < 15 day plots
TickInterval = 1
ElseIf DaysAcross > 15 And DaysAcross < 32 Then ' 2 days between tick marks for 15-32 day duration plots
TickInterval = 2
ElseIf DaysAcross > 32 And DaysAcross < 60 Then ' for 32-60 day plots set tick interval to 4 days
TickInterval = 4
Else
TickInterval = Application.WorksheetFunction.RoundUp(DaysAcross / 15, 0) ' Set tick mark interval such that it provides ~15 divisons along x-axis
End If
chtObj.Chart.Axes(xlCategory, xlSecondary).MajorUnit = TickInterval
Next Series
Bookmarks