0

I got some values that i need to draw as a vertical line. The line should be from begin till the end of diagramm field.

I use VCLTee.Chart.hpp in Embarcadero. As I know it is the Tchart, that is actually used more for Delphi.

However:

I use this function:

DlgMainWindow->ChartTemperatureCurve->Canvas->DoVertLine(XValue,YValue,ZValue);

i can´t find the description. As I see DoVertLine works with Pixel of the diagramm. But if my YValue = 10 , and should be always parallel to x for whole distance.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Lama Dingo
  • 123
  • 1
  • 11

1 Answers1

2

You should convert your YValue from axis values to pixels with the axis CalcPosValue function.

If you want to draw a line at a constant YValue, it would be an horizontal line, not a vertical line.

In the following example I'm drawing an horizontal line at YValue=10.
Note the drawing functions should be called at OnAfterDraw event or similar to make sure your custom drawings are done after every repaint.

To use OnAfterDraw event on RAD Studio, select the chart at design-time, navigate to the Events tab at the Object Inspector and double-click on the white cell next to OnAfterDraw.
This action should open the code view with the cursor inside a new and empty OnAfterDraw function.
Then you can add what you want to do there. Ie, drawing an horizontal line within the ChartRect, at YValue=10:

void __fastcall TForm1::Chart1AfterDraw(TObject *Sender)
{
  Chart1->Canvas->Pen->Color = clRed;

  int X0Pos = Chart1->ChartRect.Left;
  int X1Pos = X0Pos + Chart1->ChartRect.Width();
  double YVal = 10;
  int YPos = Chart1->Axes->Left->CalcPosValue(YVal);

  Chart1->Canvas->DoHorizLine(X0Pos, X1Pos, YPos);
}
Yeray
  • 5,009
  • 1
  • 13
  • 25
  • yeah sry , actually i meant horizontal, but my head is empty – Lama Dingo Aug 27 '15 at 09:59
  • Using it in a thread, i put your function in synchronize. There is a dynamic curve and this horizontal. it draws once and than disappear. what could be the reason? – Lama Dingo Aug 27 '15 at 10:03
  • Note custom drawing functions must be called at OnAfterDraw or similar; inside an event that is being called after each repaint. Otherwise the next repaint will overwrite what you've manually drawn. – Yeray Aug 27 '15 at 10:06
  • I've edited the answer explaining you how to use OnAfterDraw event – Yeray Aug 28 '15 at 07:25