I need the possibility to copy series from one chart to another. I tried it first with the series clone method but this did not work sufficiently. So I did it bythis code:
Code: Select all
Public Overridable Sub CopySeries(ByVal Src As Series, ByVal SrcChart As TChart, ByVal DestChart As TChart, ByVal CopyDataPoints As Boolean)
Try
'MyMainForm1.CopiedSeries is a buffer for some copy/paste actions
If MyMainForm1.CopiedSeries IsNot Nothing Then MyMainForm1.CopiedSeries.Dispose()
If TypeOf Src Is FastLine Then MyMainForm1.CopiedSeries = New Steema.TeeChart.Styles.FastLine()
If TypeOf Src Is Line Then MyMainForm1.CopiedSeries = New Steema.TeeChart.Styles.Line()
If TypeOf Src Is Points Then MyMainForm1.CopiedSeries = New Steema.TeeChart.Styles.Points()
If CopyDataPoints Then
MyMainForm1.CopiedSeries.AssignValues(Src)
MyMainForm1.CopiedSeries.Assign(Src)
MyMainForm1.CopiedSeries.AssignFormat(Src)
MyMainForm1.CopiedSeries.Tag = Src.Tag
MyMainForm1.CopiedSeries.Title = MyMainForm1.CopiedSeries.Title
End If
If TypeOf Src Is Line Then
'This was necessary since for line series the data point properties were not copied - a bug, I assume...
Dim Line1 As Line = MyMainForm1.CopiedSeries
Dim Line2 As Line = Src
Line1.Pointer = Line2.Pointer
End If
If DestChart IsNot Nothing Then
DestChart.Series.Add(MyMainForm1.CopiedSeries)
MyMainForm1.CopiedSeries = Nothing
End If
Catch ex As Exception
MsgBox("CopySeries: " + Chr(13) + ex.Message)
End Try
The problem is with the following lines:
Code: Select all
'concrete example: Src has 111 data points
'Before executing one of the following lines
'MyMainForm1.CopiedSeries.YValues.Value() has the length of 111
MyMainForm1.CopiedSeries.AssignValues(Src)
MyMainForm1.CopiedSeries.Assign(Src)
'Now MyMainForm1.CopiedSeries.YValues.Value() has the length of 126
'MyMainForm1.CopiedSeries.YValues.count is still 111
Code: Select all
Dim XValues As Vector
Dim YValues As Vector
YValues.CopyFromArray(SourceChart.Series(cbSeries.SelectedIndex).YValues.Value)
XValues.CopyFromArray(SourceChart.Series(cbSeries.SelectedIndex).XValues.Value)
That implies that accessing the data points as array (of double, for instance) is impossible since one can not trust that the values() property always returns the true data points...
Best regards
Uli