Use OWC to draw statistical charts in ASP.net

Source: Internet
Author: User

OWCMicrosoft Office Web Components) is a data binding ActiveX Control used by Microsoft Office to add charts to Web pages. OWC supports two-dimensional charts (such as line charts, column charts, and stock price charts) and polar charts (such as pie charts and radar charts) in most Microsoft Excel 2000, and supports combining charts, for example, if a two-axis line-bar chart is created, the data table is published along with the chart, and the chart changes as the data changes. OWC can output the processing result as a standard GIF and download it to the browser for display.
First, read the data set using ADODB. Recordset and bind the data 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 OWC display type:
OwcChart. Type = OWC. ChartChartTypeEnum. chChartTypeSmoothLineMarkers
There are multiple ways to input data to OWC at runtime. The SetData method is used to write data into the Chart component. Therefore, 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 references a part of the filled data in the chart. Available dimension constants include SeriesNames, Categories, Values, YValues, XValues, OpenValues, CloseValues, HighValues, LowValues, BubbleValues, RValues, and ThetaValues. Each of these constants references a part of the chart. For example, the SeriesNames constant references each sequence name, The OpenValues and CloseValues constants reference the opening and closing prices of the stock chart, and so on. Each constant is passed to this method as an enumeration constant in forms such as chDimSeriesNames, chDimCategories, and chDimValues.
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, convert the OWC processing result into a Gif image and output it to the browser for display:
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 OWC display Type, modify owcChart. Type:
OwcChart. Type = OWC. ChartChartTypeEnum. chChartTypeColumnClustered
Using OWC in ASP.net can help us quickly construct statistical charts. Because OWC generates Gif images, it can be compatible with all client versions of browsers and has a wide range of applicability. This program runs successfully in Windows 2000 server, IIS5.0, and IE6.0 environments.


Related Article

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.