Ecco il codice:

codice:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
  anno_rif = Request.QueryString("anno")
  trimestre = Request.QueryString("trimestre")

  on Error resume next
    url_DB = "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.mappath("DATABASE/ProgStratFA_Dati.mdb")
    set connobj = Server.CreateObject( "ADODB.Connection" )
    connobj.Open url_DB

	grafico = false
 
    if err.Number=0 then

      Dim obiettivi_direttiva(100)
      Dim importo_programmato(100)
      Dim importo_monitorato_1tr(100)
      Dim importo_monitorato_2tr(100)
      Dim importo_monitorato_3tr(100)
      Dim importo_monitorato_4tr(100)

      str_PROGRAMMAZIONE = "SELECT CodOBS,CodOBO,Sum(Programmato) AS SommaDiProgrammato FROM PDATabRF WHERE Anno='" & anno_rif & "' GROUP BY CodOBS,CodOBO ORDER BY CodOBS,CodOBO"
      set Mostra_PROGRAMMAZIONE = server.createobject("adodb.recordset") 
      Mostra_PROGRAMMAZIONE.open str_PROGRAMMAZIONE, connobj, 3, 3 

      str_MONITORAGGIO = "SELECT CodOBS,CodOBO,Sum(Aggiornato1) AS SommaDiAggiornato1,Sum(Aggiornato2) AS SommaDiAggiornato2,Sum(Aggiornato3) AS SommaDiAggiornato3,Sum(Aggiornato4) AS SommaDiAggiornato4 FROM MonitoraggioRF WHERE Anno='" & anno_rif & "' GROUP BY CodOBS,CodOBO ORDER BY CodOBS,CodOBO"
      set Mostra_MONITORAGGIO = server.createobject("adodb.recordset") 
      Mostra_MONITORAGGIO.open str_MONITORAGGIO, connobj, 3, 3 
	  
      Set cs = Server.CreateObject("OWC10.ChartSpace")
      Set chConstants = cs.Constants
      Set chart = cs.charts.add

      'tipo di grafico (da 0 a 65 con dei buchi):
      '   0  (istogramma)
      '   6  (linea)
      '   7  (linea con pallini)
      '   47 (istogramma 3D)
      chart.type = 0

      'colore del bordo della tabella
      chart.Border.Color = "Red" 

      'titolo
      chart.HasTitle = True
      chart.Title.Caption = "Confronto tra risorse finanziarie programmate e risorse finanziarie realmente disponibili (E.F. " & anno_rif & ") aggiornato al " & date & "," & time
      set objFont = chart.Title.Font
      objFont.Name = "Tahoma"
      objFont.Size = 14
      objFont.Bold = True

      'asse delle x
      set objAxis = chart.Axes(chConstants.chAxisPositionBottom)
      objAxis.HasTitle = True
      objAxis.Title.Caption = "Obiettivi iscritti in direttiva"
      set objFont = objAxis.Title.Font
      objFont.Name = "Tahoma"
      objFont.Size = 8
      objFont.Bold = True
      objFont.Color = "#FF0000"

      'asse delle y
      set objAxis = chart.Axes(chConstants.chAxisPositionLeft)
      objAxis.HasTitle = True
      objAxis.Title.Caption = "Risorse finanziarie associate"
      set objFont = objAxis.Title.Font
      objFont.Name = "Tahoma"
      objFont.Size = 8
      objFont.Bold = True
      objFont.Color = "#FF0000"
  
      if not Mostra_PROGRAMMAZIONE.eof then
	    grafico = true
	
  	    set serie1 = chart.seriesCollection.add 
		if (cint(trimestre)>=1) then
          set serie2 = chart.seriesCollection.add
		end if
		if (cint(trimestre)>=2) then
          set serie3 = chart.seriesCollection.add
		end if
		if (cint(trimestre)>=3) then
          set serie4 = chart.seriesCollection.add
		end if
		if (cint(trimestre)>=4) then
          set serie5 = chart.seriesCollection.add
		end if
		
        for i = 1 to Mostra_PROGRAMMAZIONE.RecordCount
	      
		  obiettivi_direttiva(i) = Mostra_PROGRAMMAZIONE("CodOBS") & VBcrlf & Mostra_PROGRAMMAZIONE("CodOBO")
	      importo_programmato(i) = clng(Mostra_PROGRAMMAZIONE("SommaDiProgrammato"))
		  if (i=1) then
			minimo = clng(Mostra_PROGRAMMAZIONE("SommaDiProgrammato"))
			massimo = clng(Mostra_PROGRAMMAZIONE("SommaDiProgrammato"))
		  else
			if ((importo_programmato(i)<minimo) and (importo_programmato(i)>0)) then
			  minimo = clng(Mostra_PROGRAMMAZIONE("SommaDiProgrammato"))
			end if
			if (importo_programmato(i)>massimo) then
			  massimo = clng(Mostra_PROGRAMMAZIONE("SommaDiProgrammato"))
			end if
		  end if
		  
		  trovato = false
		  while ((not Mostra_MONITORAGGIO.eof) and (not trovato))
		     if ((Mostra_MONITORAGGIO("CodOBS")=Mostra_PROGRAMMAZIONE("CodOBS")) and (Mostra_MONITORAGGIO("CodOBO")=Mostra_PROGRAMMAZIONE("CodOBO"))) then
			   trovato = true
			 else
		       Mostra_MONITORAGGIO.MoveNext
			 end if
		  wend
		  
		  if (cint(trimestre)>=1) then
  	        importo_monitorato_1tr(i) = 0
		    if trovato then
			  if (Len(Mostra_MONITORAGGIO("SommaDiAggiornato1"))<>0) then
  	            importo_monitorato_1tr(i) = clng(Mostra_MONITORAGGIO("SommaDiAggiornato1"))
			    if ((importo_monitorato_1tr(i)<minimo) and (importo_monitorato_1tr(i)>0)) then
			      minimo = clng(Mostra_MONITORAGGIO("SommaDiAggiornato1"))
			    end if
			    if (importo_monitorato_1tr(i)>massimo) then
			      massimo = clng(Mostra_MONITORAGGIO("SommaDiAggiornato1"))
			    end if
			  end if
			end if
	      end if
		  if (cint(trimestre)>=2) then
  	        importo_monitorato_2tr(i) = 0
		    if trovato then
			  if (Len(Mostra_MONITORAGGIO("SommaDiAggiornato2"))<>0) then
  	            importo_monitorato_2tr(i) = clng(Mostra_MONITORAGGIO("SommaDiAggiornato2"))
			    if ((importo_monitorato_2tr(i)<minimo) and (importo_monitorato_2tr(i)>0)) then
			      minimo = clng(Mostra_MONITORAGGIO("SommaDiAggiornato2"))
			    end if
			    if (importo_monitorato_2tr(i)>massimo) then
			      massimo = clng(Mostra_MONITORAGGIO("SommaDiAggiornato2"))
			    end if
			  end if
			end if
	      end if
		  if (cint(trimestre)>=3) then
  	        importo_monitorato_3tr(i) = 0
		    if trovato then
			  if (Len(Mostra_MONITORAGGIO("SommaDiAggiornato3"))<>0) then
  	            importo_monitorato_3tr(i) = clng(Mostra_MONITORAGGIO("SommaDiAggiornato3"))
			    if ((importo_monitorato_3tr(i)<minimo) and (importo_monitorato_3tr(i)>0)) then
			      minimo = clng(Mostra_MONITORAGGIO("SommaDiAggiornato3"))
			    end if
			    if (importo_monitorato_3tr(i)>massimo) then
			      massimo = clng(Mostra_MONITORAGGIO("SommaDiAggiornato3"))
			    end if
			  end if
			end if
	      end if
		  if (cint(trimestre)>=4) then
  	        importo_monitorato_4tr(i) = 0
		    if trovato then
			  if (Len(Mostra_MONITORAGGIO("SommaDiAggiornato4"))<>0) then
  	            importo_monitorato_4tr(i) = clng(Mostra_MONITORAGGIO("SommaDiAggiornato4"))
			    if ((importo_monitorato_4tr(i)<minimo) and (importo_monitorato_4tr(i)>0)) then
			      minimo = clng(Mostra_MONITORAGGIO("SommaDiAggiornato4"))
			    end if
			    if (importo_monitorato_4tr(i)>massimo) then
			      massimo = clng(Mostra_MONITORAGGIO("SommaDiAggiornato4"))
			    end if
			  end if
			end if
	      end if
          
		  Mostra_MONITORAGGIO.MoveFirst
          Mostra_PROGRAMMAZIONE.MoveNext
        
		next

        serie1.SetData chConstants.chDimCategories, chConstants.chDataLiteral, obiettivi_direttiva
        serie1.SetData chConstants.chDimValues, chConstants.chDataLiteral, importo_programmato
		if (cint(trimestre)>=1) then
	      serie2.SetData chConstants.chDimValues, chConstants.chDataLiteral, importo_monitorato_1tr
		end if
		if (cint(trimestre)>=2) then
	      serie3.SetData chConstants.chDimValues, chConstants.chDataLiteral, importo_monitorato_2tr
		end if
		if (cint(trimestre)>=3) then
	      serie4.SetData chConstants.chDimValues, chConstants.chDataLiteral, importo_monitorato_3tr
		end if
		if (cint(trimestre)>=4) then
	      serie5.SetData chConstants.chDimValues, chConstants.chDataLiteral, importo_monitorato_4tr
		end if
      end if

      'legenda
      chart.HasLegend = True
	  
      chart.SeriesCollection(0).Caption = "Importo programmato"
	  for i=1 to cint(trimestre)
        chart.SeriesCollection(i).Caption = i & "° Monitoraggio - Importo aggiornato" 
	  next
  
      larghezza = Mostra_PROGRAMMAZIONE.RecordCount*(40*(cint(trimestre)+1))
	  if (larghezza > 6450) then
	    larghezza = 6450
	  end if
	  altezza = round((massimo/minimo)*2)
	  if (altezza > 4350) then
	    altezza = 4350
	  end if
      cs.ExportPicture server.MapPath("GRAFICO/grafico_monitoraggio.gif"), "GIF", larghezza, altezza

      Set cs = Nothing
	  
      Mostra_PROGRAMMAZIONE.Close
      Set Mostra_PROGRAMMAZIONE = Nothing
      Mostra_MONITORAGGIO.Close
      Set Mostra_MONITORAGGIO = Nothing
	 
	end if

    connobj.Close
    set connobj = nothing
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Grafico monitoraggi</title>

</head>
<body>

<%
  if grafico then
%>
    <div align="center">[img]GRAFICO/grafico_monitoraggio.gif[/img]</div>
<%
  else
%>
    <div align="center">ATTENZIONE: non esiste alcun monitoraggio</div>
<%
  end if
%>

</body>
</html>