Page 1 of 1

TPieSeries OnClick not working

Posted: Thu Sep 27, 2012 6:41 am
by 16461991
My application charts a dataset and allows the user to choose the chart type from a list; bar, area, line and pie. They can double-click any of the series to see the data in another form. The bar, area and line charts work just fine. The pie one doesn't and it seems that the 'OnClickSeries' event doesn't fire. This 100% definitely used to work in an older version of TChart, but the current (v2112.06.120613) version does not.

I have tried setting the Series.OnClick instead (as per below code) of the Chart.OnClickSeries and it makes no difference - the procedure is never fired.

Any suggestions/solutions gratefully received.

Code snippet;

Code: Select all

// When creating the chart
for fnl := 0 to MyChart.SeriesCount-1 do
  MyChart.Series[fnl].OnClick := ChartSeriesClick;


// Series OnClick.
procedure MyForm.ChartSeriesClick(Sender: TChartSeries; ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Sender is TPieSeries then
    ClickValueVariable := Sender.ValueMarkText[ValueIndex]
  else
    ClickValueVariable := Sender.Title;
end;

Re: TPieSeries OnClick not working

Posted: Thu Sep 27, 2012 3:07 pm
by yeray
Hi,

I'm trying to reproduce this with the code below but both the Series' OnClick event and the Clicked function in the OnMouseMove event seem to work fine for me here:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  with Chart1.AddSeries(TPieSeries) as TPieSeries do
  begin
    FillSampleValues;
    OnClick:=SeriesOnClick;
  end;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  //test 1
  //Caption:=IntToStr(Chart1[0].Clicked(X,Y));
end;

procedure TForm1.SeriesOnClick(Sender: TChartSeries; ValueIndex: Integer; Button:TMouseButton;
                               Shift: TShiftState; X, Y: Integer);
begin
  //test 2
  Caption:=IntToStr(ValueIndex);
end;
Could you please arrange a simple example project we can run as-is to reproduce the problem here?
Thanks in advance.

Re: TPieSeries OnClick not working

Posted: Fri Sep 28, 2012 2:11 am
by 16461991
After cloning my code into a fresh project, I stumbled on the cause of the problem.

For TBarSeries, TAreaSeries and TLineSeries, the event OnClickBackground only fires when you click the background.

For TPieSeries, the OnClickBackground event fires all the time - overriding the OnClickSeries and the Series.OnClick.

Re: TPieSeries OnClick not working

Posted: Fri Sep 28, 2012 8:43 am
by yeray
Hi,

I think I found what really makes the difference, at least for me here: the TeeCommander.
The code I posted above behaves differently when you have or you haven't a TeeCommander on the form. Is it possible that you are using a TeeCommander too?
Having a TeeCommander on the form, when you click on the TPieSeries you can drag the clicked slice to explode it. When you've entered in this "mode", these two events (OnClickSeries and the Series.OnClick) aren't checked.
You can disable this "mode" with:

Code: Select all

  TeeCommander1.EnablePieExploding:=false;
Could you please confirm this is what is causing the problem for you?