Q: how to plot a Horizontal line in a Line Chart?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
NoName
Newbie
Newbie
Posts: 34
Joined: Fri Nov 15, 2002 12:00 am
Location: Italy

Q: how to plot a Horizontal line in a Line Chart?

Post by NoName » Tue Nov 25, 2003 11:12 am

Hello,

I have a LineSeries chart, used to display quotation values.

I want to draw a horizontal line tangent the highest and lowest values visible in the chart.

My problem is I don't know where the MaxValue or MinValue has been drawn on the chart (in other words, the Y-coordinate), in order to draw a line at that coordinate.

Regards

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Tue Nov 25, 2003 4:05 pm

Hi!

You could use the following approach:

1) Cycle through all visible points and determine the index of minimum and maximum point. Pseudo-code you can use:

Code: Select all

for i := Series.FirstVisibleIndex to Series.LastVisibleInde x do
 if Series.YValues[i] > current_max then maxindex := i ;
 if Series.YValues[i] < current_min then minindex := i;
2) Now that you have minimum and maximum point indices, you can use series CalcYPos method to get the maximum and minimum point y pixel coordinate.

3) Finally, use calculated screen position to draw horizontal line. Pseudo-code, placed in TChart.OnAfterDraw event:

Code: Select all

With Chart1, Chart1.Canvas do 
begin
  MoveTo(ChartRect.Left,calculated_y_pos);
  LineTo(ChartRect.Right,calculated_y_pos);
end;

NoName
Newbie
Newbie
Posts: 34
Joined: Fri Nov 15, 2002 12:00 am
Location: Italy

Post by NoName » Tue Nov 25, 2003 4:57 pm

you can use series CalcYPos method
CalcYPos, that's the key I was missing!

Thank you

NoName
Newbie
Newbie
Posts: 34
Joined: Fri Nov 15, 2002 12:00 am
Location: Italy

Post by NoName » Fri Nov 28, 2003 9:18 am

Hello,
I reuse this topic for another problem.

I want to draw a horizontal line, on my TLineSeries chart, at certain Y value.
I obtained the screen coordinates using TChartSeries.CalcYPosValue.

I'd like drawing a line using SmallDots style, which I found only in TChartPen class (derived from TPen).

Where TChartPen is used? Chart objects have the standard Canvas property, which contains the standard Pen.
How can I draw a line using TChartPen, in a chart?

Regards

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Sun Nov 30, 2003 8:42 pm

How about using the ColorLine tool ?
I think it does all that you're looking for. You can see one example example of it in the TeeChart Pro Demo Features under : All Features -> Welcome ! -> Tools -> Color Line

Josep Lluis Jorge
http://support.steema.com

Post Reply