Link to home
Start Free TrialLog in
Avatar of mcmahling
mcmahling

asked on

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);
var
dbValue: Double;
dbValue2: Double;
strValue: String;
begin
dbValue := Series.XValue[ValueIndex];
strValue := Series.XValueToText(dbValue);
dbValue2:=Series.YValues.Locate(Series.YValue[ValueIndex]);

end;
ASKER CERTIFIED SOLUTION
Avatar of Jacco
Jacco
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh yeah, I used Chart1.Series1.XValues.DateTime = True

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

Jacco
Avatar of mcmahling
mcmahling

ASKER

Thanks.

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.
Hi there,

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

procedure TForm1.FormCreate(Sender: TObject);
begin
//
  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);

end;

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

Regards Jacco
I am using

tmpLineSeries := TLineSeries.Create(self);
  DBCharts[l].AddSeries(tmpLineSeries);
  With tmpLineSeries do
  Begin
  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?

Jacco
Oerfect.  Thanks
I meant.

Perfect.  Thanks