贴一段我自己的程序,动态改变形状,希望对你有帮助!
要改变的chart为sourcechart,deschart只是一个中间变量!
//改变chart的形状
procedure ChangeSeries(SourceChart:TDBChart;DesChart:TDBChart;SeriesType:String);//改变图表形状
var
i,j:integer;
Series:TchartSeries;
begin
if SourceChart.Series[0].ClassName=SeriesType then
exit;
if DesChart=nil then
DesChart:=TDBChart.Create(nil);
if SeriesType='TPieSeries' then
DesChart.Assign(SourceChart);
if desChart=nil then
DesChart.Assign(SourceChart);
if SourceChart.Series[0].ClassName='TPieSeries' then
SourceChart.Assign(DesChart);
for i:=0 to SourceChart.SeriesCount-1do
begin
if SeriesType='TPieSeries' then
Series:=TPieSeries.Create(nil)
else
if SeriesType='TBarSeries' then
series:=TBarSeries.Create(nil)
else
if SeriesType='TFastLineSeries' then
Series:=TFastLineSeries.Create(nil)
else
Exit;
//Series.AssignValues(SourceChart.Series[0]);
//Series.DataSource:=SourceChart.Series[0].DataSource;
Series.Assign(SourceChart.Series[0]);
{
for j:=0 to Series.Count-1do
begin
Series.XLabel[j]:=SourceChart.Series[0].XLabel[j];
end;
}
Series.Active :=SourceChart.Series[0].Active;
SourceChart.RemoveSeries(SourceChart.Series[0]);
SourceChart.AddSeries(Series);
end;