• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 536
  • Last Modified:

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;
0
mcmahling
Asked:
mcmahling
  • 4
  • 4
1 Solution
 
JaccoCommented:
The following code seems to work for me:

procedure TForm1.Chart1ClickSeries(Sender: TCustomChart; Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Memo1.Lines.Add('********************');
  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]));
end;

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
0
 
JaccoCommented:
Oh yeah, I used Chart1.Series1.XValues.DateTime = True

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

Jacco
0
 
mcmahlingAuthor Commented:
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
JaccoCommented:
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
0
 
mcmahlingAuthor Commented:
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;
0
 
JaccoCommented:
Have you tried with

  Series1.XValues.ValueSource := 'PublicationDate'

What database type are you using?

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

Perfect.  Thanks
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now