Getting the Point X and Y axis value

I have a Delphi 2005 VCL application where I am creating DBCharts at runtime.  I need to know the values of the point the use clicks on the series in the chart.  For example, my series has dates on the X axis and numbers on the Y axis.  So I would like to know that a user has clicked on the point (1/1/2005, 5) where 1/1/2005 is the X axis value and 5 is the Y axis value of the point.  I am using the code below but all I am getting is the numerical value of the index and not the actual value of the point.  Such that point (1/1/2005, 5) is the 3rd point displayed, I am getting the index value of 2 and not 1/1/2005 or 5.  Can someone help?

procedure TMultiDBChart.DoClickSeries(Sender: TCustomChart; Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; x, y: Integer);
dbValue: Double;
dbValue2: Double;
strValue: String;
dbValue := Series.XValue[ValueIndex];
strValue := Series.XValueToText(dbValue);

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The following code seems to work for me:

procedure TForm1.Chart1ClickSeries(Sender: TCustomChart; Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  Memo1.Lines.Add(IntToStr(X) + '-' + IntToStr(Y));
  Memo1.Lines.Add('ToText: ' + Series.XValueToText(Series.XValues[ValueIndex]));
  Memo1.Lines.Add('ToText: ' + Series.YValueToText(Series.YValues[ValueIndex]));

The only quirk is that the ValueIndex passed is not the closest point to where the user clicks but always the closest point to the left of where the user clicks.

Regards Jacco

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Oh yeah, I used Chart1.Series1.XValues.DateTime = True

XValues[ValueIndex] returns the Double value (same as TDateTime) of the date clicked.

mcmahlingAuthor Commented:

I used your code "Series.XValueToText(Series.XValues[ValueIndex]))" and   "Chart1.Series1.XValues.DateTime := True". The Y value is being assigned but the X value keeps coming up the Date 12/31/1899.  Can you suggest something else I might be doing wrong?  When I tried just getting the double value using the code dbValue := Series.XValue[ValueIndex], I get 0.
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Hi there,

Maybe this helps. This is the code I used to fill the Series with some values:

procedure TForm1.FormCreate(Sender: TObject);
  Series1.AddXY(Trunc(Now)+0, 20);
  Series1.AddXY(Trunc(Now)+1, 40);
  Series1.AddXY(Trunc(Now)+2, 30);
  Series1.AddXY(Trunc(Now)+3, 20);
  Series1.AddXY(Trunc(Now)+4, 40);
  Series1.AddXY(Trunc(Now)+5, 30);


I used a TLineSeries. I think you have used antoher method to add the points?

Regards Jacco
mcmahlingAuthor Commented:
I am using

tmpLineSeries := TLineSeries.Create(self);
  With tmpLineSeries do
  DataSource:= ChartQuery1;
  YValues.ValueSource := 'Score';
  XLabelsSource := 'PublicationDate';
  XValues.DateTime := True;
  Pointer.Visible := True;
Have you tried with

  Series1.XValues.ValueSource := 'PublicationDate'

What database type are you using?

mcmahlingAuthor Commented:
Oerfect.  Thanks
mcmahlingAuthor Commented:
I meant.

Perfect.  Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.