Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP pie-chart won't work with OWC

Status
Not open for further replies.

mikki

Programmer
Jun 5, 2001
2
US
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(&quot;./testit&quot;)

' Opening connection
Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)

strConn = &quot;Driver={SQL Server};&quot; & &quot;Server=sqlserver;Uid=test;Pwd=test; Database=Northwind&quot;

objConn.open strConn


' SQL sentence, which retrieves product names and prices which cost under 10 dollars
strSQL = &quot;select productname, unitprice from products where unitprice < 10&quot;

' Creating recordset
set rs = server.createObject(&quot;adodb.recordset&quot;)

' Defining OWC
set owc = createObject(&quot;owc.chart&quot;)
set owcChart = owc.charts.add

' Defining Chart-type

owcChart.type = owc.constants.chChartTypePie
owcChart.hasLegend = true
owcChart.hasTitle = true
owcChart.title.caption = &quot;Testing&quot;
owcChart.title.font.name = &quot;tahoma&quot;
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, &quot;productname&quot;

owcChart.seriesCollection.add.setData owc.constants.chDimValues, 0, &quot;unitprice&quot;

set owcLabels = owcChart.seriesCollection.add.dataLabelsCollection.add
owcLabels.hasValue = false
owcLabels.hasPercentage = true
owcLabels.font.name = &quot;tahoma&quot;
owcLabels.font.size = 8



' Storing image to the server

owc.exportPicture strPath & &quot;/&quot; & session.sessionId _
& &quot;b.gif&quot;, &quot;gif&quot;, 800, 500
response.write &quot;<img src=&quot;&quot;testit/&quot; & _
session.sessionId & &quot;b.gif&quot;&quot;>&quot;


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 am having the same problem, except that my chart shows up at 1 full data series instead of the 3 series that are in my database. They show up fine in the legend, does anyone know what is wrong???

<% Option Explicit %>
<HTML>
<HEAD>
<TITLE>D/90 FY02 Total Burdened Direct Hours</TITLE>
<!-- #include virtual=&quot;/adovbs.inc&quot; -->
<%
Function ExportChartToGIF(objCSpace, strAbsFilePath, strRelFilePath)
Dim strFileName
Randomize
strFileName = Timer & Rnd & &quot;.gif&quot;
objCSpace.ExportPicture strAbsFilePath & &quot;\&quot; & strFileName, &quot;gif&quot;, 765, 400
ExportChartToGIF = strRelFilePath & &quot;/&quot; & strFileName
End Function

Sub CleanUpGIF(GIFpath)
Dim objFS
Dim objFolder
Dim gif
set objFS = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
set objFolder = objFS.GetFolder(GIFpath)
for each gif in objFolder.Files
if instr(gif.Name, &quot;.gif&quot;) > 0 and DateDiff(&quot;n&quot;, gif.DateLastModified, now) > 10 then
objFS.DeleteFile GIFpath & &quot;\&quot; & gif.Name, True
end if
next
set objFolder = nothing
set objFS = nothing
End Sub

%>
</HEAD>
<BODY BGCOLOR=&quot;#FFFFFF&quot;>
<%
dim objChartSpace
dim objChart
dim objSeries
dim objConn
dim objRS
dim c
dim series
dim strChartAbsPath
dim strChartRelPath
dim strChartFile
strChartAbsPath = Server.MapPath(&quot;/metrics/chartimages&quot;)
strChartRelPath = &quot;&quot;

set objChartSpace = Server.CreateObject(&quot;OWC.Chart&quot;)
set objChart = objChartSpace.Charts.Add()
set c = objChartSpace.Constants

objChart.Type = c.chChartTypePie
objChart.HasLegend = True
objChart.Legend.Position = c.chLegendPositionBottom
objChart.PlotArea.Interior.Color = &quot;White&quot;



set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
objConn.Open &quot;pie&quot;
set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
set objRS.ActiveConnection = objConn
objRS.CursorType = adOpenStatic
objRS.CursorLocation = adUseClient
objRS.Open &quot;select * from pie&quot;
set objChartSpace.DataSource = objRS
objChart.SetData c.chDimSeriesNames, 0, &quot;NAME&quot;
for each objSeries in objChart.SeriesCollection
objSeries.SetData c.chDimCategories, 0, &quot;NAME&quot;
objSeries.SetData c.chDimValues, 0, &quot;DATA&quot;
next

strChartFile = ExportChartToGIF(objChartSpace, strChartAbsPath, strChartRelPath)
Response.Write &quot;<IMG SRC=&quot;&quot;/metrics/chartimages&quot; & strChartFile & &quot;&quot;&quot;>&quot; & &quot;<P>&quot;
CleanUpGIF strChartAbsPath

objRS.Close
set objRS = nothing
set objConn = nothing
set objSeries = nothing
set objChart = nothing
set objChartSpace = nothing
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top