17 abril 2009

Criando gráficos no ASP

O artigo abaixo irá explicar o uso do componente OWC10 da Microsoft, essa função já está em uso comigo há algum tempo.

Espero que vocês façam bom proveito com este fonte, assim como eu já o fiz.

<%
'================================================================================================================='
Function Gera_Grafico(RSDADOS,titulo,largura,altura,titulo_eixo,char_type)
  on error resume next
  if isarray(RSDADOS)=true then
    Set oChart = CreateObject("OWC10.ChartSpace")
    
    if IsObject(oChart) = false then
      response.write "Erro ao criar o componente"
      exit function
    end if
    
    Set c = oChart.Constants
    oChart.Border.Color = c.chColorNone
    
    Redim categories(UBOUND(RSDADOS,2)), Vals(UBOUND(RSDADOS,2))
    
    ' críe um array que represente os valores da primeira série. 
    FOR I=0 TO UBOUND(RSDADOS,2)
      Vals(I) = RSDADOS(1,I)
    NEXT
    
    ' gráfico de coluna com as duas séries e quatro categorias. 
    ' críe um array que represente as categorias, as categorias serão as mesmas para as duas séries. 
    FOR I=0 TO UBOUND(RSDADOS,2)
      legenda=RSDADOS(0,I)
      categories(I) = legenda&" : Total("&Vals(I)&")"
    NEXT
    
    With oChart
    
    ' adicionando um objeto do gráfico.
    .Charts.Add

    ' adicionando o tipo do gráfico.    
    select  case cInt(char_type)
        case 0  
          .Charts(0).Type = oChart.Constants.chChartTypePie
        case 1  
          .Charts(0).Type = oChart.Constants.chChartTypePie3d
        case 2
          .Charts(0).Type = oChart.Constants.chChartTypeColumnClustered
        case 3
          .Charts(0).Type = oChart.Constants.chChartTypeColumn3d
        case 4
          .Charts(0).Type = oChart.Constants.chChartTypeArea
        case 5
          .Charts(0).Type = oChart.Constants.chChartTypeBarClustered
        case 6
          .Charts(0).Type = oChart.Constants.chChartTypeBar3D          
        case 7
          .Charts(0).Type = oChart.Constants.chChartTypeArea3D
        case 8
          .Charts(0).Type = oChart.Constants.chChartTypeLine
        case 9
          .Charts(0).Type = oChart.Constants.chChartTypeLineMarkers
    end select
        
    ' adicionando a primeira série ao gráfico.
    .Charts(0).SeriesCollection.Add
    
    ' ajustando o subtítulo da série (o texto da legenda).
    .Charts(0).SeriesCollection(0).Caption = titulo_eixo
    
    ' adicionando as categorias e os valores da primeira série.
    .Charts(0).SeriesCollection(0).SetData c.chDimCategories, c.chDataLiteral, categories
    .Charts(0).SeriesCollection(0).SetData c.chDimValues, c.chDataLiteral, Vals
    .Charts(0).HasLegend = false
    .Charts(0).HasTitle = false
    End With
    
    Response.Expires = 0
    Response.Buffer = true
    Response.Clear
    Response.ContentType = "image/png"
    
    'ajustando o tamanho do gráfico (figura).
    Response.BinaryWrite oChart.GetPicture("png",largura, altura)
  end if
end function

  t  =  request("t")
  th  =  request("th")
  w  =  request("w")
  h  =  request("h")
  id  =  request("id")
  o  =  request("o")

Call Gera_Grafico(Session(o),t,w,h,th,id)%>

Nenhum comentário: