Hi, everybody!
I'm working in Visual Basic 6 (NOT for excel application). I'm quite new in this and I'm trying to plot some curves in a graph. The point is that when I plot the curve the second time, the curve for the first time is still there!!! And I don't know how to erase it. I tried with "erase" command, but it doesn't work. I thought that maybe with "mychart.clear" or something like that could work, but there is not "clear" command to do that.
Any help??
Thanks in advance.

It would depend on what 'chart' you are using....is it MSChart from the MSChart Control (MSCHRT20.ocx)?

If so did you try:

myChart.Data = 0

Let me know if that works for you :)

It would depend on what 'chart' you are using....is it MSChart from the MSChart Control (MSCHRT20.ocx)?

If so did you try:

myChart.Data = 0

Let me know if that works for you :)

Hi, Themaj and Veena!!!
The stored curves are still plotted!! :(
It doesn't work either with .data=0 or with .todefaults. Another suggestion??
Regards,
Maria.

OK Marie,

Let's backup first;

Exactly which Chart object are you using and is that object currently residing on a VB form?

If MSChart as I mentioned aboce, what 'chartType' have you set it for?

Can you post some of the code; I'll be happy to take a look and figure things out if I can see enough of it.

Cheers

Hello, again!
Thanks for the answer.
It is a MsChart, VtChChartType2dXY type. This is a bit of my code:

Public Sub PostChartCorrelation(CurSeries As Integer, counterclockwise, plotpostbands)

dim min5, min6, max5, max6 as integer
min5 = 0
min6 = 0
max5=4
max6=4

With frmCorrelation.MSChart1(counterclockwise)
.AllowDithering = False
.AllowSelections = True
.AutoIncrement = False
.AllowDynamicRotation = False
.AllowSeriesSelection = False
End With
If CurSeries = 5 Then
ReDim postChartPoints(min5 To max5, 1 To 2)
ElseIf CurSeries = 6 Then
ReDim postChartPoints(min6 To max6, 1 To 2)
end if
With frmCorrelation.MSChart1(counterclockwise)
.chartType = VtChChartType2dXY
.ShowLegend = True
.Data = 0
With .Plot.Axis(VtChAxisIdY).AxisTitle
.VtFont.Size = 10
.Visible = True
.Text = "Speed(RPM), Current (A)"
End With
.....
.....
.....

Like you see, I tried with ".data=0" but it still doesn't work.
Do you know where is the mistake??
Thanks.

Marie,

I'm not a big fan of MSChart because it's not well documented or supported; I prefer creating a grid in a PictureBox because you can control so much more (my opinion).

You may want to consider this especially if your chart is a simple X~Y Grid.

On your issue, I don't have enough code to actually produce the chart before I even try to clear.
You may need to send me more, PM if you want.

I've haven't given up :-/

Hi Themaj and Veena!!!
I found the error!!! It had nothing to do what I was asking you. It was another type of error,
but thank you very much!!! I really apreciate it.
Regards,
Maria.

Marie,

Glad to hear you solved the problem.

Perhaps it would be of interest to many of us if you told us the solution; you never know when we might need a little bit more info.

That's part of what these forums are all about.

Keep punching those keys,

maj

Yes, sure!!!
Well, I don't know exactly why it works with the last modification that I did. But the problem was in this line of code:

.rowcount = hcOldRowCount&

The point is that when I runned the program, it started counting the row. In the first run hcOldRowCount& stored a number, and so, in the second run (the second time I was trying to plot the curves) it started counting from that number instead from zero. So I change this and I put hcOldRowCount&=0 everytime I wanna plot a chart, and it works!!!

Now the new code will be this:

Dim xvar, xvar2 As Single
Dim count As Single
Dim tend As Single
Dim xvalue1, xvalue2, xvalue3 As Single
Dim yvalue1, yvalue2, yvalue3 As Single
Dim cy, sy, pout, pin, eff, vmotor As Single
Dim x1, k1, x2, k2, x3, k3 As Single
Dim slb, slm, sly, shy, shm, chm, chb, chy As Single
Dim min10, min11 As Integer
Dim max10, max11As Integer
Dim YS As Double
Dim alpha As Double
Dim tgalpha As Double
Dim alpharound As Double
Dim pi As Double

Dim i As Integer

For i = 10 To 11
CurSeries = i

counterclockwise = 0
min10 = 0
min11 = 0
max10 = 4
max11 = 4
If counterclockwise = 0 Then
If ini0 = True Then
hcOldRowCount& = 0
End If
End If

With frmchart.MSChart1(counterclockwise)
.AllowDithering = False
.AllowSelections = True
.AutoIncrement = False
.AllowDynamicRotation = False
.AllowSeriesSelection = False
End With

If CurSeries = 10 Then
ReDim prechartpoints(min10 To max10, 1 To 2)
ElseIf CurSeries = 11 Then
ReDim prechartpoints(min11 To max11, 1 To 2)
End If

With frmchart.MSChart1(counterclockwise)
.chartType = VtChChartType2dXY
.ShowLegend = True
'.Data = 0

With .Plot.Axis(VtChAxisIdY).AxisTitle
.VtFont.Size = 10
.Visible = True
.Text = "Speed(RPM), Current (A)"
End With
With .Plot.Axis(VtChAxisIdX).AxisTitle
.VtFont.Size = 10
.Visible = True
.Text = "Torque (Nm)"
End With
.Title.VtFont.Size = 12
If counterclockwise = 0 Then
.Title = "Clock Wise"
Else
.Title = "Counter-Clock Wise"
End If
With .Title.VtFont
.Name = "Arial"
.Style = VtFontStyleBold
.Effect = VtFontEffectUnderline
.Size = 14
.VtColor.Set 0, 128, 64
End With
.Legend.Location.LocationType = VtChLocationTypeBottom
.Plot.Axis(VtChAxisIdY).AxisScale.Type = VtChScaleTypeLinear
.Plot.Axis(VtChAxisIdX).AxisScale.Type = VtChScaleTypeLinear
.Plot.UniformAxis = False

End With

Dim val1, val2 As Single
Dim m, n As Single

If CurSeries = 10 Then
If counterclockwise = 0 Then
'(lp1torquenm, lp1speed) for CW
prechartpoints(1, 1) = 2.85
prechartpoints(1, 2) = 70.66
'(lp2torquenm, lp2speed) for CW
prechartpoints(2, 1) = 4.64
prechartpoints(2, 2) = 45.12
'(lp3torquenm, lp3speed) for CW
prechartpoints(3, 1) = 7.52
prechartpoints(3, 2) = 20.83
'(stalltorquenm, stallspeed) for CW
prechartpoints(4, 1) = 8.37
prechartpoints(4, 2) = 0
End If
' Post Run In Current (Clock Wise)
ElseIf CurSeries = 11 Then
If counterclockwise = 0 Then
'(lp1torquenm, lp1current) for CW
prechartpoints(1, 1) = 2.85
prechartpoints(1, 2) = 9.17
'(lp2torquenm, lp2current) for CW
prechartpoints(2, 1) = 4.64
prechartpoints(2, 2) = 14.55
'(lp3torquenm, lp3current) for CW
prechartpoints(3, 1) = 7.52
prechartpoints(3, 2) = 19.95
'(stalltorquenm, stallcurrent) for CW
prechartpoints(4, 1) = 8.37
prechartpoints(4, 2) = 23.67
End If
End If

frmchart.MSChart1(counterclockwise).ColumnCount = CurSeries * 2

With frmchart.MSChart1(counterclockwise)
With .Plot
.Wall.Brush.Style = VtBrushStyleNull '= VtBrushStyleSolid
.Wall.Brush.FillColor.Set 255, 255, 225
If CurSeries = 10 Then 'post speed
.SeriesCollection(1).Pen.Style = VtPenStyleSolid
.SeriesCollection(1).Pen.VtColor.Set 64, 128, 128
ElseIf CurSeries = 11 Then 'post current
.SeriesCollection(21).Pen.Style = VtPenStyleSolid
.SeriesCollection(3).Pen.VtColor.Set 10, 10, 230
End If
End With
Dim A As Single
.RowCount = hcOldRowCount&
A = .RowCount

.ColumnLabelCount = CurSeries * 2

If UBound(prechartpoints, 1) > hcOldRowCount& Then
.RowCount = UBound(prechartpoints, 1)
End If

If CurSeries <> 0 Then
.Plot.SeriesCollection(CurSeries * 2 - 1).SeriesMarker.Auto = False
.Plot.SeriesCollection(CurSeries * 2 - 1).DataPoints(-1).Marker.Size = 50
.Plot.SeriesCollection(CurSeries * 2 - 1).DataPoints(-1).Marker.Visible = True
End If


If CurSeries <> 0 Then
For hclrow = 1 To UBound(prechartpoints, 1)
If (prechartpoints(1, 1) = 0 And prechartpoints(1, 2) = 0) Or prechartpoints(hclrow, 1) <> 0 Or prechartpoints(hclrow, 2) <> 0 Then
.DataGrid.SetData hclrow, CurSeries * 2 - 1, prechartpoints(hclrow, 1), False
.DataGrid.SetData hclrow, CurSeries * 2, prechartpoints(hclrow, 2), False
End If
Next

For hclrow2 = hclrow To hcOldRowCount&
.DataGrid.SetData hclrow2, CurSeries * 2 - 1, 0, True
.DataGrid.SetData hclrow2, CurSeries * 2, 0, True
Next
'Remove null points from *prior* series, if this series
'has *more* points than the prior ones:
If CurSeries > 1 Then
For hclrow = hcOldRowCount& + 1 To .RowCount
For hclrow2 = 1 To CurSeries - 1
.DataGrid.SetData hclrow, hclrow2 * 2 - 1, 0, True
.DataGrid.SetData hclrow, hclrow2 * 2, 0, True
Next
Next
End If

'Store the current RowCount
hcOldRowCount& = .RowCount

.Column = CurSeries * 2 - 1
Select Case CurSeries
Case 10
.ColumnLabel = "Pre Run-In Speed"
Case 11
.ColumnLabel = "Pre Run-In Current"
End Select

End If
.Refresh
A = .RowCount
End With

Next
If counterclockwise = 0 Then
ini0 = False
End If

frmchart.Show
frm_prepostbuttoms.Show
End Sub


Note: I modified the code a little bit, because original is very long.

Hi everybody,
I just wanted to write a quick post. Maybe it's interesting for someone.
I found how to erase a chart. It's very simple and it works!! This is the code:

Dim a() As Double
ReDim a(0, 0)
MSChart.ChartData = a

Hope this helps.
mariegomez84

This article has been dead for over six months. Start a new discussion instead.