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_")