Display/Explode or drill down the 'Other Slice'

TeeChart FireMonkey (Windows,OSX,iOS & Android) for Embarcadero RAD Studio, Delphi and C++ Builder (XE5+)
Post Reply
realsol
Newbie
Newbie
Posts: 70
Joined: Mon Feb 27, 2017 12:00 am

Display/Explode or drill down the 'Other Slice'

Post by realsol » Tue Jun 20, 2017 6:45 pm

I know I have asked this in the past but I can't seem to find the answer now that I am ready to code it. How do I display the 'Other Slice' items when a user clicks on it?

Thanks.

Yeray
Site Admin
Site Admin
Posts: 9509
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Display/Explode or drill down the 'Other Slice'

Post by Yeray » Wed Jun 21, 2017 9:02 am

Hello,

Here an example with a SubChart to drilldown:

Code: Select all

var pie1: TPieSeries;
    pie2: TPieSeries;
    subChartTool: TSubChartTool;
    subChart: TChart;

procedure TForm1.Chart1ClickSeries(Sender: TCustomChart; Series: TChartSeries;
  ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var i: Integer;
begin
  if ((Series = pie1) and (ValueIndex > -1) and (pie1.Labels[ValueIndex] = pie1.OtherSlice.Text)) then
  begin
    pie2.Clear;

    for i:=0 to pie1.Count-1 do
      if (pie1.XValues.Value[i] = -1) then
         pie2.AddPie(pie1.YValue[i], pie1.Labels[i], pie1.ValueColor[i]);

    subChart.Visible:=True;
  end;
end;

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
begin
  subChart.Visible:=False;
  Chart1.Repaint;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Single);
var ValueIndex: Integer;
begin
  subChartTool.Charts[0].Left:=round(X-50);
  subChartTool.Charts[0].Top:=round(Y-100);

  ValueIndex:=pie1.Clicked(X, Y);
  if (ValueIndex<0) or (pie1.Labels[ValueIndex] <> pie1.OtherSlice.Text) then
  begin
    subChart.Visible:=False;
    Chart1.Repaint;
  end;

  if subChart.Visible then
     Chart1.Repaint;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  pie1:=Chart1.AddSeries(TPieSeries) as TPieSeries;
  pie1.FillSampleValues();
  pie1.OtherSlice.Value:=10;
  pie1.OtherSlice.Style:=poBelowPercent;

  subChartTool:=Chart1.Tools.Add(TSubChartTool) as TSubChartTool;
  subChart:=subChartTool.Charts.AddChart();
  subChart.Height:=300;
  subChart.Width:=300;
  pie2:=subChart.AddSeries(TPieSeries) as TPieSeries;
  pie2.AngleSize:=180;
  pie2.RotationAngle:=270;
  subChart.Visible:=False;
end;
Project1_2017-06-21_11-01-49.png
Project1_2017-06-21_11-01-49.png (33.07 KiB) Viewed 9668 times
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply