Using OWC to draw statistical charts in asp.net

Source: Internet
Author: User
Asp.net| Statistics | Charts in Web development using asp.net, it is often necessary to graphically display a variety of statistical data. If it's just a histogram, it can be represented by drawing a table or by using a certain color GIF to shrink the degree of relaxation and height, and many voting programs use this method more. However, it is difficult to ask for a pie chart or a continuous wave diagram. This article introduces you to the easy way to draw a statistical chart using the OWC graphical component.

OWC (Microsoft Office Web components) is a data-bound ActiveX control used by Microsoft Office to add charting functionality to your Web pages. OWC supports most two-dimensional charts in Microsoft Excel 2000, such as line charts, column charts, stock charts, and polar charts (such as Pie and radar charts), and support combination charts, such as two axis-column charts, data tables are published with the chart, and the chart changes as the data changes. OWC can be processed as a standard GIF output and downloaded to the browser to display.

First, the data collection is read out using Adodb.recordset and data binding with the OWC component:

Dim Owcchartspace as OWC. ChartSpace = New OWC. ChartSpace ()
Dim Owcchart as OWC. WCChart = OwcChartSpace.Charts.Add
Dim Connado as New ADODB. Connection ()
Dim Recordsetado as New ADODB. Recordset ()
Dim connectionString as String
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data source=" & Server.MapPath ("Grades.mdb")
Connado.open (connectionString)

Recordsetado.activeconnection = Connado
Recordsetado.cursortype = ADODB. CursorTypeEnum.adOpenStatic
Recordsetado.cursorlocation = ADODB. Cursorlocationenum.aduseclient
Dim strSQL as String
strSQL = "Select City, month, temperature from test order by City,ids"
Recordsetado.open (strSQL, Connado)
Owcchartspace.datasource = Recordsetado



Then, specify the display type of the OWC:

Owcchart.type = OWC. Chartcharttypeenum.chcharttypesmoothlinemarkers



There are several ways to enter data into OWC at run time. All of these methods use the SetData method to actually write the data to the Chart component, so this method is described in detail. The SetData method is applied to WCChart, WCErrorBars, and wcseries objects and can input data to these three objects.

The SetData method has three parameters: Dimension, DataSourceIndex, and DataReference. The Dimension parameter refers to a portion of the data that is populated in the chart. The available dimension constants are Seriesnames, Categories, Values, Yvalues, XValues, Openvalues, Closevalues, Highvalues, Lowvalues, bubblevalues , RValues and Thetavalues. Each of these constants refers to a part of the chart; For example, the Seriesnames constant references each sequence name, the Openvalues and Closevalues constants refer to the opening and closing price of the stock chart, and so on. Each constant is passed to the method as an enumeration constant in forms such as chDimSeriesNames, chDimCategories, chDimValues, and so on.

Here, we use the SetData method to assign values to OWC:

Owcchart.setdata (OWC. Chartdimensionsenum.chdimseriesnames, 0, "city")
Dim owcseries as OWC. WCSeries
For each owcseries in Owcchart.seriescollection
Owcseries.setdata (OWC. Chartdimensionsenum.chdimcategories, 0, "month")
Owcseries.setdata (OWC. Chartdimensionsenum.chdimvalues, 0, "temperature")
Next



Finally, the OWC processing results are converted to GIF image output to display in the browser:

Randomize ()
Dim Nfilenamesuffix as Integer
Dim Sfilenamesuffix as String
Nfilenamesuffix = 100000 * RND ()
Sfilenamesuffix = System.Convert.ToString (Nfilenamesuffix)
Owcchartspace.exportpicture (MapPath ("Owc/price_")
+ Sfilenamesuffix + ". gif", "gif", 800, 600)
Image1.imageurl = "Owc/price_" + Sfilenamesuffix + ". gif"


If you change the display type of OWC, you modify the Owcchart.type to make it:

Owcchart.type = OWC. Chartcharttypeenum.chcharttypecolumnclustered

  
Using OWC in asp.net can help us quickly construct statistical charts, and because OWC produces GIF images that are compatible with all versions of the browser, the scope of the application is wide. This program runs successfully in Windows Server, IIS5.0, and IE6.0 environments.


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.