Delphi 生成excel中饼图的实例代码
<div class="codetitle"><span><U>复制代码</U></span> 代码如下:</div><div class="codebody" id="code32050"><BR>var<BR> i,j,m,n,count1:integer;<BR> str:string;<BR> Jdate:tdatetime;<BR> channellist,potBstrtime,potEstrtime,Jchannelname:string;<BR> Rres:boolean;<BR> JSHR:double;<BR> Excelid,achart1,cell1,cell2,cell3,cell4,cellMiddle,Range1,Range2,series1:variant;<BR> ExRowsValue,ExRowsName,ExClos:Integer;<BR> ImagePage,dataPage:integer;<BR> leftPostion,topPostion,widthPostion,heightPostion:integer;<BR>begin<BR> //创建OLE对象<BR> try<BR> Excelid:=CreateOleObject( 'Excel.Application' );<BR> except<BR> on Exception do raise exception.Create('无法创建Xls文件,请确认是否安装EXCEL')<BR> end;<BR> Excelid.Visible := false; //Excel显示设置<BR> Excelid.WorkBooks.Add; //生成新的excel文件<BR> //不用excel以前的页<BR> Excelid.worksheets.add;<BR> dataPage:=Excelid.Worksheets.count; //用作数据页<BR> Excelid.worksheets.add;<BR> ImagePage:=Excelid.Worksheets.count;<BR> //showmessage(inttostr(dataPage));<BR> //showmessage(inttostr(ImagePage)+'sdfg');<BR> Jdate:=DateTimePicker1.Date;<BR> count1:=0;<BR> ExRowsValue:=1; //存储值<BR> ExRowsName:=2; //存储名称<BR> //取得频率编号<BR> for i:=0 to CheckListBoxFQ.Items.Count-1 do<BR> begin<BR> if CheckListBoxFQ.Checked then<BR> begin<BR> channellist:= QCaky.FChannelList+','+channellist;<BR> end;<BR> end;<BR> delete(channellist,length(channellist),1);<BR> leftPostion:=20;<BR> topPostion:=50;<BR> widthPostion:=450;<BR> heightPostion:=230;<BR> for i:=0 to CheckListBoxPOTT.Items.Count-1 do<BR> begin<BR> if CheckListBoxPOTT.Checked then<BR> begin<BR> //动态生成excel页数<BR> //Excelid.worksheets.add;<BR> //sheetCount:=sheetCount+1;<BR> //Excelid.worksheets.name:='图表页'+inttostr(sheetCount);<BR> //在这里生成图表<BR> if CheckListBoxPOTT.Items='全天' then<BR> begin<BR> potBstrtime:='';<BR> potEstrtime:='';<BR> end<BR> else<BR> begin<BR> potBstrtime:=QCaky.FPOTbeginList;<BR> potEstrtime:=QCaky.FPOTendList;<BR> end;<BR> Rres:=QCaky.getFQShr(Jdate,FormMain.QAreacode,channellist,potBstrtime,potEstrtime); //取得占有率<BR> ExClos:=1;<BR> while not QCaky.FADOQueryFQ.Eof do<BR> begin<BR> Excelid.worksheets.Activate;<BR> Jchannelname:=QCaky.FADOQueryFQ.fieldbyname('channelname').AsString;<BR> JSHR:=QCaky.FADOQueryFQ.fieldbyname('allshr').AsFloat;<BR> Excelid.worksheets.Cells.Value :=Jchannelname;<BR> Excelid.worksheets.Cells.Value :=JSHR;<BR> inc(ExClos);<BR> QCaky.FADOQueryFQ.Next;<BR> end;<BR> {添加一个二维图(20,50,450,230)表示(左,顶,宽,高)}<BR> //achart1 := Excelid.worksheets.chartobjects.add(20,50,450,230);<BR> achart1 := Excelid.worksheets.chartobjects.add(leftPostion,topPostion,widthPostion,heightPostion);<BR> achart1.chart.charttype := xl3DPie ; //生成何种类型的图********在此生成的是饼图<BR> //设置x轴、y轴数据<BR> cell1 := Excelid.worksheets.Cells;<BR> cell2 := Excelid.worksheets.Cells;<BR> cell3 := Excelid.worksheets.Cells;<BR> cell4 := Excelid.worksheets.Cells;<BR> Range1 := Excelid.worksheets.Range; //设定Chart类别坐标轴(x轴)的取值区域<BR> Range2 := Excelid.worksheets.Range; //设定Chart数值坐标轴(y轴)的取值区域<BR> series1:= achart1.chart.seriescollection ;<BR> //series1.add (Range2,xlColumns,false); //设置y轴的数据<BR> series1.add (Range2,true); //可以使用,能够生成饼图<BR> achart1.chart.seriescollection.name:='nihao';<BR> //设置饼图的形式<BR> achart1.chart.seriescollection.ApplyDataLabels(xlDataLabelsShowLabelAndPercent,true,true,true);<BR> achart1.Chart.Axes.CategoryNames := Range1; //设置x轴数据<BR> //series1.add (Range2,xlColumns,false); //设置y轴的数据<BR> //achart1.Chart.Axes.CategoryNames := Range1; //设置x轴数据<BR> //删除右侧的标题<BR> achart1.Chart.Legend.delete;<BR> //添加图表标题<BR> achart1.Chart.HasTitle:=True;<BR> achart1.Chart.ChartTitle.Characters.Text:='收视率走势图';<BR> achart1.Chart.HasLegend:=true;<BR> achart1.Chart.Legend.Position := xlBottom;<BR> //图表左标说明<BR> //achart1.Chart.Axes(xlValue,xlPrimary).HasTitle := True;<BR> //achart1.Chart.Axes(xlValue,xlPrimary).AxisTitle.Characters.Text := '收视率(%)';<BR> //图表下标说明<BR> //achart1.Chart.Axes(xlCategory,xlPrimary).HasTitle:=True;<BR> //achart1.Chart.Axes(xlCategory,xlPrimary).AxisTitle.Characters.Text:='时间';<BR> ExRowsName:=ExRowsName+2;<BR> ExRowsValue:=ExRowsValue+2;<BR> end; //如果时段设置被选中<BR> leftPostion:=20;<BR> topPostion:=topPostion+600;<BR> //showmessage(inttostr(dataPage));<BR> end;<BR> Excelid.Visible := true;<BR>end;<BR></div><div class="art_xg">
<b>您可能感兴趣的文章:</b><ul><li>python开发的小球完全弹性碰撞游戏代码</li><li>Delphi实现毫秒级别的倒计时实例代码</li><li>截取指定符号之间的字符串(随机读取)delphi实例代码</li><li>C# 调用Delphi dll 实例代码</li><li>Delphi修改操作注册表权限的代码</li><li>DELPHI7.0 获取硬盘、CPU、网卡序列号的代码</li><li>C#定义并实现单链表实例解析</li></ul>
</div>
</div>
<!--endmain-->
頁:
[1]