-
MsChart
I am busy using a mschrt20.ocx control.
Everything is working perfectly accept plotting on my x-axis.
I only want to plot on the x-axis if it is the beginning of a new month.
The problem that I am experiencing is that you can only specify the devisions per label once.
I need to do it per beginning of month.
ie. Jan has 31 days and Feb only 28 days thus resulting in my chart and x-axis not lining up.
I attached the code that I am using.
If any could help I would realy appriciate it.
[Private Sub Form_Load()
On Error GoTo Error
PopTwoArray MSChart1, CDate(dDateTo), CDate(dDateFrom)
twoColChart MSChart1, "Company", "Optional Company", "Testing The MsCrt20.ocx"
Error:
End Sub/]
[Public Function GetMonths(iMonth As Integer) As String
Select Case iMonth
Case 1, 6, 7
GetMonths = "J"
Case 2
GetMonths = "F"
Case 3, 5
GetMonths = "M"
Case 4, 8
GetMonths = "A"
Case 9
GetMonths = "S"
Case 10
GetMonths = "O"
Case 11
GetMonths = "N"
Case 12
GetMonths = "D"
End Select
End Function/]
[Public Sub PopTwoArray(chrtGraph As MSChart, dMaxDate As Date, dMinDate As Date)
Dim xaxis As Object
Dim i As Integer
Dim j As Integer
Dim s As Integer
iRow = DaysDiff(CDate(dMaxDate), CDate(dMinDate))
ReDim arrClose(1 To iRow, 1 To 3)
j = 1
For i = 1 To iRow
arrClose(i, 1) = GetMonths(Month(CDate(dMinDate))) & DatePart("yyyy", CDate(dMinDate))
arrClose(i, 2) = Format(120 * Rnd, "##.##")
arrClose(i, 3) = Format(120 * Rnd, "##.##")
dMinDate = AddDays(1, CDate(dMinDate))
If isLastDayofMonth(CDate(dMinDate - 1)) Then
chrtGraph.Plot.Axis(VtChAxisIdX, j).CategoryScale.DivisionsPerLabel = DaysInMonth(CLng(Month(dMinDate)), CLng(Year(dMinDate)))
chrtGraph.Plot.Axis(VtChAxisIdX, j).CategoryScale.DivisionsPerTick = DaysInMonth(CLng(dMinDate), CLng(dMinDate))
j = j + 1
End If
Next i
End Sub/]
[Public Sub twoColChart(chrtGraph As MSChart, str1 As String, str2 As String, str3 As String)
Dim i As Integer
With chrtGraph
.chartType = VtChChartType2dLine
.ChartData = arrClose
.RowCount = iRow
.ColumnCount = 2
.Column = 1
.ColumnLabel = str1
.Column = 2
.ColumnLabel = str2
.Title = str3
.Legend.Location.LocationType = VtChLocationTypeTop
.Footnote.Location.LocationType = VtChLocationTypeBottom
.FootnoteText = "Period From " & dDateFrom & " To " & dDateTo
End With
ReDim arrClose(0, 0)
End Sub/]
[Public Function isLastDayofMonth(ByVal dtDate As Date) As Boolean
dtDate = dtDate + 1
If Day(dtDate) = 1 Then
isLastDayofMonth = True
Else
isLastDayofMonth = False
End If
End Function/]