Asp.net|xml Summary: Application component programming is the main aspect of C #, this article unifies the author's practical experience in the project development, through a concrete example elaborated calls the component OWC10 and uses the XML technology to draw each kind of dynamic statistics graph, the line trend chart method and the technique. Tags: c#,asp.net,.net sdk,owc10, component programming, xml,b/s mode, COM, server-side, class, attribute 1 preface
With the development of WWW, more and more information system, expert system development using browser/server (b/s) mode. Since the introduction of. NET by Microsoft (Microsoft) in March 2002, the ASP, thanks to its fast, efficient and convenient features. NET becomes the first choice of developing B/s system. It is very important and necessary to make a statistic of all kinds of useful information and generate the corresponding dynamic statistic chart. Invoke the method in the component OWC (Office Web Component) Related class, properties, you can easily achieve the drawing of various columns, graphs, map, radar, area map, pie chart, etc. Greatly improved the development efficiency. OfficeXP corresponds to the owc10,office2003 corresponding to the OWC11 version, which is actually a COM, Based on the experience summed up in the actual project development, this paper gives an example method of calling OWC10 in asp.net to realize the trend chart of drawing polyline, and expands it. 2 Function Realization development system platform is windowsxp+visualstudio.net2003+sql Server2000, development language is c#.1) System configuration You must make the following settings on the server side before calling OWC10 drawing in asp.net: (1) download OWC10 from Microsoft's website for free, address is http:// Office.microsoft.com/downloads/2002/owc10.aspx or search Interop.OWC10.dll directly from the Internet, OWC10.dll Two DLL files can also be found and installed as shared assemblies from the OfficeXP installation disk. (2) Place the Interop.OWC10.dll and OWC10.dll files found in the Bin folder in the project directory. (3) open the project file and add Interop.OWC10.dll and OWC10.dll files to the reference. Add control image to the foreground of the WebForm1.aspx and set its id=image1. (4) Install IIS (in the Windows XP Add component), set up the virtual directory. and configure the Web.config file (5) Create a database zj_new in Enterprise Manager and create the tables you need to add relevant data. In this project the database table structure is as follows:
Database name |
Zj_new |
Table name |
Testmuti |
Field name |
Field type |
Field length |
Note |
Id |
Int |
4 |
Key words |
Metalcomponent |
Char |
10 |
Metal name (eg: fe,cu,al) |
Testtime |
Float |
8 |
Test time |
Nongdu |
Float |
8 |
The concentration of metal contained |
&NBSP;2) Background code in WebForm1.aspx.cs key source code and text description as follows: Using OWC10; Very critical using system.data.sqlclient;//using system.configuration;//using system.xml; //Critical, Reference system.xmlsqlconnection myconn=new SqlConnection (configurationsettings.appsettings["ConnectionString"]); string mycommstring= "Select Testtime,nongdu from Testmuti where metalcomponent= ' Fe ';/note the x axis sorted in ascending order the DataSet ds = new DataSet (" Chart "); datatable dt=new DataTable (); SqlDataAdapter da = new SqlDataAdapter (Mycommstring, myconn); da. Fill (DS); OWC10. Chartspaceclass ochartspace = new OWC10. Chartspaceclass (); Create diagram space System.IO.StringWriter SW = New System.IO.StringWriter (); Used to write String XmlDocument xdoc = new XmlDocument (); Create XML document ds. WriteXml (SW); //Clean up Myconn.close (); da. Dispose (); xdoc.loadxml (SW. ToString ()); SW. Close (); System.Xml.XmlNodeList nodes; nodes = XDoc.ChildNodes.Item (0). ChildNodes; int ncount = nodes. Count; string[] anames = new String[ncount]; string[] atotals = new String[ncount ]; string Names=string.empty; string Totals =string.empty; int i = 0; for (i=0;i<ncount;i++) { anames[i]= nodes. Item (i). Childnodes.item (0). innertext; //Don't write the item (I-1) or else a little bit less; atotals[i]= nodes. Item (i). Childnodes.item (1). InnerText; } names= string.join ("T", Anames); totals= string.join ("T", atotals); oChartSpace.Charts.Add (0); // Set drawing space and chart format ochartspace.charts[0]. Border.color= "Blue";//Boundary color ochartspace.charts[0]. hastitle=true;//Chart title; Ochartspace.charts[0]. title.caption= "Oil Sample iron spectrum Analysis";//Chart Title description text ochartspace.haschartspacetitle=true; ochartspace.chartspacetitle.caption= "line trend chart test"; Drawing Space Title Description text ochartspace.charts[0]. Axes[0]. hastitle=true; //x Shaft ochartspace.charts[0 ]. Axes[0]. Title.caption= "Time (10 hours)"; X-Axis caption Description ochartspace.charts[0]. AXES[1]. hastitle=true; //y shaft ochartspace.charts[0]. AXES[1]. Title.caption= "is" (wear intensity);//y Axis caption Description ochartspace.charts[0]. haslegend=true; //allowed with legend Ochartspace.charts[0]. Legend.position=owc10. chartlegendpositionenum.chlegendpositionright;//set the legend position, Ochartspace.charts[0]. Plotarea.interior.color= "Wheat"; //set the fill color in a chart area block
Ochartspace.charts[0]. Type=owc10. Chartcharttypeenum.chcharttypesmoothlinemarkers; Sets the properties Ochartspace.charts[0] of the first shape in chart charts[0]. SeriesCollection.Add (0);//Add the first graphic ochartspace.charts[0 to chart one]. Seriescollection[0]. SetData (OWC10. Chartdimensionsenum.chdimseriesnames,convert.toint32 (OWC10. chartspecialdatasourcesenum.chdataliteral), "Fe")//Set the title of the first curve, Seriescollection[0] ochartspace.charts[0]. Seriescollection[0]. Interior.color= "Blue"; The color of the node used to set the first shape (blue here); Ochartspace.charts[0]. Seriescollection[0]. SetData (OWC10. Chartdimensionsenum.chdimcategories, Convert.ToInt32 (OWC10. chartspecialdatasourcesenum.chdataliteral), names); Ochartspace.charts[0]. Seriescollection[0]. SetData (OWC10. Chartdimensionsenum.chdimvalues, Convert.ToInt32 (OWC10. chartspecialdatasourcesenum.chdataliteral), totals); Ochartspace.charts[0]. Seriescollection[0]. Line.color= "green";//control the color of the lines of the line graph; Ochartspace.charts[0]. Seriescollection[0]. Marker.style=owc10. chartmarkerstyleenum.chmarkerstylediamond;//Linear Graph string sTrfullpathandname=server.mappath (System.DateTime.Now.Ticks.ToString () + ". gif"); ochartspace.exportpicture (strfullpathandname, "gif", 600, 400); Determine the length and width image1.imageurl=strfullpathandname of the frame; To lose a graphic to a control with an ID of Image1; Image1.visible =true; 3) output results as shown in (Figure I): (Figure I) 4) flexible extension will be the same, only change the following attributes (
that is, the coarse font part) can be different types of statistical graphics: Ochartspace.charts[0]. Type= OWC10. ChartChartTypeEnum.
chChartTypeColumnClustered3D; This property is output as a solid bar chart (figure II). Of course, you can also add multiple data series in the same data chart, in order to compare statistics of each data series, the process of repeating a data graph can get multiple data series diagram, very convenient. As shown in (Figure III): (figure III) 3 Summary by invoking the component OWC10 powerful drawing function, and the application XML technology, as long as changes its output attribute, may obtain the different type output graph, the flexibility is changeable, the programming is simple, the execution efficiency is high, also greatly enhances the development efficiency, overcomes in. NET Frame Work SDK does not provide related classes in the production of data graphs, in C # to draw a variety of dynamic statistics, trend chart is a troublesome disadvantage. 4 Reference documents: 1. Dan Wahlinzhu "xml-based asp.net development", Tsinghua University Press 2. Simon Robinson, "Professional C # 2nd Edition", Tsinghua University Press 3. Mulinsen "C # and ASP.net programming course", Tsinghua University Press 4. Scott Allen, "Introduction to the C # database", Tsinghua University Press