Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TChart Marks Positions problem



Permlink Replies: 4 - Last Post: Jun 27, 2016 10:17 PM Last Post By: Gord Pollock
Gord Pollock

Posts: 34
Registered: 12/13/03
TChart Marks Positions problem
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 16, 2016 9:12 PM
I am have a problem moving the mark on a line series point using C++
Builder XE7 and the standard version of TChart. When porting the
program over from 2006 to XE7, the marks cover the top half of the
pointer. I want to move them up and to the left a bit. I am trying to
follow the example in the Steema website (after converting to C++), but
keep getting an Access Violation exception.

In the form show function:
{
Series1->Pointer->Visible = true;
Series1->Pointer->Style = psCircle;
Series1->Pointer->Brush->Color = clWhite;

Series1->Marks->Visible = true;
Series1->Marks->BackColor = clWhite;
}

In the function where the data gets plotted as it is calculated:
{
Series1->AddXY(Xdata,Ydata,"mark label",clWhite);
int nbrPoints = Series1->Count();

Series1->Marks->Positions->Position[nbrPoints -1]->Custom = true; //
Exception here
TSeriesMarkPosition *MarkToMove ;
MarkToMove = Series1->Marks->Positions->Position[nbrPoints -1];
Series1->Marks->Positions->MoveTo(MarkToMove , MarkToMove->LeftTop.X-5,
MarkToMove->LeftTop.Y-50);
}

For some reason, Series1->Marks->Positions->Position[nbrPoints -1] is
always NULL.

What I am doing wrong?

Yeray Alonso

Posts: 75
Registered: 6/12/11
Re: TChart Marks Positions problem
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 17, 2016 12:56 AM   in response to: Gord Pollock in response to: Gord Pollock
Hello Gord,

Gord Pollock wrote:
In the function where the data gets plotted as it is calculated:
{
Series1->AddXY(Xdata,Ydata,"mark label",clWhite);
int nbrPoints = Series1->Count();

Series1->Marks->Positions->Position[nbrPoints -1]->Custom = true; //

Note here you are adding a point to a series; but you aren't drawing it before accessing the Positions.

Gord Pollock wrote:
For some reason, Series1->Marks->Positions->Position[nbrPoints -1] is
always NULL.

What I am doing wrong?

You should force a repaint before accessing the Positions because this array is populated internally when the chart is drawn.
To force a repaint:

  Chart1->Draw();


--
Best Regards

Yeray Alonso
Steema Support Central
Follow us in Twitter and Facebook

"Important note: If you are a TeeChart registered customer,
please post your support questions at Steema's Support
monitored Forums for a prompter reply."
http://support.steema.com
Gord Pollock

Posts: 34
Registered: 12/13/03
Re: TChart Marks Positions problem [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 17, 2016 11:06 PM   in response to: Yeray Alonso in response to: Yeray Alonso
On 17/06/2016 1:56 AM, Yeray Alonso wrote:
You should force a repaint before accessing the Positions because this array is populated internally when the chart is drawn.
To force a repaint:

  Chart1->Draw();

Okay, thanks. Getting closer, but still some strange things happening.
I had thought that the 2nd and 3rd terms in the MoveTo call were the
new coordinates of the LeftTop in pixels. But I am getting some odd
behavior. It moved the mark way more than numbers I was adding on to
LeftTop.X and LeftTop.Y. Even when I added 1 to them, it jumped way
more than one pixel.

So then I tried not adding anything to the coordinates. I thought this
command would leave the mark in its current place.
But the mark still moved. Doesn't make any sense to me.
Series1->Marks->Positions->MoveTo(MarkToMove ,
MarkToMove->LeftTop.X , MarkToMove->LeftTop.Y);
// nothing added to X or Y and still the mark moves

Anyway I went at it a different way (probably the correct way) by using
the mark callout length:
Series1->Marks->Callout->Length = 5;
It moved above the pointer enough that you can see the pointer now. I
would have liked to have moved it left a bit, but this will suffice.
Yeray Alonso

Posts: 75
Registered: 6/12/11
Re: TChart Marks Positions problem [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 20, 2016 1:31 AM   in response to: Gord Pollock in response to: Gord Pollock
Gord Pollock wrote:
Anyway I went at it a different way (probably the correct way) by using
the mark callout length:
Series1->Marks->Callout->Length = 5;
It moved above the pointer enough that you can see the pointer now. I
would have liked to have moved it left a bit, but this will suffice.

That way is fine if you only want to increase the distance between the mark and the point.

If you wanted to completely control the position of the marks, you should play with the Positions array, as you were doing at the beginning. However, I would calculate the new position relative to the position of the point instead of relative to the old mark position. And a good place to do this calculation would be at OnBeforeDrawSeries. Ie:

void __fastcall TForm1::Chart1BeforeDrawSeries(TObject *Sender)
{
  for (int i = 0; i < Series1->Marks->Positions->Count; i++) {
	Series1->Marks->Positions->Position[i]->Custom = true;
	TSeriesMarkPosition *MarkToMove ;
	MarkToMove = Series1->Marks->Positions->Position[i];
	Series1->Marks->Positions->MoveTo(MarkToMove, Series1->CalcXPos(i)-10, Series1->CalcYPos(i)-10);
  }
}


--
Best Regards

Yeray Alonso
Steema Support Central
Follow us in Twitter and Facebook

"Important note: If you are a TeeChart registered customer,
please post your support questions at Steema's Support
monitored Forums for a prompter reply."
http://support.steema.com
Gord Pollock

Posts: 34
Registered: 12/13/03
Re: TChart Marks Positions problem [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 27, 2016 10:17 PM   in response to: Yeray Alonso in response to: Yeray Alonso
On 20/06/2016 2:31 AM, Yeray Alonso wrote:
If you wanted to completely control the position of the marks, you should play with the Positions array, as you were doing at the beginning. However, I would calculate the new position relative to the position of the point instead of relative to the old mark position. And a good place to do this calculation would be at OnBeforeDrawSeries. Ie:

void __fastcall TForm1::Chart1BeforeDrawSeries(TObject *Sender)
{
  for (int i = 0; i < Series1->Marks->Positions->Count; i++) {
	Series1->Marks->Positions->Position[i]->Custom = true;
	TSeriesMarkPosition *MarkToMove ;
	MarkToMove = Series1->Marks->Positions->Position[i];
	Series1->Marks->Positions->MoveTo(MarkToMove, Series1->CalcXPos(i)-10, Series1->CalcYPos(i)-10);
  }
}

Sorry, I was away for a bit. Thanks for the post, I will check it out.

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02