We are using MSChart(a Microsoft control for drawing charts) control in Visual Basic for
charting purpose in our project. Our requirement is like this:
It will be a 2D line graph.
On a single chart on the X-axis I will have to show some values for the current year as well as
for the previous year. It may happen that the current data points contains values for 4months
values(i.e. values for Jan, Feb, Mar and Apr) but the previous data points always contains all
the 12 values (for 12 months).
So we will have to draw the chart like : the current
data line will show 4data points and then it will stop there and the previous data line will
show all the 12data points. We are facing a problem like: we can't stop the current link after
showing the line for 4data points rather it draws the chart for all the 12 data points (although
it has only 4defined data points to draw the chart, it just gets the rest 8data points and draws
the chart). So the current chart is wrong, we do not have any problem with the previous chart. But
we will have to stop the current chart after displaying the 4data points.
Can u pls suggest any feasible solution for the above stated problem. Thanks in advance.
Just to restrict the current chart from showing the rest 8 data points I have forcefully made
the rest 8 data points array values as 0. But it does not solve our problem as u can guess.
Pls have a look at the attached
VB code.. We get the data points from a Oracle stored procedure and
we get exactly 4 data points for current and 12 data points for previous. Pls have a look at the subroutine
'CreateChartImage' that draws the chart for us. Check on line 526 we are forcefully making the rest 8 data
values for current to 0.
Public Sub CreateChartImage(ByVal ChartNo As Integer, ByVal i_time As String, ByVal rowCount As Long, _
ByRef a_apsub() As Single, ByVal countCurrentDPLth As Integer, ByRef a_apsubp() As Single, _
ByRef a_ovaprt() As Single, ByRef a_ovaprtp() As Single, _
ByRef a_bta() As Single, ByRef a_btap() As Single, _
ByRef a_chgoff() As Single, ByRef a_chgoffp() As Single, _
ByRef a_lr() As Single, ByRef a_lrp() As Single, _
ByRef a_inp() As Single, ByRef a_inpp() As Single, _
ByRef a_inlr() As Single, ByRef a_inlrp() As Single, _
ByRef a_roma() As Single, ByRef a_romap() As Single, _
ByRef a_FMS() As Single, ByRef a_FMSp() As Single)
Dim i As Integer
Dim ArrayLength As Integer
Dim objPen As Object
i = 0
'Add a title and legend.
With frm_Chart.MsChart
If ChartNo = 1 Then
.Title.Text = "Applications Submitted"
ElseIf ChartNo = 2 Then
.Title.Text = "Overall Approval Rate "
ElseIf ChartNo = 3 Then
.Title.Text = "Booked to Approval"
ElseIf ChartNo = 4 Then
.Title.Text = "Charge Off Amount"
ElseIf ChartNo = 5 Then
.Title.Text = "Loss Rate"
ElseIf ChartNo = 6 Then
.Title.Text = "Insurance Penetration"
ElseIf ChartNo = 7 Then
.Title.Text = "Insurance In Force Loss Ratio"
ElseIf ChartNo = 8 Then
.Title.Text = "ROMA"
ElseIf ChartNo = 9 Then
.Title.Text = "Finance Market Share"
End If
.Legend.Location.LocationType = MSChart20Lib.VtChLocationType.VtChLocationTypeRigh t
.Legend.Location.Visible = True
End With
If Mid(i_time, 1, 4) <> "CQTD" And Mid(i_time, 1, 4) <> "FQTD" Then
frm_Chart.MsChart.Plot.Axis(VtChAxisIdX, 1).AxisTitle = "Months"
Else
frm_Chart.MsChart.Plot.Axis(VtChAxisIdX, 1).AxisTitle = "Quarters"
End If
' If ChartNo = 1 Then
' frm_Chart.MsChart.Plot.Axis(VtChAxisIdY, 1).AxisTitle = "Applications Submitted"
' ElseIf ChartNo = 2 Then
' frm_Chart.MsChart.Plot.Axis(VtChAxisIdY, 1).AxisTitle = "Overall Approval Rate "
' ElseIf ChartNo = 3 Then
' frm_Chart.MsChart.Plot.Axis(VtChAxisIdY, 1).AxisTitle = "Booked to Approval"
' ElseIf ChartNo = 4 Then
' frm_Chart.MsChart.Plot.Axis(VtChAxisIdY, 1).AxisTitle = "Charge Off Amount"
' ElseIf ChartNo = 5 Then
' frm_Chart.MsChart.Plot.Axis(VtChAxisIdY, 1).AxisTitle = "Loss Rate"
' ElseIf ChartNo = 6 Then
' frm_Chart.MsChart.Plot.Axis(VtChAxisIdY, 1).AxisTitle = "Insurance Penetration"
' ElseIf ChartNo = 7 Then
' frm_Chart.MsChart.Plot.Axis(VtChAxisIdY, 1).AxisTitle = "Insurance In Force Loss Ratio"
' ElseIf ChartNo = 8 Then
' frm_Chart.MsChart.Plot.Axis(VtChAxisIdY, 1).AxisTitle = "ROMA"
' ElseIf ChartNo = 9 Then
' frm_Chart.MsChart.Plot.Axis(VtChAxisIdY, 1).AxisTitle = "Finance Market Share"
' End If
With frm_Chart.MsChart
.chartType = VtChChartType2dLine
.rowCount = rowCount
.ColumnCount = 2
'restrict to only 4 values for CQTD and FQTD
If Mid(i_time, 1, 4) <> "CQTD" And Mid(i_time, 1, 4) <> "FQTD" Then
ArrayLength = 11
Else
ArrayLength = 3
End If
For i = 0 To ArrayLength
.Row = i + 1
.RowLabel = aMonths(i)
' MsgBox aMonths(i)
Next
If ChartNo = 1 Then
'Applications Submitted - Current & Previous
For i = 0 To countCurrentDPLth - 1
.Row = i + 1
.Column = 1
.Data = a_apsub(i)
' MsgBox a_apsub(i)
Next
If countCurrentDPLth <= ArrayLength Then
' For i = countCurrentDPLth To ArrayLength
' .rowCount = rowCount
' .Row = i + 1
' .Column = 1
' .Plot.SeriesCollection(1).Pen.Width = 0
' .Plot.SeriesCollection(1).DataPoints(6).Pen.VtColo r.Set 255, 255, 0
' .Data = vbNull
' Next
For i = countCurrentDPLth To ArrayLength
.Row = i + 1
.Column = 1
.Data = 0
If Mid(i_time, 1, 4) = "CYTD" Or Mid(i_time, 1, 4) <> "FYTD" Or Mid(i_time, 1, 4) = "CQTD" Or Mid(i_time, 1, 4) <> "FQTD" Then
.Plot.SeriesCollection(1).Pen.Width = 0
End If
' Set objPen = .Plot.SeriesCollection(1).Pen
' ' Set Pen attributes.
' With objPen
' .VtColor.Set 255, 255, 0
' .Width = 100
' .Style = VtPenStyleDashDot
' .Join = VtPenJoinRound
' .Cap = VtPenCapRound
' End With
Next
End If
For i = 0 To ArrayLength
.Row = i + 1
.Column = 2
.Data = a_apsubp(i)
' MsgBox a_apsubp(i)
Next
End If
End With
With frm_Chart.MsChart.Plot
.SeriesCollection(1).LegendText = "Current"
.SeriesCollection(2).LegendText = "Previous"
End With
frm_Chart.Picture1.Visible = False
Dim strDateTime As String
strDateTime = Now()
strDateTime = Replace(strDateTime, "/", "")
strDateTime = Replace(strDateTime, ":", "")
strDateTime = Replace(strDateTime, " ", "")
If ChartNo = 1 Then
g_filename = "Demochart1" & strDateTime & ".jpg"
Call Save_to_JPEG_From_Chart(pFilePath)
End If
End Sub
Thanks,
sanjib