最近刚好做这个,看大富翁离线chm和delphi的demo(Teechart)搞定。
往窗体上放Chart控件后,双击弹出对话框,可以在上面设置一系列属性,通过这个办法很多需求就实现了。
代码部分,相关的有:
with dm.qrycomm do
begin
if active then close;
sql.Text:=sqlstr;
open;
maxshow:=20;
maxcount:=recordcount;
if maxcount>maxshow then
begin
btn_showall.Enabled:=true;
if barChart.MaxPointsPerPage>0 then
begin
btn_pre.Enabled:=true;
btn_next.Enabled:=true;
end;
end;
if recordcount=0 then
begin
Panel1.Visible:=false;
end
else
Panel1.Visible:=true;
maxitem:=100;
i:=0;
Series1.Clear;
Series2.Clear;
while not eof do
begin
Series1.Add(fields.FieldByName('icount').AsInteger,fields.FieldByName('RegOperator').AsString,clteecolor);
Series2.Add(fields.FieldByName('icount').AsInteger,fields.FieldByName('RegOperator').AsString,clteecolor);
next;
i:=i+1;
if i>=maxitem then
break;
end;
end;
//Series1.Circled:=true;
if rdg_showtype.ItemIndex=0 then
begin
pieChart.Visible:=true;
barChart.Visible:=false;
end
else
begin
pieChart.Visible:=false;
barChart.Visible:=true;
end;
if rdg_position.ItemIndex=0 then
begin
pieChart.Legend.Visible:=true;
barChart.Legend.Visible:=true;
pieChart.Legend.Alignment:=TLegendAlignment(1);
barChart.Legend.Alignment:=TLegendAlignment(1);
end
else if rdg_position.ItemIndex=1 then
begin
pieChart.Legend.Visible:=true;
barChart.Legend.Visible:=true;
pieChart.Legend.Alignment:=TLegendAlignment(3);
barChart.Legend.Alignment:=TLegendAlignment(3);
end
else
begin
pieChart.Legend.Visible:=false;
barChart.Legend.Visible:=false;
end;
if cbx_3d.Checked then
begin
pieChart.View3D:=True;
barChart.View3D:=True;
end
else
begin
pieChart.View3D:=false;
barChart.View3D:=false;
end;
if cbx_hint.Checked then
begin
pieChart.SeriesList[0].Marks.Visible:=True;
barChart.SeriesList[0].Marks.Visible:=True;
end
else
begin
pieChart.SeriesList[0].Marks.Visible:=false;
barChart.SeriesList[0].Marks.Visible:=false;
end;
其中有些与chart无关代码,我用两个chart,其实还可以一个chart放两个Series。