PDA

View Full Version : How to duplicate a chart


paulafernandes
02-18-2005, 07:47 PM
Hello!

I have this code to draw a pie chart on my ASP Page:

<object id=ChartSpace1 classid=CLSID:0002E500-0000-0000-C000-000000000046 width="346" height="274"></object>
<script language=vbscript>
Sub Window_OnLoad()

Dim oChart
Dim oSeries1
dim oConst

'Ensure ChartSpace1 is empty:
ChartSpace1.Clear

Set oConst = ChartSpace1.Constants

'Create a new chart in the ChartSpace
Set oChart = ChartSpace1.Charts.Add

'Adiciona as colunas que existem no grafico
Set oSeries1 = oChart.SeriesCollection.Add
With oSeries1
.Caption = "Norte"

.SetData oConst.chDimCategories, oConst.chDataLiteral, Array("Não Respondeu", "Gasóleo", "Gasolina", "Gasolina 95", "Gasolina 98", "Mistura")
.Type = oConst.chChartTypePie
.SetData oConst.chDimValues, oConst.chDataLiteral, Array(22,55,66,99,77,44)

End With

'Add a second value axis to the Chart
'oChart.Axes.Add oChart.Scalings(oConst.chDimValues),
oConst.chAxisPositionRight, oConst.chValueAxis

'Display the legend
oChart.HasLegend = true
oChart.Legend.Position = oConst.chLegendPositionBottom

'Para por o titulo no grafico
oChart.HasTitle = true
oChart.Title.Caption = "Norte"
end sub
</script>


It works fine, including with database records. (A little diferent code...)

My problem is that I need 5 diferent charts on my ASP page, each one of them resulting from an SQL query.
The first one works fine, but when I duplicate the code above the first one desapears and it shows the second. I change the reference "object id=ChartSpace1" to object "id=ChartSpace2" and the references to this name on the VB code. It seems it's not enough.

What am I doing wrong????
Help!

Thank's
Paula

miranda
02-18-2005, 08:07 PM
Have you tried creating the object at run time versus at design time? Then you would merely need to create the object one time, run code to populate the chart, open it, display results, close, run code to populate the 2nd chart, open it, display results, close,.... etc then at the very end when all done using the object set object to nothing to release the object from memory.

paulafernandes
02-21-2005, 11:55 AM
Hello miranda, thank's for your answer.

I've tried your sugestion but I can't get it to work that way.
Any more sugestions?....

Thank's
Paula