Asp.net| Statistics
1, first download OWC11 COM components
http://www.microsoft.com/downloads/details.aspx?FamilyID=7287252c-402e-4f72-97a5-e0fd290d4b76&displaylang=en
2, Registered OWC11
Add a components\11 reference under the C:\Program Files\Common Files\Microsoft Shared\Web Owc11.dll file in the project
3, in the project to add
Using OWC11;
4, the beginning coding examples are as follows:
public class Chartfactory
{
Public chartfactory ()
{
Inittypemap ();
//TODO: Add constructor logic here
//
}
protected System.Web.UI.WebControls.Image imghondalineup;
Private string[] Chartcategoriesarr;
Private string[] Chartvaluesarr;
Private OWC11. ChartChartTypeEnum ChartType = OWC11. chartcharttypeenum.chcharttypecolumn3d;//default
private static Hashtable Chartmap = new Hashtable ();
private static string Charttypech = "vertical bar chart";
private static string charttitle = ";
private void Inittypemap ()
{
Chartmap.clear ();
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 statistic graph, ' 3D vertical Column chart ", horizontal column chart", "3D Horizontal Column Chart", "Regional statistics Chart", "3D Regional Statistics Chart", "Hollow pie chart", "Line statistics chart", "3D Line Statistics Chart", "line with point statistics", "pie chart", "3D pie chart", "Mesh Statistics", "ARC Statistics"};
for (int i=0;i<charttypes.length;i++)
{
Chartmap.add (Charttypesch[i],charttypes[i]);
}
}
Public Chartspaceclass Buildcharts ()
{
String chartcategoriesstr = String.Join ("T", Chartcategoriesarr);
String chartvaluesstr = String.Join ("T", Chartvaluesarr);
OWC11. Chartspaceclass ochartspace = new OWC11. Chartspaceclass ();
// ------------------------------------------------------------------------
Give pie and doughnut charts a legend on the bottom. For the rest of
them let the control figure it in its own.
// ------------------------------------------------------------------------
ChartType = (chartcharttypeenum) Chartmap[charttypech];
if (ChartType = = Chartcharttypeenum.chcharttypepie | |
ChartType = = Chartcharttypeenum.chcharttypepie3d | |
ChartType = = chartcharttypeenum.chcharttypedoughnut)
{
Ochartspace.haschartspacelegend = true;
OChartSpace.ChartSpaceLegend.Position = Chartlegendpositionenum.chlegendpositionbottom;
}
OChartSpace.Border.Color = "Blue";
OCHARTSPACE.CHARTS.ADD (0);
Ochartspace.charts[0]. HasTitle = true;
Ochartspace.charts[0]. Type = ChartType;
Ochartspace.charts[0]. Chartdepth = 125;
Ochartspace.charts[0]. Aspectratio = 80;
Ochartspace.charts[0]. Title.caption = ChartTitle;
Ochartspace.charts[0]. Title.Font.Bold = true;
Ochartspace.charts[0]. SeriesCollection.Add (0);
Ochartspace.charts[0]. Seriescollection[0]. Datalabelscollection.add ();
// ------------------------------------------------------------------------
If you ' re charting a pie or a variation thereof percentages make a lot
More sense than values ...
// ------------------------------------------------------------------------
if (ChartType = = Chartcharttypeenum.chcharttypepie | |
ChartType = = Chartcharttypeenum.chcharttypepie3d | |
ChartType = = chartcharttypeenum.chcharttypedoughnut)
{
Ochartspace.charts[0]. Seriescollection[0]. Datalabelscollection[0]. Haspercentage = true;
Ochartspace.charts[0]. Seriescollection[0]. Datalabelscollection[0]. HasValue = false;
}
// ------------------------------------------------------------------------
Not so for the other chart types where values have more meaning than
Percentages.
// ------------------------------------------------------------------------
Else
{
Ochartspace.charts[0]. Seriescollection[0]. Datalabelscollection[0]. Haspercentage = false;
Ochartspace.charts[0]. Seriescollection[0]. Datalabelscollection[0]. HasValue = true;
}
// ------------------------------------------------------------------------
Plug your own visual bells and whistles here
// ------------------------------------------------------------------------
Ochartspace.charts[0]. Seriescollection[0]. Caption = String.Empty;
Ochartspace.charts[0]. Seriescollection[0]. Datalabelscollection[0]. Font.Name = "Verdana";
Ochartspace.charts[0]. Seriescollection[0]. Datalabelscollection[0]. Font.Size = 10;
Ochartspace.charts[0]. Seriescollection[0]. Datalabelscollection[0]. Font.Bold = true;
Ochartspace.charts[0]. Seriescollection[0]. Datalabelscollection[0]. Font.Color = "Red";
Ochartspace.charts[0]. Seriescollection[0]. Datalabelscollection[0]. Position = Chartdatalabelpositionenum.chlabelpositioncenter;
if (ChartType = = Chartcharttypeenum.chcharttypebarclustered | |
ChartType = = Chartcharttypeenum.chcharttypebar3d | |
ChartType = = Chartcharttypeenum.chcharttypecolumnclustered | |
ChartType = = chartcharttypeenum.chcharttypecolumn3d)
{
Ochartspace.charts[0]. Seriescollection[0]. Datalabelscollection[0]. Position = Chartdatalabelpositionenum.chlabelpositionoutsideend;
}
Ochartspace.charts[0]. Seriescollection[0]. SetData (OWC11. Chartdimensionsenum.chdimcategories,
Convert.ToInt32 (OWC11. chartspecialdatasourcesenum.chdataliteral), CHARTCATEGORIESSTR);
Ochartspace.charts[0]. Seriescollection[0]. SetData (OWC11. Chartdimensionsenum.chdimvalues,
Convert.ToInt32 (OWC11. chartspecialdatasourcesenum.chdataliteral), CHARTVALUESSTR);
return ochartspace;
}
#region Property settings
Public string[] Chartcategoriesarrvalue
{
Get
{
return Chartcategoriesarr;
}
Set
{
Chartcategoriesarr = value;
}
}
Public string[] Chartvaluesarrvalue
{
Get
{
return Chartvaluesarr;
}
Set
{
Chartvaluesarr = value;
}
}
public string Charttypevalue
{
Get
{
return Charttypech;
}
Set
{
Charttypech = value;
}
}
public string Charttitlevalue
{
Get
{
return charttitle;
}
Set
{
ChartTitle = value;
}
}
#endregion
}
Call first need to place an image on the page to display the resulting statistics
public void Showchart ()
{
Initialize Assignment
Chartfactory.chartcategoriesarrvalue = chartcategories;
Chartfactory.chartvaluesarrvalue = chartvalues;
Chartfactory.charttitlevalue = ChartTitle;
Chartfactory.charttypevalue = ChartType;
OWC11. Chartspaceclass ochartspace = Chartfactory.buildcharts ();
String path = Server.MapPath (".") + @ "\images\chart.jpeg"; Create a picture and save the page can be a PNG gif picture
Ochartspace.exportpicture (Path, "JPEG", 745, 500);
Image1.imageurl = path; Show Statistics Chart
}
Save Statistics Chart Please refer to the previous article
Because each generated statistical map will overwrite the original picture, so it is necessary to use the date plus time as the name of the picture, but this will produce a lot of pictures to be processed in time, if you do not need to take the same name to overwrite the original picture can be.