下面的例子是通过一个ComboBox来选择TeeChar的类型:
procedure Form.SeriesClsComboBoxClick(Sender: TObject);
var
SeriesCls : TChartSeriesClass;
mySeries : TChartSeries;
i : integer;
begin
for i := Chart1.SeriesCount-1do
wnto 0do
Chart1.Series.Free;
case SeriesClsComboBox.ItemIndex of
0 : SeriesCls := TLineSeries;
1 : SeriesCls := TBarSeries;
2 : SeriesCls := THorizBarSeries;
3 : SeriesCls := TAreaSeries;
4 : SeriesCls := TPointSeries;
5 : SeriesCls := TPieSeries;
6 : SeriesCls := TFastLineSeries;
else
SeriesCls := TPieSeries;
end;
mySeries := SeriesCls.Create(self);
mySeries.ParentChart := Chart1;
mySeries.Clear;
mySeries.Marks.Visible := True;
mySeries.ColorEachPoint := True;
//下面对Series赋值
Dat.myQuery.Open;
Dat.myQuery.First;
while not Dat.myQuery.Eofdo
begin
if Dat.myQuery.FieldByName('a1').AsString = '' then
mySeries.Add(Dat.myQuery.FieldByName('a2').Value, '其他', clTeeColor)
else
mySeries.Add(Dat.myQuery.FieldByName('a2').Value, Dat.myQuery.FieldByName('a1').AsString, clTeeColor);
Dat.myQuery.Next;
end;
Dat.myQuery.Close;
end;