[LineSeries] How to insert Y values at specific X positions?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
mw-108
Newbie
Newbie
Posts: 9
Joined: Tue Mar 29, 2016 12:00 am

[LineSeries] How to insert Y values at specific X positions?

Post by mw-108 » Wed Apr 20, 2016 4:50 pm

Hello :)

I'm trying to realize an optimization for handling alot of data and adding a custom zoom.

This is the original chart, where only each 9th point is being drawn.

Image

If I zoom in ...

Image

... the following happens:

Image

Image

As you can see, the Chart draws a line from the last X value (14.000'ish) to the zoom point and adds new values to that position, simply overdrawing the previous, instead of "inserting" the values at this position.
I already followed a solution given by Narcís, but it isn't working. http://www.teechart.net/support/viewtopic.php?t=5127

Code: Select all

procedure TFrame_ElementDetails.Chart_ObservationZoom(Sender: TObject);
var
  Chart: TChart;
  i, IndexFrom, IndexTo: Cardinal;
  LineColor: TColorRec;
  S: String;
  Ls: TLineSeries;
  // ...
begin
  if not (Sender is TChart) or not Assigned(FObserver) then
    Exit;

  // ...
  Chart := TChart(Sender);
  Ls := TLineSeries(Chart.Series[0]);
  IndexFrom := Floor(Chart.BottomAxis.CalcPosPoint(Chart.Zoom.X0));
  IndexTo := Ceil(Chart.BottomAxis.CalcPosPoint(Chart.Zoom.X1));

  Chart.AutoRepaint := FALSE;
  try
    for i := IndexFrom to IndexTo do
      begin
        Data := DataList[i];
        LineColor := GetChartValueColor(Data.Values[0], Data.Sigma[4]);
        S := FormatDateTime('ddddd', Data.Timestamp) + #13#10 +
          FormatDateTime('tt', Data.Timestamp);
        TLineSeries(Chart_Observation.Series[0]).AddXY(i, Data.Values[0], S,
          LineColor);
      end;
  finally
    Chart.AutoRepaint := TRUE;
    Chart.Refresh;
  end;
end;
How can I solve this please?

mw-108
Newbie
Newbie
Posts: 9
Joined: Tue Mar 29, 2016 12:00 am

Re: [LineSeries] How to insert Y values at specific X positions?

Post by mw-108 » Thu Apr 21, 2016 9:28 am

Ok, got it solved. I had "LineSeries.XValues.Order := loNone;" Setting it to "Ls.XValues.Order := loAscending;" actually works fine. :)

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: [LineSeries] How to insert Y values at specific X positions?

Post by Yeray » Thu Apr 21, 2016 1:24 pm

Hello,

I'm glad to hear you found how to solve it! :)
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply