Recently to do a project, according to customer needs, need to generate some reports, OWC is a more appropriate component.
1. How to install OWC components
OWC is the abbreviation for Office Web compents, the Microsoft Office Web Component, which contains spreadsheet components, chart components, piotable components, and data source components.
As long as you have Office Office software installed, there will be an installation file in C:\Program Files\msecache\owc11_12: Owc11.msi (offic 2003)
2, after installation, create a new project, and then add references ...-->com--> Microsoft Office WEB Components 11.0 in the Bin folder: Interop.OWC10.dll
Reference space: Using Microsoft.Office.Interop.Owc11;
private void Makelinechart ()
{
Y axis
String[] Dataname = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
Data for the first curve
Int[] Data = {0, 10, 20, 100, 40, 50, 60};
Data for the second curve
Int[] Data1 = {100, 50, 41, 86};
Data for the third curve
Int[] Data2 = {10, 50, 100, 30, 50, 60};
String strValue1 = "";
string strvalue = "";
String strValue2 = "";
String strcateory = "";
Loop to get data and format it in OWC10 format (plus ' \ t ')
for (int i = 0; i < dataname.length; i++)
{
Strcateory + = Dataname[i] + ' t ';
}
for (int i = 0; i < data.length; i++)
{
strvalue + = Data[i]. ToString () + ' \ t ';
}
for (int i = 0; i < data1.length; i++)
{
StrValue1 + = Data1[i]. ToString () + ' \ t ';
}
for (int i = 0; i < data2.length; i++)
{
StrValue2 + = Data2[i]. ToString () + ' \ t ';
}
OWC10. Chartspaceclass mySpace = new OWC10. Chartspaceclass ()///Create ChartSpace object to place chart
OWC10. ChChart MyChart = mySpace.Charts.Add (0);//Add chart in ChartSpace object, Add method return chart Object
Mychart.type = OWC10. chartcharttypeenum.chcharttypecolumnclustered;//Specifies the type of chart as a linear graph
Mychart.haslegend = true;//Specify whether the chart requires a legend
Mychart.hastitle = true;//given title
MyChart.Title.Caption = "Trading graph"; Chart name
Illustrated illustration of a given x\y axis
Mychart.axes[0]. HasTitle = true;
Mychart.axes[0]. title.caption = "Quantity"; Horizontal name
MYCHART.AXES[1]. HasTitle = true;
MYCHART.AXES[1]. Title.caption = "date"; Vertical axis Name
Add a series (sequence)
MYCHART.SERIESCOLLECTION.ADD (0);
Given the name of the series
Mychart.seriescollection[0]. SetData (OWC10. Chartdimensionsenum.chdimseriesnames, (int) OWC10. Chartspecialdatasourcesenum.chdataliteral, "buy");
The classification of a given series
Mychart.seriescollection[0]. SetData (OWC10. Chartdimensionsenum.chdimcategories, (int) OWC10. Chartspecialdatasourcesenum.chdataliteral, strcateory);
Given a specific value
Mychart.seriescollection[0]. SetData (OWC10. Chartdimensionsenum.chdimvalues, (int) OWC10. Chartspecialdatasourcesenum.chdataliteral, strvalue);
Add a series
MYCHART.SERIESCOLLECTION.ADD (1);
Given the name of the series
MYCHART.SERIESCOLLECTION[1]. SetData (OWC10. Chartdimensionsenum.chdimseriesnames, (int) OWC10. Chartspecialdatasourcesenum.chdataliteral, "sell");
The classification of a given series
MYCHART.SERIESCOLLECTION[1]. SetData (OWC10. Chartdimensionsenum.chdimcategories, (int) OWC10. Chartspecialdatasourcesenum.chdataliteral, strcateory);
Given a specific value
MYCHART.SERIESCOLLECTION[1]. SetData (OWC10. Chartdimensionsenum.chdimvalues, (int) OWC10. Chartspecialdatasourcesenum.chdataliteral, strValue1);
Add a series
MYCHART.SERIESCOLLECTION.ADD (2);
Given the name of the series
MYCHART.SERIESCOLLECTION[2]. SetData (OWC10. Chartdimensionsenum.chdimseriesnames, (int) OWC10. Chartspecialdatasourcesenum.chdataliteral, "total deal");
The classification of a given series
MYCHART.SERIESCOLLECTION[2]. SetData (OWC10. Chartdimensionsenum.chdimcategories, (int) OWC10. Chartspecialdatasourcesenum.chdataliteral, strcateory);
Given a specific value
MYCHART.SERIESCOLLECTION[2]. SetData (OWC10. Chartdimensionsenum.chdimvalues, (int) OWC10. Chartspecialdatasourcesenum.chdataliteral, strValue2);
Output as GIF file
String Strabsolutepath = (Server.MapPath (".")) + @ "\images\tempchart.gif";
Response.Write (Strabsolutepath);
Myspace.exportpicture (Strabsolutepath, "GIF", 300, 300); Output chart
Create a relative path to a GIF file
String Strrelativepath = "Images/tempchart.gif";
Add a picture to image
Image1.imageurl = Strrelativepath;
}
Chart Type Enumeration
OWC11. chartcharttypeenum[] Charttypes = new OWC11. chartcharttypeenum[]{
Chartcharttypeenum.chcharttypecolumnclustered,
Chartcharttypeenum.chcharttypecolumn3d,
Chartcharttypeenum.chcharttypebarclustered,
Chartcharttypeenum.chcharttypebar3d,
Chartcharttypeenum.chcharttypearea,
Chartcharttypeenum.chcharttypearea3d,
Chartcharttypeenum.chcharttypedoughnut,
Chartcharttypeenum.chcharttypelinestacked,
Chartcharttypeenum.chcharttypeline3d,
Chartcharttypeenum.chcharttypelinemarkers,
Chartcharttypeenum.chcharttypepie,
Chartcharttypeenum.chcharttypepie3d,
Chartcharttypeenum.chcharttyperadarsmoothline,
Chartcharttypeenum.chcharttypesmoothline};
string[] Charttypesch = new string[] {"Vertical column chart", "3D Vertical Column Chart", "Horizontal Column chart", "3D Horizontal column statistics
Charts, regional statistics, 3D area statistics, "Hollow Pie", "line chart", "3D Line chart", "line with DOT statistics", "pie chart", "3D pie chart", "Mesh statistics
Diagram "," ARC statistics diagram "};