Does anyone know how to copy the XValues from one TChartSeries to another in Delphi7 (and TeeCha开发者_Python百科rt 4.04)? TChartSeries.ReplaceList(CopySeries.XValues, OriginalSeries.XValues)
does not work, since it seem to replace the reference, so when OriginalSeries is changed, so is CopySeries. The length of CopySeries is equal or greater than OriginalSeries. I want to preserve the CopySeries.YValues.
My workaround has been to create a temporary list
Dummy := TChartSeries.Create(nil);
Dummy.AssignValues(OriginalSeries);
CopySeries.ReplaceList(CopySeries.XValues, Dummy.XValues);
Dummy.YValues.Destroy;
but I get a memory leakage since I cannot Destroy the Dummy since that also removes the Dummy.XValues referenced by CopySeries.XValues.
Any help is greatly appreciated.
I can think of two options:
Assigning ValueList arrays directly to the series as in the Real-time Charting article, for example:
uses Series; procedure TForm1.FormCreate(Sender: TObject); begin Chart1.AddSeries(TLineSeries.Create(Self)).FillSampleValues; Chart1.AddSeries(TLineSeries.Create(Self)); { set our X array } Chart1[1].XValues.Value:=Chart1[0].XValues.Value; { <-- the array } Chart1[1].XValues.Count:=Chart1[0].Count; { <-- number of points } Chart1[1].XValues.Modified:=True; { <-- recalculate min and max } { set our Y array } Chart1[1].YValues.Value:=Chart1[0].YValues.Value; Chart1[1].YValues.Count:=Chart1[0].Count; Chart1[1].YValues.Modified:=True; { Show data } Chart1.Series[1].Repaint; end;
Clone series:
uses Series; procedure TForm1.FormCreate(Sender: TObject); begin Chart1.AddSeries(TLineSeries.Create(Self)).FillSampleValues; Chart1.AddSeries(CloneChartSeries(Chart1[0])); end;
If you are using TeeChart 4.04 you'll probably have to address series like Chart1.Series[0] instead of Chart1[0] as in the Repaint call in the first example. Alternatively you could try something like this:
uses Series, Math; procedure TForm1.FormCreate(Sender: TObject); var i, MinNumValues, MaxNumValues: Integer; begin Chart1.AddSeries(TLineSeries.Create(Self)).FillSampleValues(15); Chart1.AddSeries(TLineSeries.Create(Self)).FillSampleValues(25); MinNumValues:=Min(Chart1.Series[0].Count, Chart1.Series[1].Count); MaxNumValues:=Max(Chart1.Series[0].Count, Chart1.Series[1].Count); for i:=0 to MinNumValues -1 do Chart1.Series[1].XValue[i]:=Chart1.Series[0].XValue[i]; for i:=MinNumValues to MaxNumValues-1 do Chart1.Series[1].ValueColor[i] := clNone; end;
精彩评论