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.DoClickSerie s(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(dbValu e);
dbValue2:=Series.YValues.L ocate(Seri es.YValue[ ValueIndex ]);
end;
procedure TMultiDBChart.DoClickSerie
var
dbValue: Double;
dbValue2: Double;
strValue: String;
begin
dbValue := Series.XValue[ValueIndex];
strValue := Series.XValueToText(dbValu
dbValue2:=Series.YValues.L
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
I used your code "Series.XValueToText(Serie s.XValues[ ValueIndex ]))" and "Chart1.Series1.XValues.Da teTime := 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.
I used your code "Series.XValueToText(Serie
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
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
Series1.AddXY(Trunc(Now)+1
Series1.AddXY(Trunc(Now)+2
Series1.AddXY(Trunc(Now)+3
Series1.AddXY(Trunc(Now)+4
Series1.AddXY(Trunc(Now)+5
end;
I used a TLineSeries. I think you have used antoher method to add the points?
Regards Jacco
ASKER
I am using
tmpLineSeries := TLineSeries.Create(self);
DBCharts[l].AddSeries(tmpL ineSeries) ;
With tmpLineSeries do
Begin
DataSource:= ChartQuery1;
YValues.ValueSource := 'Score';
XLabelsSource := 'PublicationDate';
XValues.DateTime := True;
Pointer.Visible := True;
tmpLineSeries := TLineSeries.Create(self);
DBCharts[l].AddSeries(tmpL
With tmpLineSeries do
Begin
DataSource:= ChartQuery1;
YValues.ValueSource := 'Score';
XLabelsSource := 'PublicationDate';
XValues.DateTime := True;
Pointer.Visible := True;
Have you tried with
Series1.XValues.ValueSourc e := 'PublicationDate'
What database type are you using?
Jacco
Series1.XValues.ValueSourc
What database type are you using?
Jacco
ASKER
Oerfect. Thanks
ASKER
I meant.
Perfect. Thanks
Perfect. Thanks
XValues[ValueIndex] returns the Double value (same as TDateTime) of the date clicked.
Jacco