Page 1 of 1

Get values from chart when clicked

Posted: Tue Apr 12, 2005 11:08 pm
by 9339722
We are using Delphi 7.1, TeeChart 7 for the development.

We have many charts in the application and lately client wants us to implement a feature where they can click on the chart and that inturn will display a form or a hint which displays Label and Values and much more information about the state of few more variables in the application which is not a part of the chart.

Now when I have a chart displayed via program then I can click on Edit button for the chart which brings up an editing box. Now I got to "Tools" tab and click on Add button which brings up Chart Tools Gallery dialog box.

Select Mark Tip and press OK. Then select the "Series", "Label and Value", "Either click or mouse over" and "Delay"

Press OK on the main dialog box and then move the mouse on the chart or click on the point or a line connecting 2 points and it will display the label and values of axis as a tool tip.

I want to do the similar kind of thing but want to add more information to the tool tip which is displayed.

So my plan was to have some code in Chart's click event which finds if the point or the line was clicked and then get the values and pass those values back to the program with an event so the program can display a tool tip or format the values the way we want and display it differently.

If anyone has a small code sample to detect if the point or line was clicked and what were the Label and Value of each axis then I would apreciate it. I can manage the event part once I have all the values.

Cheers,

Nirav

P.S. : I would attach some images to explain more but there is no way to upload an image on this forum but I will try to upload it on a site and so it can be viewed.

Posted: Tue Apr 12, 2005 11:14 pm
by 9339722
OK I have uploaded 4 images which if you open one by one, will give you an idea of what I am talking about.

However I couldn't take a screen shot with a tool tip displaying "Label and Value" but you get the idea.

Here are the links.

http://www.patel.com.au/1.jpg
http://www.patel.com.au/2.jpg
http://www.patel.com.au/3.jpg
http://www.patel.com.au/4.jpg

Cheers

Posted: Wed Apr 13, 2005 9:35 am
by narcis
Hi Nirav,

You can use the MarkTipsTool's OnGetText event to customize the text the tool will display.

Posted: Thu Apr 14, 2005 9:01 pm
by 9339722
Thank you Narcis,

Actually I was wondering if it is possible to extract the values without using MarkTip..?

Cheers

Posted: Thu Apr 14, 2005 11:50 pm
by Pep
Hi,

yes, you can get the values using the OnClick event of the Series which return the Series and the ValueIndex which has been clicked :
procedure TForm1.Series1Click(Sender: TChartSeries; ValueIndex: Integer;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

With this info you can get the values using :
x:=Series1.XValue[ValueIndex];
y:=Series1.YValue[ValueIndex];