Page 1 of 1
Display/Explode or drill down the 'Other Slice'
Posted: Tue Jun 20, 2017 6:45 pm
by 16880166
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.
Re: Display/Explode or drill down the 'Other Slice'
Posted: Wed Jun 21, 2017 9:02 am
by yeray
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 (33.07 KiB) Viewed 10836 times