Delphi generates an instance code for a pie chart in Excel _delphi

Source: Internet
Author: User
Copy Code code as follows:

Var
I,j,m,n,count1:integer;
str:string;
Jdate:tdatetime;
channellist,potbstrtime,potestrtime,jchannelname:string;
Rres:boolean;
jshr:double;
Excelid,achart1,cell1,cell2,cell3,cell4,cellmiddle,range1,range2,series1:variant;
Exrowsvalue,exrowsname,exclos:integer;
Imagepage,datapage:integer;
Leftpostion,toppostion,widthpostion,heightpostion:integer;
Begin
Creating an OLE Object
Try
Excelid:=createoleobject (' Excel.Application ');
Except
On Exception do raise Exception. Create (' Unable to create XLS file, please verify that Excel ' is installed)
End
Excelid.visible: = false; Excel display Settings
EXCELID.WORKBOOKS.ADD; To generate a new Excel file
No previous pages in Excel
Excelid.worksheets.add;
Datapage:=excelid.worksheets.count; Use as a data page
Excelid.worksheets.add;
Imagepage:=excelid.worksheets.count;
ShowMessage (IntToStr (dataPage));
ShowMessage (IntToStr (imagepage) + ' SDFG ');
Jdate:=datetimepicker1.date;
count1:=0;
Exrowsvalue:=1; Store values
exrowsname:=2; Store Name
Get frequency number
For i:=0 to Checklistboxfq.items.count-1 do
Begin
If Checklistboxfq.checked[i] Then
Begin
channellist:= qcaky.fchannellist[i]+ ', ' +channellist;
End
End
Delete (Channellist,length (channellist), 1);
leftpostion:=20;
toppostion:=50;
widthpostion:=450;
heightpostion:=230;
For i:=0 to Checklistboxpott.items.count-1 do
Begin
If Checklistboxpott.checked[i] Then
Begin
Dynamically Generate Excel Pages
Excelid.worksheets.add;
sheetcount:=sheetcount+1;
Excelid.worksheets[sheetcount].name:= ' Chart page ' +inttostr (sheetcount);
Generate a chart here
If checklistboxpott.items[i]= ' all day ' then
Begin
Potbstrtime:= ';
Potestrtime:= ';
End
Else
Begin
Potbstrtime:=qcaky.fpotbeginlist[i];
Potestrtime:=qcaky.fpotendlist[i];
End
RRES:=QCAKY.GETFQSHR (Jdate,formmain.qareacode,channellist,potbstrtime,potestrtime); Gain Share
Exclos:=1;
While does QCaky.FADOQueryFQ.Eof do
Begin
Excelid.worksheets[datapage]. Activate;
Jchannelname:=qcaky.fadoqueryfq.fieldbyname (' ChannelName '). asstring;
Jshr:=qcaky.fadoqueryfq.fieldbyname (' Allshr '). Asfloat;
Excelid.worksheets[datapage]. Cells[exrowsname,exclos]. Value: =jchannelname;
Excelid.worksheets[datapage]. Cells[exrowsvalue,exclos]. Value: =JSHR;
Inc (Exclos);
QCaky.FADOQueryFQ.Next;
End
{Add a two-dimensional graph (20,50,450,230) representation (left, top, wide, high)}
Achart1: = Excelid.worksheets[imagepage].chartobjects.add (20,50,450,230);
Achart1: = Excelid.worksheets[imagepage].chartobjects.add (leftpostion,toppostion,widthpostion,heightpostion);
Achart1.chart.charttype: = xl3DPie; What type of graph ******** generate this is a pie chart
Set x axis, Y axis data
CELL1: = Excelid.worksheets[datapage]. CELLS[EXROWSNAME,1];
CELL2: = Excelid.worksheets[datapage]. Cells[exrowsname,exclos];
Cell3: = Excelid.worksheets[datapage]. CELLS[EXROWSVALUE,1];
CELL4: = Excelid.worksheets[datapage]. Cells[exrowsvalue,exclos];
Range1: = Excelid.worksheets[datapage]. RANGE[CELL1, Cell2]; Set the range of values for the chart category axis (x axis)
Range2: = Excelid.worksheets[datapage]. Range[cell3, CELL4]; Set the value area of the chart value axis (Y axis)
Series1:= achart1.chart.seriescollection;
Series1.add (Range2,xlcolumns,false); Set data for y-axis
Series1.add (range2,true); can be used to generate pie charts
achart1.chart.seriescollection[1].name:= ' Nihao ';
Set the form of a pie chart
ACHART1.CHART.SERIESCOLLECTION[1]. ApplyDataLabels (xldatalabelsshowlabelandpercent,true,true,true);
Achart1. Chart.axes[xlcategory].  CategoryNames: = Range1; Set X-axis data
Series1.add (Range2,xlcolumns,false); Set data for y-axis
Achart1. Chart.axes[xlcategory].  CategoryNames: = Range1; Set X-axis data
Remove title to right
Achart1. Chart.Legend.delete;
Add Chart Title
Achart1. Chart.hastitle:=true;
Achart1. Chart.charttitle.characters.text:= ' ratings trend Chart ';
Achart1. Chart.haslegend:=true;
Achart1. Chart.Legend.Position: = Xlbottom;
Chart Left label description
Achart1. Chart.axes (xlvalue,xlprimary). HasTitle: = True;
Achart1. Chart.axes (xlvalue,xlprimary). AxisTitle.Characters.Text: = ' Rating (%) ';
Chart Subscript Description
Achart1. Chart.axes (xlcategory,xlprimary). Hastitle:=true;
Achart1. Chart.axes (xlcategory,xlprimary). axistitle.characters.text:= ' time ';
exrowsname:=exrowsname+2;
exrowsvalue:=exrowsvalue+2;
End If the time period setting is selected
leftpostion:=20;
toppostion:=toppostion+600;
ShowMessage (IntToStr (dataPage));
End
Excelid.visible: = true;
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.