I've used the following code to create charts with Office Web Components, but pie-chart doesn't work. Stacked-pie works fine.
I got no errors or warnings, so what could be wrong with the following code?
I use MS SQL Server 7. This code is retrieving its charting data from Northwind -database.
Here's the code:
<% option explicit %>
<%
' Declaring variables
Dim objConn
Dim objResSet
Dim strConn
Dim owc
Dim owcChart
Dim rs
Dim strSQL
Dim strPath
Dim owcLabels
' Path to server (chart picture is stored here.)
strPath = server.mapPath("./testit"
' Opening connection
Set objConn = Server.CreateObject("ADODB.Connection"
strConn = "Driver={SQL Server};" & "Server=sqlserver;Uid=test;Pwd=test; Database=Northwind"
objConn.open strConn
' SQL sentence, which retrieves product names and prices which cost under 10 dollars
strSQL = "select productname, unitprice from products where unitprice < 10"
' Creating recordset
set rs = server.createObject("adodb.recordset"
' Defining OWC
set owc = createObject("owc.chart"
set owcChart = owc.charts.add
' Defining Chart-type
owcChart.type = owc.constants.chChartTypePie
owcChart.hasLegend = true
owcChart.hasTitle = true
owcChart.title.caption = "Testing"
owcChart.title.font.name = "tahoma"
owcChart.title.font.size = 10
owcChart.title.font.bold = true
rs.cursorLocation = 3 'adUseClient
rs.open strSQL, strConn, 3 'adOpenStatic - opening recordset statically
set owc.dataSource = rs
' Attempting to create chart
owcChart.seriesCollection.add.setData owc.constants.chDimCategories, 0, "productname"
owcChart.seriesCollection.add.setData owc.constants.chDimValues, 0, "unitprice"
set owcLabels = owcChart.seriesCollection.add.dataLabelsCollection.add
owcLabels.hasValue = false
owcLabels.hasPercentage = true
owcLabels.font.name = "tahoma"
owcLabels.font.size = 8
' Storing image to the server
owc.exportPicture strPath & "/" & session.sessionId _
& "b.gif", "gif", 800, 500
response.write "<img src=""testit/" & _
session.sessionId & "b.gif"">"
rs.close
set owcChart = nothing
set rs = nothing
set strSQL = nothing
%>
It shows the legend ok. Sector values are collected correctly, but it doesn't draw the pie.
Stacked pie is displayed ok, which amazes me, since there's no big difference between stacked-pie and pie.
I would appreciate your help!
I got no errors or warnings, so what could be wrong with the following code?
I use MS SQL Server 7. This code is retrieving its charting data from Northwind -database.
Here's the code:
<% option explicit %>
<%
' Declaring variables
Dim objConn
Dim objResSet
Dim strConn
Dim owc
Dim owcChart
Dim rs
Dim strSQL
Dim strPath
Dim owcLabels
' Path to server (chart picture is stored here.)
strPath = server.mapPath("./testit"
' Opening connection
Set objConn = Server.CreateObject("ADODB.Connection"
strConn = "Driver={SQL Server};" & "Server=sqlserver;Uid=test;Pwd=test; Database=Northwind"
objConn.open strConn
' SQL sentence, which retrieves product names and prices which cost under 10 dollars
strSQL = "select productname, unitprice from products where unitprice < 10"
' Creating recordset
set rs = server.createObject("adodb.recordset"
' Defining OWC
set owc = createObject("owc.chart"
set owcChart = owc.charts.add
' Defining Chart-type
owcChart.type = owc.constants.chChartTypePie
owcChart.hasLegend = true
owcChart.hasTitle = true
owcChart.title.caption = "Testing"
owcChart.title.font.name = "tahoma"
owcChart.title.font.size = 10
owcChart.title.font.bold = true
rs.cursorLocation = 3 'adUseClient
rs.open strSQL, strConn, 3 'adOpenStatic - opening recordset statically
set owc.dataSource = rs
' Attempting to create chart
owcChart.seriesCollection.add.setData owc.constants.chDimCategories, 0, "productname"
owcChart.seriesCollection.add.setData owc.constants.chDimValues, 0, "unitprice"
set owcLabels = owcChart.seriesCollection.add.dataLabelsCollection.add
owcLabels.hasValue = false
owcLabels.hasPercentage = true
owcLabels.font.name = "tahoma"
owcLabels.font.size = 8
' Storing image to the server
owc.exportPicture strPath & "/" & session.sessionId _
& "b.gif", "gif", 800, 500
response.write "<img src=""testit/" & _
session.sessionId & "b.gif"">"
rs.close
set owcChart = nothing
set rs = nothing
set strSQL = nothing
%>
It shows the legend ok. Sector values are collected correctly, but it doesn't draw the pie.
Stacked pie is displayed ok, which amazes me, since there's no big difference between stacked-pie and pie.
I would appreciate your help!