Recent

Author Topic: Lines in different places on the chart.  (Read 1940 times)

Seenkao

  • Hero Member
  • *****
  • Posts: 610
    • New ZenGL.
Lines in different places on the chart.
« on: February 07, 2023, 06:19:06 am »
Могу ли я с помощью TChart "нарисовать" линии в разных местах графика? Линии не должны соединяться. Линии могут быть построены произвольно.

Google translate:
Can I use TChart to "draw" lines in different places on the chart? The lines must not connect. Lines can be drawn arbitrarily.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: Lines in different places on the chart.
« Reply #1 on: February 07, 2023, 03:55:42 pm »
Sorry I don't understand... Could you try to draw a sketch of what the chart should look like and post the image here?

Nicole

  • Hero Member
  • *****
  • Posts: 1009
Re: Lines in different places on the chart.
« Reply #2 on: February 07, 2023, 06:10:45 pm »
Quite certain "yes".
Check the DEMO-folder of TAChart.

Have a glance at "userdrawn" although I thought, that there must be another one much better.

Seenkao

  • Hero Member
  • *****
  • Posts: 610
    • New ZenGL.
Re: Lines in different places on the chart.
« Reply #3 on: February 08, 2023, 04:19:47 am »
nan-demo показывает как можно сделать что-то подобное.

Google translate:
nan-demo shows how you can do something similar.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: Lines in different places on the chart.
« Reply #4 on: February 08, 2023, 06:26:15 pm »
One possibility to connect pairs of points with lines in TAChart is the use the TFieldSeries. It was originally intended to draw a field of vectors to illustrate, for example, the flow direction and velocity of a streaming liquid or gas. But since it consisits of two (x,y) pairs per datapoint, it can be used for your purpose.

The method to add data points (here: lines) to this series is AddVector which gets two (x,y) pairs as arguments. Note, however, that they are not the start and end points of the line, but the center point and the direction vector. You can calculate the center of the connectionline between two points P1 and P2 as (P1 + P2) * 0.5, and the direction vector is P2 - P1. When you add unit TAGeometry to the "uses" clause of your form, these expressions really can be calculated exactly like this because TAGeometry implements overloaded simple arithmetic operators for the TDoublePoint type (otherwise you would have to calculate the X and Y coordinates separately, eg. center.X := (P1.X + P2.X) * 0.5; center.Y := (P1.Y + P2.Y) * 0.5).

Code: Pascal  [Select][+][-]
  1. { Adds a line to the series which connects the points P1 and P2. The line
  2.   is drawn in the specified color. }
  3. procedure TForm1.AddLine(ASeries: TFieldSeries; P1, P2: TDoublePoint; AColor: TColor);
  4. var
  5.   center: TDoublePoint;
  6.   direction: TDoublePoint;
  7. begin
  8.   center := (P1 + P2) * 0.5;
  9.   direction := P2 - P1;
  10.   ASeries.AddVector(center.X, center.Y, direction.X, direction.Y, '', AColor);
  11. end;

You should also turn off the Arrow of the FieldSeries which otherwise would show up at the endpoint.

Study the attached demo project.

Seenkao

  • Hero Member
  • *****
  • Posts: 610
    • New ZenGL.
Re: Lines in different places on the chart.
« Reply #5 on: February 09, 2023, 07:56:01 am »
wp, это как раз то, что я искал! И мне нужны были стрелки.  ;) Благодарю!

Google translate:
wp, this is exactly what I was looking for! And I needed arrows. ;) Thank you!
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

 

TinyPortal © 2005-2018