Hi,
I've wrote the code GRAPHIC_ENGINE. ASPX.VB
but it doesn't work properly, because the chart appears only with one
dataline (the last line resulting from the query). Can anyone tell me
what i'm doing wrong?
Thanks in advance.
Marco Viana
Portugal
GRAPHIC_ENGINE. ASPX.VB:
Imports System
Imports System.Data
Imports System.Data.Sql Client
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.UI.H tmlControls
Imports Microsoft.Offic e.Interop
Imports Microsoft.Offic e.Interop.OWC
Public Class graphic_engine
Inherits System.Web.UI.P age
Protected WithEvents chartspace1 As OWC.ChartSpace
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
Response.Buffer = True
'''************ *************** *************** *************** ***
'''*** Query building
'''************ *************** *************** *************** ***
Dim v_campanha As String
v_campanha = Request.QuerySt ring("idcampanh a")
Dim a_campanha() As String
a_campanha = Split(v_campanh a, ",")
Dim v_estacao As String
v_estacao = Request.QuerySt ring("idestacao ")
Dim a_estacao() As String
a_estacao = Split(v_estacao , ",")
Dim v_parametro As String
v_parametro = Request.QuerySt ring("idparamet ro")
Dim v_profundidade As String
v_profundidade = Request.QuerySt ring("idprofund idade")
Dim a_sql_series(UB ound(a_estacao) + 1, 1) As String
'Criar primeira linha do array com uma query que vai criar
todas as campanhas
a_sql_series(0, 0) = "SELECT nome, 0 AS valor FROM l_periodo
ORDER BY codigo"
a_sql_series(0, 1) = "SELECT count(*) FROM l_periodo"
Dim j As Integer
j = 0
Dim k As Integer
k = 1
While j <= UBound(a_estaca o)
a_sql_series(j + 1, 0) = "SELECT periodo,cast(va lor AS
float),parametr o,profund,unid FROM l_medicoes WHERE parametro_codig o="
& v_parametro & " AND profund='" & v_profundidade & "' AND
local_codigo=" & a_estacao(j) & " AND (periodo_codigo = " &
a_campanha(0) & " "
'a_sql_series(j , 0) = "SELECT periodo_codigo, cast(valor AS
float),parametr o,profund,unid FROM l_medicoes WHERE parametro_codig o="
& v_parametro & " AND profund='" & v_profundidade & "' AND
local_codigo=" & a_estacao(j) & " AND (periodo_codigo = " &
a_campanha(0) & " "
a_sql_series(j + 1, 1) = "SELECT count(*) FROM l_medicoes
WHERE parametro_codig o=" & v_parametro & " AND profund='" &
v_profundidade & "' AND local_codigo=" & a_estacao(j) & " AND
(periodo_codigo = " & a_campanha(0) & " "
While k <= UBound(a_campan ha)
a_sql_series(j + 1, 0) = a_sql_series(j + 1, 0) & " OR
periodo_codigo = " & a_campanha(k) & " "
a_sql_series(j + 1, 1) = a_sql_series(j + 1, 1) & " OR
periodo_codigo = " & a_campanha(k) & " "
If k = UBound(a_campan ha) Then
a_sql_series(j + 1, 0) = a_sql_series(j + 1, 0) &
") "
a_sql_series(j + 1, 1) = a_sql_series(j + 1, 1) &
") "
End If
k = k + 1
End While
a_sql_series(j + 1, 0) = a_sql_series(j + 1, 0) & " ORDER
BY periodo_codigo"
j = j + 1
k = 1
End While
'''************ *************** *************** *************** ***
'''*** End Query Building
'''************ *************** *************** *************** ***
'declare chartsapce, chart and "series objects" of OWC
'new chartspace
Dim chartspace1
chartspace1 = New OWC.ChartSpace( )
chartspace1.Cle ar()
'new chart
chartspace1.cha rts.add()
'DB Connection
Dim ConnStr As String
ConnStr = f_conexion_stri ng_bd(Session(" username"),
Session("passwo rd"))
Dim PubsConn As New SqlClient.SqlCo nnection(ConnSt r)
PubsConn.Open()
'Loop--> creation of graphic
Dim m As Integer
m = 0
While m <= UBound(a_sql_se ries)
Dim countCmd As New SqlCommand(a_sq l_series(m, 1),
PubsConn)
Dim perfilCmd As New SqlClient.SqlCo mmand(a_sql_ser ies(m,
0), PubsConn)
'Declare DataReader object
Dim data_reader As SqlClient.SqlDa taReader
'Declare variables
Dim i As Integer
Dim numpoints 'number of datapoints
Dim categories() 'array with x values
Dim values() 'array with y values
'1st: find number of datapoints
data_reader = countCmd.Execut eReader()
data_reader.Rea d()
numpoints = data_reader.Get Value(0)
data_reader.Clo se()
'Redim arrays
ReDim values(numpoint s - 1)
ReDim categories(nump oints - 1)
'2nd: bind arrays
data_reader = perfilCmd.Execu teReader
i = 0
While data_reader.Rea d
categories(i) = data_reader.Get Value(0)
'Response.Write (categories(i) & "<br>")
values(i) = data_reader.Get Value(1)
'Response.Write (values(i) & "<p>")
i = i + 1
End While
'3th create graphs
chartspace1.cha rts(0).seriesco llection.add(m)
chartspace1.cha rts(0).seriesco llection(m).typ e =
chartspace1.con stants.chChartT ypeLineMarkers
chartspace1.Cha rts(0).SeriesCo llection(m).Set Data(OWC.ChartD imensionsEnum.c hDimCategories,
OWC.ChartSpecia lDataSourcesEnu m.chDataLiteral , categories)
chartspace1.Cha rts(0).SeriesCo llection(m).Set Data(OWC.ChartD imensionsEnum.c hDimValues,
OWC.ChartSpecia lDataSourcesEnu m.chDataLiteral , values)
data_reader.Clo se()
m = m + 1
End While
PubsConn.Close( )
'Format chart
With chartspace1.Cha rts(0)
.HasLegend = True
.Legend.Positio n =
OWC.ChartLegend PositionEnum.ch LegendPositionB ottom
.HasTitle = True
.Title.Caption = "Gráfico"
.Axes(0).HasTit le = True
.Axes(0).Title. Caption = "Campanha"
.Axes(1).HasTit le = True
.Axes(1).Title. Caption = "parametro"
End With
With chartspace1.Cha rts(0).SeriesCo llection(0)
.line.color = "white"
.interior.color = "white"
.border.color = "white"
.caption = ""
.Marker.Style = ChartMarkerStyl eEnum.chMarkerS tyleNone
'.DataLabelsCol lection.Add()
End With
With chartspace1.Cha rts(0).SeriesCo llection(1)
'.line.color = "black"
'.zorder = 200
End With
'chartspace1.Ch arts(0).SeriesC ollection(2).
'Legends
Dim n As Integer
n = 1
Dim sql_estacao As String
While n <= UBound(a_estaca o) + 1
sql_estacao = "SELECT nome FROM l_local WHERE codigo=" &
a_estacao(n - 1)
Dim estacaoCmd As New SqlClient.SqlCo mmand(sql_estac ao,
PubsConn2)
Dim lista_estacao As SqlClient.SqlDa taReader
lista_estacao = estacaoCmd.Exec uteReader()
lista_estacao.R ead()
chartspace1.Cha rts(0).SeriesCo llection(n).cap tion =
lista_estacao.G etValue(0)
lista_estacao.C lose()
n = n + 1
End While
PubsConn2.Close ()
Response.Conten tType = "image/gif"
Response.Expire s = 0
Response.Binary Write(chartspac e1.GetPicture(" gif", 600, 400))
Response.End()
End Sub
End Class