Creating Pie Series In Code
Posted: Tue Dec 14, 2010 5:04 am
Trying to create a Pie Series connected to a TClientDataSet in code.
There are two problems I am running into.
1) The Pie chart is not flat. Instead it is on an angle like it is trying to be a 3D chart. How do I stop it from doing this?
2) When I close the form (after the chart is loaded) I get an Exception (Invalid Pointer Operation). I think that has something to do with the Series and it's parent.
I combed the examples but they all seem to be examples with the series created at design time. I need to do it at run time.
Code: Select all
procedure TMyForm.CreateChart;
var
pieSeries: TPieSeries;
i: Integer;
begin
MyChart.View3D := FALSE; //MyChart is a TeeChart On The From
Screen.Cursor := crHourglass;
try
for i:= (MyChart.SeriesCount -1) downto 0 do
MyChart.Series[i].Free;
MyChart.SeriesList.Clear;
pieSeries := TPieSeries.Create(MyChart);
pieSeries.ParentChart := MyChart;
pieSeries.DataSource := cdsChartData; //cdsChartData is The TClientDataSet with the data I want to display
pieSeries.PieValues.ValueSource := 'YearTotal'; //Field
pieSeries.XLabelsSource := 'SliceLabel'; //Labels for the different values
MyChart.SeriesList.Add(pieSeries);
MyChart.Title.Text.Clear;
MyChart.Title.Text.Add(''My Pie Series');
GetData(); //Loads the Dataset by opening it
pieSeries.CheckDataSource;
finally
Screen.Cursor := crDefault;
end;
end;
1) The Pie chart is not flat. Instead it is on an angle like it is trying to be a 3D chart. How do I stop it from doing this?
2) When I close the form (after the chart is loaded) I get an Exception (Invalid Pointer Operation). I think that has something to do with the Series and it's parent.
I combed the examples but they all seem to be examples with the series created at design time. I need to do it at run time.