0

Hope this is clear...

I want to know if the PaintBox control can allow the user to scroll, left to right through data? Imagine it like an oscilloscope display where a single capture allows zooming and scrolling. In this case I do not need zooming. So, my Paintbox is 800x600 and my data set is 16000x600.

I can plot in the 800x600 region as shown below, no problems at all, and can apply scaling to get all the data in, but I want to keep the Y-axis scaled to 1 and be able to scroll/drag left/right and view the data.

    for J := 1 to ((Form1.Memo1.Lines.count)-1) do
    begin
      MyTorques[J] := StrToInt(Form1.Memo1.Lines[J]);
      Tqmult := ((StrToInt(Label6.Caption) + 500) Div 600);
      Ycalc[J] := ((MyTorques[J]) Div Tqmult);
      InvY[J] := (600 - (Ycalc[J]));
      X1 := (J-1);
      Y1 := InvY[J-1];
      X2 := (J);
      Y2 := InvY[J];
        with PaintBox1.Canvas do
        begin
          pen.Style := psSolid;
          pen.Color := clBlack;
          pen.Width := 1;
          moveto(X1, Y1);
          Lineto(X2, Y2);
          Label51.Caption := IntToStr(X1);
          Label52.Caption := IntToStr(Y1);
          Label28.Caption := IntToStr(X2);
          Label29.Caption := IntToStr(Y2);
          Label35.Caption := IntToStr(Tqmult);
          Label37.Caption := IntToStr(Ycalc[J]);
          Label39.Caption := IntToStr(InvY[J]);
          Label41.Caption := IntToStr(MyTorques[J]);
        end;
      if MyTorques[J] < Smallest Then
      Begin
        Smallest := MyTorques[J];
        SmallestIndex := J;
      end;
      if MyTorques[J] > Largest Then
      begin
        Largest := MyTorques[J];
        LargestIndex := J;
      end;
      Label30.Caption := IntToStr(Smallest);
      Label31.Caption := IntToStr(SmallestIndex);
      Label32.Caption := IntToStr(Largest);
      Label33.Caption := IntToStr(LargestIndex);
    end;

So, does my paintbox.canvas need to be sized 16000x600 with a "window" over the top sized 800x600, and the paintbox control is drag-able with vertical and horizontal constraints?

  • Add a scrollbar and use its position to calculate the visible window over the full data set. Far easier would be to use a charting library. – David Heffernan Apr 24 '19 at 05:50
  • 1
    Have you considered using the TChart component, that ships with Delphi? – Delphi Coder Apr 24 '19 at 12:24
  • Is TChart a component in the palette? I don't have one (searched for chart) but is that a result of using the community edition of Delphi? – Andrew Pratt Apr 24 '19 at 15:23
  • Yes, it is, in `TeeChart Std`, at least here in my Delphi 10.2.3 Tokyo Professional. Should also be included in 10.3 Rio CE. AFIK, the Community Edition is the same as the Professional Edition, it just uses another license. Maybe you just did not install TChart component? – Delphi Coder Apr 24 '19 at 16:26
  • Did a reinstall and it's an option during the process. Going to give it a try, thank you Delphi Coder. – Andrew Pratt Apr 24 '19 at 18:05

1 Answers1

1

PaintBox by default does not have any scrolling support built in.

So if you want to have scrolling capabilities you will have to place your PaintBox into some other scrollable control like ScrollBox and set size of your PaintBox large enoought to contain rendering of your entire plot.

But this is a bad practice. Why? Doing so you will spend a lot of time painting your plot even thou only a part of it is visible to user at one time.

Instead you should be thinking of painting just part of your plot that can actually be visible by your user at the sima time (fits into PaintBox) and then redraw the plot when user scrolls to different position on a plot.

SilverWarior
  • 7,372
  • 2
  • 16
  • 22