OWC Chart and XML DataSource

  • Thread starter César Juan Viñas Arias
  • Start date
C

César Juan Viñas Arias

Hi,

I have a problem, I'm building a solution using OWC Chart with XML
DataSourse in ASP, but there is an error that I can't resolve. Please,
anyone can help me?

The error is in this line of code:

oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimCategories, 0, 0

and the message is:

Runtime Error '1004'

Invalid Parameter

This the code in Visual Basic:

Private Sub Form_Load()
Dim oCn As New ADODB.Connection 'Conexión
Dim oCmd As New ADODB.Command 'Comando
Dim oDSC As New OWC10.DataSourceControl 'DataSourceControl para los
datos XML
Dim oCS As New OWC10.ChartSpace 'ChartSpace
Dim oConstantes 'Constantes del ChartSpace
Dim strSQL As String 'Sentencia SQL
Dim strIn As New Stream 'Stream para el ingreso de datos
Dim strOut As New Stream 'Stream para los datos de salida
Dim strXML As String 'XML obtenido de la consulta a
la base de datos
Dim strXMLFinal As String 'XML formateado

'Generar la sentencia SQL que devolverá los datos
strSQL = "<ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql'>"
strSQL = strSQL & "<sql:query>"
strSQL = strSQL & "SELECT VM_PLATE_F001 AS XValues, VM_TARA_F006 AS
YValues FROM TABLE_061_VEHICLE_MAINTENANCE WHERE FLAG_LAST = 1 FOR XML RAW"
strSQL = strSQL & "</sql:query>"
strSQL = strSQL & "</ROOT>"

'Crear el objeto Stream de entrada y asignarle la plantilla de la
consulta
strIn.Open
strIn.WriteText strSQL, adWriteChar
strIn.Position = 0

'Crear y configurar la conexión a la base de datos
oCn.ConnectionString = "Provider=SQLOLEDB.1;Password=;Persist Security
Info=True;User ID=sa;Initial Catalog=myDataBase;Data Source=myServer"

'Abrir la conexión a la base de datos
oCn.Open

'Crear y configurar el comando
Set oCmd.CommandStream = strIn
Set oCmd.ActiveConnection = oCn

'Configurar el dialecto para ejecutar plantillas de consultas XML
oCmd.Dialect = "{5D531CB2-E6Ed-11D2-B252-00C04F681B71}"

'Crear el objeto Stream de salida y asignarle el resultado de la
consulta
strOut.Open

oCmd.Properties("Output Stream") = strOut

oCmd.Execute , , adExecuteStream

strOut.Position = 0

'Obtener el XML resultante
strXML = strOut.ReadText(adReadAll)

'Cerrar la conexión a la base de datos
oCn.Close

'Destruir los objetos utilizados
Set oCmd = Nothing
Set oCn = Nothing
Set strIn = Nothing
Set strOut = Nothing

'Formatear el XML resultante
strXML = Replace(strXML, "<ROOT
xmlns:sql=""urn:schemas-microsoft-com:xml-sql"">", "")
strXML = Replace(strXML, "</ROOT>", "")
strXML = Replace(strXML, "<row", "<z:row")

'Agregar los elementos XML que dan forma al documento
strXMLFinal = "<xml
xmlns:s=""uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882""
xmlns:dt=""uuid:C2F41010-65B3-11d1-A29F-00AA00C14882""
xmlns:rs=""urn:schemas-microsoft-com:rowset"" xmlns:z=""#RowsetSchema"">"
strXMLFinal = strXMLFinal & "<s:Schema id=""RowsetSchema"">"
strXMLFinal = strXMLFinal & "<s:ElementType name=""row""
content=""eltOnly"">"
strXMLFinal = strXMLFinal & "<s:attribute type=""XValues""/>"
strXMLFinal = strXMLFinal & "<s:attribute type=""YValues""/>"
strXMLFinal = strXMLFinal & "<s:extends type=""rs:rowbase""/>"
strXMLFinal = strXMLFinal & "</s:ElementType>"
strXMLFinal = strXMLFinal & "<s:AttributeType name=""XValues""
rs:number=""1"" rs:nullable=""true"">"
strXMLFinal = strXMLFinal & "<s:datatype dt:type=""string""
dt:maxLength=""10""/>"
strXMLFinal = strXMLFinal & "</s:AttributeType>"
strXMLFinal = strXMLFinal & "<s:AttributeType name=""YValues""
rs:number=""2"">"
strXMLFinal = strXMLFinal & "<s:datatype dt:type=""i2""
dt:maxLength=""2"" rs:precision=""5"" rs:fixedlength=""true""
rs:maybenull=""false""/>"
strXMLFinal = strXMLFinal & "</s:AttributeType>"
strXMLFinal = strXMLFinal & "</s:Schema>"
strXMLFinal = strXMLFinal & "<rs:data>"
strXMLFinal = strXMLFinal & strXML
strXMLFinal = strXMLFinal & "</rs:data>"
strXMLFinal = strXMLFinal & "</xml>"

'Agregar los datos XML al DataSource
If (Len(oDSC.ConnectionString) = 0) Then
oDSC.ConnectionString = "provider=mspersist"
oDSC.UseXMLData = True
oDSC.XMLLocation = dscXMLEmbedded
oDSC.XMLDataTarget = strXMLFinal
End If

'Obtener una referencia a la colección de constantes del contenedor de
gráficos
Set oConstantes = oCS.Constants

'Limpiar el contenedor del gráfico
oCS.Clear

'Configurar el DataSource del contenedor del gráfico
oCS.DataSource = oDSC
oCS.DataMember = "ChartData"

'Configurar el gráfico
oCS.Charts(0).Type = oConstantes.chChartTypeLineMarkers
oCS.Charts(0).HasLegend = True
oCS.Charts(0).Legend.Position = oConstantes.chLegendPositionTop
oCS.Charts(0).HasTitle = True
oCS.Charts(0).Title.Caption = "Ejemplo con Datos XML"

'Configurar la serie de datos
'oCS.Charts(0).SeriesCollection(0).Name = "Tara (Tn.)"
'oCS.Charts(0).SeriesCollection(0).Caption = oSerie.Name
'oCS.Charts(0).SeriesCollection(0).Marker.Size = 4

'Configurar datos para el eje Y (YValues)
oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimCategories,
0, 0

'Configurar los datos para el eje X (XValues)
oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimValues, 0, 1

'Configurar el Tick para el eje
oChart.Axes(oConstantes.chAxisPositionBottom).TickLabelSpacing =
oChart.SeriesCollection(0).Points.Count / 10

'Exportar el gráfico a un archivo de imagen
oCS.ExportPicture "c:\chart.gif", "gif", 330, 230

'Destruir los objetos utilizados
Set oConstantes = Nothing
Set oCS = Nothing
Set oDSC = Nothing
End Sub

And XML source is:

<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
<s:ElementType name="row" content="eltOnly">
<s:attribute type="XValues"/>
<s:attribute type="YValues"/>
<s:extends type="rs:rowbase"/>
</s:ElementType>
<s:AttributeType name="XValues" rs:number="1" rs:nullable="true">
<s:datatype dt:type="string" dt:maxLength="10"/>
</s:AttributeType>
<s:AttributeType name="YValues" rs:number="2">
<s:datatype dt:type="i2" dt:maxLength="2" rs:precision="5"
rs:fixedlength="true" rs:maybenull="false"/>
</s:AttributeType>
</s:Schema>
<rs:data>
<z:row XValues="AQ-2569" YValues="250.00"/>
<z:row XValues="PR-5236" YValues="360.25"/>
<z:row XValues="XS-5898" YValues="458.70"/>
<z:row XValues="XS-5898" YValues="458.70"/>
<z:row XValues="XS-5898" YValues="458.70"/>
<z:row XValues="AA-2368" YValues="253.60"/>
<z:row XValues="AA-2369" YValues="54.00"/>
<z:row XValues="HH-8569" YValues="253.69"/>
<z:row XValues="sq-8925" YValues="1000.00"/>
<z:row XValues="AQA-713" YValues="500.00"/>
</rs:data>
</xml>

Thanks!
 
A

Alvin Bruney [MVP - ASP.NET]

The parameters you are passing in are not valid. See the setdata method to
figure out the correct parameters. For instance, you haven't passed in the
data to be plotted on the category axis

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc
 
C

César Juan Viñas Arias

Hello,

Thanks for your answer.

I have done some modifications to code, I have this lines now:

oCS.SetData chDimCategories, oConstantes.chDataLiteral, 0

'Configurar los datos para el eje X (XValues)
oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimValues,
oConstantes.chDataLiteral, 1

There are not errors thrown, but my graphic is empty (see the atachment
please).

Any help is welcome

Thanks.

Alvin Bruney said:
The parameters you are passing in are not valid. See the setdata method to
figure out the correct parameters. For instance, you haven't passed in the
data to be plotted on the category axis

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc
César Juan Viñas Arias said:
Hi,

I have a problem, I'm building a solution using OWC Chart with XML
DataSourse in ASP, but there is an error that I can't resolve. Please,
anyone can help me?

The error is in this line of code:

oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimCategories,
0,
0

and the message is:

Runtime Error '1004'

Invalid Parameter

This the code in Visual Basic:

Private Sub Form_Load()
Dim oCn As New ADODB.Connection 'Conexión
Dim oCmd As New ADODB.Command 'Comando
Dim oDSC As New OWC10.DataSourceControl 'DataSourceControl para los
datos XML
Dim oCS As New OWC10.ChartSpace 'ChartSpace
Dim oConstantes 'Constantes del ChartSpace
Dim strSQL As String 'Sentencia SQL
Dim strIn As New Stream 'Stream para el ingreso de datos
Dim strOut As New Stream 'Stream para los datos de salida
Dim strXML As String 'XML obtenido de la consulta a
la base de datos
Dim strXMLFinal As String 'XML formateado

'Generar la sentencia SQL que devolverá los datos
strSQL = "<ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql'>"
strSQL = strSQL & "<sql:query>"
strSQL = strSQL & "SELECT VM_PLATE_F001 AS XValues, VM_TARA_F006 AS
YValues FROM TABLE_061_VEHICLE_MAINTENANCE WHERE FLAG_LAST = 1 FOR XML RAW"
strSQL = strSQL & "</sql:query>"
strSQL = strSQL & "</ROOT>"

'Crear el objeto Stream de entrada y asignarle la plantilla de la
consulta
strIn.Open
strIn.WriteText strSQL, adWriteChar
strIn.Position = 0

'Crear y configurar la conexión a la base de datos
oCn.ConnectionString = "Provider=SQLOLEDB.1;Password=;Persist Security
Info=True;User ID=sa;Initial Catalog=myDataBase;Data Source=myServer"

'Abrir la conexión a la base de datos
oCn.Open

'Crear y configurar el comando
Set oCmd.CommandStream = strIn
Set oCmd.ActiveConnection = oCn

'Configurar el dialecto para ejecutar plantillas de consultas XML
oCmd.Dialect = "{5D531CB2-E6Ed-11D2-B252-00C04F681B71}"

'Crear el objeto Stream de salida y asignarle el resultado de la
consulta
strOut.Open

oCmd.Properties("Output Stream") = strOut

oCmd.Execute , , adExecuteStream

strOut.Position = 0

'Obtener el XML resultante
strXML = strOut.ReadText(adReadAll)

'Cerrar la conexión a la base de datos
oCn.Close

'Destruir los objetos utilizados
Set oCmd = Nothing
Set oCn = Nothing
Set strIn = Nothing
Set strOut = Nothing

'Formatear el XML resultante
strXML = Replace(strXML, "<ROOT
xmlns:sql=""urn:schemas-microsoft-com:xml-sql"">", "")
strXML = Replace(strXML, "</ROOT>", "")
strXML = Replace(strXML, "<row", "<z:row")

'Agregar los elementos XML que dan forma al documento
strXMLFinal = "<xml
xmlns:s=""uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882""
xmlns:dt=""uuid:C2F41010-65B3-11d1-A29F-00AA00C14882""
xmlns:rs=""urn:schemas-microsoft-com:rowset"" xmlns:z=""#RowsetSchema"">"
strXMLFinal = strXMLFinal & "<s:Schema id=""RowsetSchema"">"
strXMLFinal = strXMLFinal & "<s:ElementType name=""row""
content=""eltOnly"">"
strXMLFinal = strXMLFinal & "<s:attribute type=""XValues""/>"
strXMLFinal = strXMLFinal & "<s:attribute type=""YValues""/>"
strXMLFinal = strXMLFinal & "<s:extends type=""rs:rowbase""/>"
strXMLFinal = strXMLFinal & "</s:ElementType>"
strXMLFinal = strXMLFinal & "<s:AttributeType name=""XValues""
rs:number=""1"" rs:nullable=""true"">"
strXMLFinal = strXMLFinal & "<s:datatype dt:type=""string""
dt:maxLength=""10""/>"
strXMLFinal = strXMLFinal & "</s:AttributeType>"
strXMLFinal = strXMLFinal & "<s:AttributeType name=""YValues""
rs:number=""2"">"
strXMLFinal = strXMLFinal & "<s:datatype dt:type=""i2""
dt:maxLength=""2"" rs:precision=""5"" rs:fixedlength=""true""
rs:maybenull=""false""/>"
strXMLFinal = strXMLFinal & "</s:AttributeType>"
strXMLFinal = strXMLFinal & "</s:Schema>"
strXMLFinal = strXMLFinal & "<rs:data>"
strXMLFinal = strXMLFinal & strXML
strXMLFinal = strXMLFinal & "</rs:data>"
strXMLFinal = strXMLFinal & "</xml>"

'Agregar los datos XML al DataSource
If (Len(oDSC.ConnectionString) = 0) Then
oDSC.ConnectionString = "provider=mspersist"
oDSC.UseXMLData = True
oDSC.XMLLocation = dscXMLEmbedded
oDSC.XMLDataTarget = strXMLFinal
End If

'Obtener una referencia a la colección de constantes del contenedor de
gráficos
Set oConstantes = oCS.Constants

'Limpiar el contenedor del gráfico
oCS.Clear

'Configurar el DataSource del contenedor del gráfico
oCS.DataSource = oDSC
oCS.DataMember = "ChartData"

'Configurar el gráfico
oCS.Charts(0).Type = oConstantes.chChartTypeLineMarkers
oCS.Charts(0).HasLegend = True
oCS.Charts(0).Legend.Position = oConstantes.chLegendPositionTop
oCS.Charts(0).HasTitle = True
oCS.Charts(0).Title.Caption = "Ejemplo con Datos XML"

'Configurar la serie de datos
'oCS.Charts(0).SeriesCollection(0).Name = "Tara (Tn.)"
'oCS.Charts(0).SeriesCollection(0).Caption = oSerie.Name
'oCS.Charts(0).SeriesCollection(0).Marker.Size = 4

'Configurar datos para el eje Y (YValues)
oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimCategories,
0, 0

'Configurar los datos para el eje X (XValues)
oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimValues,
0,
1

'Configurar el Tick para el eje
oChart.Axes(oConstantes.chAxisPositionBottom).TickLabelSpacing =
oChart.SeriesCollection(0).Points.Count / 10

'Exportar el gráfico a un archivo de imagen
oCS.ExportPicture "c:\chart.gif", "gif", 330, 230

'Destruir los objetos utilizados
Set oConstantes = Nothing
Set oCS = Nothing
Set oDSC = Nothing
End Sub

And XML source is:

<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
<s:ElementType name="row" content="eltOnly">
<s:attribute type="XValues"/>
<s:attribute type="YValues"/>
<s:extends type="rs:rowbase"/>
</s:ElementType>
<s:AttributeType name="XValues" rs:number="1" rs:nullable="true">
<s:datatype dt:type="string" dt:maxLength="10"/>
</s:AttributeType>
<s:AttributeType name="YValues" rs:number="2">
<s:datatype dt:type="i2" dt:maxLength="2" rs:precision="5"
rs:fixedlength="true" rs:maybenull="false"/>
</s:AttributeType>
</s:Schema>
<rs:data>
<z:row XValues="AQ-2569" YValues="250.00"/>
<z:row XValues="PR-5236" YValues="360.25"/>
<z:row XValues="XS-5898" YValues="458.70"/>
<z:row XValues="XS-5898" YValues="458.70"/>
<z:row XValues="XS-5898" YValues="458.70"/>
<z:row XValues="AA-2368" YValues="253.60"/>
<z:row XValues="AA-2369" YValues="54.00"/>
<z:row XValues="HH-8569" YValues="253.69"/>
<z:row XValues="sq-8925" YValues="1000.00"/>
<z:row XValues="AQA-713" YValues="500.00"/>
</rs:data>
</xml>

Thanks!
 
C

César Juan Viñas Arias

Hello,

Thanks for your answer.

I have done some modifications to code, I have this lines now:

oCS.SetData chDimCategories, oConstantes.chDataLiteral, 0

'Configurar los datos para el eje X (XValues)
oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimValues,
oConstantes.chDataLiteral, 1

There are not errors thrown, but my graphic is empty (see the atachment
please).

Any help is welcome

Thanks.

Alvin Bruney said:
The parameters you are passing in are not valid. See the setdata method to
figure out the correct parameters. For instance, you haven't passed in the
data to be plotted on the category axis

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc
César Juan Viñas Arias said:
Hi,

I have a problem, I'm building a solution using OWC Chart with XML
DataSourse in ASP, but there is an error that I can't resolve. Please,
anyone can help me?

The error is in this line of code:

oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimCategories,
0,
0

and the message is:

Runtime Error '1004'

Invalid Parameter

This the code in Visual Basic:

Private Sub Form_Load()
Dim oCn As New ADODB.Connection 'Conexión
Dim oCmd As New ADODB.Command 'Comando
Dim oDSC As New OWC10.DataSourceControl 'DataSourceControl para los
datos XML
Dim oCS As New OWC10.ChartSpace 'ChartSpace
Dim oConstantes 'Constantes del ChartSpace
Dim strSQL As String 'Sentencia SQL
Dim strIn As New Stream 'Stream para el ingreso de datos
Dim strOut As New Stream 'Stream para los datos de salida
Dim strXML As String 'XML obtenido de la consulta a
la base de datos
Dim strXMLFinal As String 'XML formateado

'Generar la sentencia SQL que devolverá los datos
strSQL = "<ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql'>"
strSQL = strSQL & "<sql:query>"
strSQL = strSQL & "SELECT VM_PLATE_F001 AS XValues, VM_TARA_F006 AS
YValues FROM TABLE_061_VEHICLE_MAINTENANCE WHERE FLAG_LAST = 1 FOR XML RAW"
strSQL = strSQL & "</sql:query>"
strSQL = strSQL & "</ROOT>"

'Crear el objeto Stream de entrada y asignarle la plantilla de la
consulta
strIn.Open
strIn.WriteText strSQL, adWriteChar
strIn.Position = 0

'Crear y configurar la conexión a la base de datos
oCn.ConnectionString = "Provider=SQLOLEDB.1;Password=;Persist Security
Info=True;User ID=sa;Initial Catalog=myDataBase;Data Source=myServer"

'Abrir la conexión a la base de datos
oCn.Open

'Crear y configurar el comando
Set oCmd.CommandStream = strIn
Set oCmd.ActiveConnection = oCn

'Configurar el dialecto para ejecutar plantillas de consultas XML
oCmd.Dialect = "{5D531CB2-E6Ed-11D2-B252-00C04F681B71}"

'Crear el objeto Stream de salida y asignarle el resultado de la
consulta
strOut.Open

oCmd.Properties("Output Stream") = strOut

oCmd.Execute , , adExecuteStream

strOut.Position = 0

'Obtener el XML resultante
strXML = strOut.ReadText(adReadAll)

'Cerrar la conexión a la base de datos
oCn.Close

'Destruir los objetos utilizados
Set oCmd = Nothing
Set oCn = Nothing
Set strIn = Nothing
Set strOut = Nothing

'Formatear el XML resultante
strXML = Replace(strXML, "<ROOT
xmlns:sql=""urn:schemas-microsoft-com:xml-sql"">", "")
strXML = Replace(strXML, "</ROOT>", "")
strXML = Replace(strXML, "<row", "<z:row")

'Agregar los elementos XML que dan forma al documento
strXMLFinal = "<xml
xmlns:s=""uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882""
xmlns:dt=""uuid:C2F41010-65B3-11d1-A29F-00AA00C14882""
xmlns:rs=""urn:schemas-microsoft-com:rowset"" xmlns:z=""#RowsetSchema"">"
strXMLFinal = strXMLFinal & "<s:Schema id=""RowsetSchema"">"
strXMLFinal = strXMLFinal & "<s:ElementType name=""row""
content=""eltOnly"">"
strXMLFinal = strXMLFinal & "<s:attribute type=""XValues""/>"
strXMLFinal = strXMLFinal & "<s:attribute type=""YValues""/>"
strXMLFinal = strXMLFinal & "<s:extends type=""rs:rowbase""/>"
strXMLFinal = strXMLFinal & "</s:ElementType>"
strXMLFinal = strXMLFinal & "<s:AttributeType name=""XValues""
rs:number=""1"" rs:nullable=""true"">"
strXMLFinal = strXMLFinal & "<s:datatype dt:type=""string""
dt:maxLength=""10""/>"
strXMLFinal = strXMLFinal & "</s:AttributeType>"
strXMLFinal = strXMLFinal & "<s:AttributeType name=""YValues""
rs:number=""2"">"
strXMLFinal = strXMLFinal & "<s:datatype dt:type=""i2""
dt:maxLength=""2"" rs:precision=""5"" rs:fixedlength=""true""
rs:maybenull=""false""/>"
strXMLFinal = strXMLFinal & "</s:AttributeType>"
strXMLFinal = strXMLFinal & "</s:Schema>"
strXMLFinal = strXMLFinal & "<rs:data>"
strXMLFinal = strXMLFinal & strXML
strXMLFinal = strXMLFinal & "</rs:data>"
strXMLFinal = strXMLFinal & "</xml>"

'Agregar los datos XML al DataSource
If (Len(oDSC.ConnectionString) = 0) Then
oDSC.ConnectionString = "provider=mspersist"
oDSC.UseXMLData = True
oDSC.XMLLocation = dscXMLEmbedded
oDSC.XMLDataTarget = strXMLFinal
End If

'Obtener una referencia a la colección de constantes del contenedor de
gráficos
Set oConstantes = oCS.Constants

'Limpiar el contenedor del gráfico
oCS.Clear

'Configurar el DataSource del contenedor del gráfico
oCS.DataSource = oDSC
oCS.DataMember = "ChartData"

'Configurar el gráfico
oCS.Charts(0).Type = oConstantes.chChartTypeLineMarkers
oCS.Charts(0).HasLegend = True
oCS.Charts(0).Legend.Position = oConstantes.chLegendPositionTop
oCS.Charts(0).HasTitle = True
oCS.Charts(0).Title.Caption = "Ejemplo con Datos XML"

'Configurar la serie de datos
'oCS.Charts(0).SeriesCollection(0).Name = "Tara (Tn.)"
'oCS.Charts(0).SeriesCollection(0).Caption = oSerie.Name
'oCS.Charts(0).SeriesCollection(0).Marker.Size = 4

'Configurar datos para el eje Y (YValues)
oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimCategories,
0, 0

'Configurar los datos para el eje X (XValues)
oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimValues,
0,
1

'Configurar el Tick para el eje
oChart.Axes(oConstantes.chAxisPositionBottom).TickLabelSpacing =
oChart.SeriesCollection(0).Points.Count / 10

'Exportar el gráfico a un archivo de imagen
oCS.ExportPicture "c:\chart.gif", "gif", 330, 230

'Destruir los objetos utilizados
Set oConstantes = Nothing
Set oCS = Nothing
Set oDSC = Nothing
End Sub

And XML source is:

<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
<s:ElementType name="row" content="eltOnly">
<s:attribute type="XValues"/>
<s:attribute type="YValues"/>
<s:extends type="rs:rowbase"/>
</s:ElementType>
<s:AttributeType name="XValues" rs:number="1" rs:nullable="true">
<s:datatype dt:type="string" dt:maxLength="10"/>
</s:AttributeType>
<s:AttributeType name="YValues" rs:number="2">
<s:datatype dt:type="i2" dt:maxLength="2" rs:precision="5"
rs:fixedlength="true" rs:maybenull="false"/>
</s:AttributeType>
</s:Schema>
<rs:data>
<z:row XValues="AQ-2569" YValues="250.00"/>
<z:row XValues="PR-5236" YValues="360.25"/>
<z:row XValues="XS-5898" YValues="458.70"/>
<z:row XValues="XS-5898" YValues="458.70"/>
<z:row XValues="XS-5898" YValues="458.70"/>
<z:row XValues="AA-2368" YValues="253.60"/>
<z:row XValues="AA-2369" YValues="54.00"/>
<z:row XValues="HH-8569" YValues="253.69"/>
<z:row XValues="sq-8925" YValues="1000.00"/>
<z:row XValues="AQA-713" YValues="500.00"/>
</rs:data>
</xml>

Thanks!
 
A

Alvin Bruney [MVP - ASP.NET]

Here is an example you should be using. This is excerpted from the Black
Book, Chapter 3

objCSpace = new ChartSpaceClass();
//Add a chart in the ChartSpace.
ChChart objChart = objCSpace.Charts.Add (0);
//load values
string strValue = "17,23,-2,4,-17";
string strCategory = "Mon, Tues, Wed,Thurs,Fri";
//clear the chart
objChart.SeriesCollection[0].SetData (ChartDimensionsEnum.chDimCharts,
(int)ChartSpecialDataSourcesEnum.chDataNone, strCategories);


--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc
César Juan Viñas Arias said:
Hello,

Thanks for your answer.

I have done some modifications to code, I have this lines now:

oCS.SetData chDimCategories, oConstantes.chDataLiteral, 0

'Configurar los datos para el eje X (XValues)
oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimValues,
oConstantes.chDataLiteral, 1

There are not errors thrown, but my graphic is empty (see the atachment
please).

Any help is welcome

Thanks.

Alvin Bruney said:
The parameters you are passing in are not valid. See the setdata method to
figure out the correct parameters. For instance, you haven't passed in the
data to be plotted on the category axis

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc
César Juan Viñas Arias said:
Hi,

I have a problem, I'm building a solution using OWC Chart with XML
DataSourse in ASP, but there is an error that I can't resolve. Please,
anyone can help me?

The error is in this line of code:

oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimCategories,
0,
0

and the message is:

Runtime Error '1004'

Invalid Parameter

This the code in Visual Basic:

Private Sub Form_Load()
Dim oCn As New ADODB.Connection 'Conexión
Dim oCmd As New ADODB.Command 'Comando
Dim oDSC As New OWC10.DataSourceControl 'DataSourceControl para los
datos XML
Dim oCS As New OWC10.ChartSpace 'ChartSpace
Dim oConstantes 'Constantes del ChartSpace
Dim strSQL As String 'Sentencia SQL
Dim strIn As New Stream 'Stream para el ingreso de datos
Dim strOut As New Stream 'Stream para los datos de salida
Dim strXML As String 'XML obtenido de la
consulta
contenedor
 
C

César Juan Viñas Arias

No, there are problems yet... In your example you are setting a string with
colons as the source for the chart, but my data source is XML. Is thre in
that book an example like that? can you copy it here please?

Thanks again :)

Alvin Bruney said:
Here is an example you should be using. This is excerpted from the Black
Book, Chapter 3

objCSpace = new ChartSpaceClass();
//Add a chart in the ChartSpace.
ChChart objChart = objCSpace.Charts.Add (0);
//load values
string strValue = "17,23,-2,4,-17";
string strCategory = "Mon, Tues, Wed,Thurs,Fri";
//clear the chart
objChart.SeriesCollection[0].SetData (ChartDimensionsEnum.chDimCharts,
(int)ChartSpecialDataSourcesEnum.chDataNone, strCategories);


--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc
César Juan Viñas Arias said:
Hello,

Thanks for your answer.

I have done some modifications to code, I have this lines now:

oCS.SetData chDimCategories, oConstantes.chDataLiteral, 0

'Configurar los datos para el eje X (XValues)
oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimValues,
oConstantes.chDataLiteral, 1

There are not errors thrown, but my graphic is empty (see the atachment
please).

Any help is welcome

Thanks.
method
to
figure out the correct parameters. For instance, you haven't passed in the
data to be plotted on the category axis

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc
Hi,

I have a problem, I'm building a solution using OWC Chart with XML
DataSourse in ASP, but there is an error that I can't resolve. Please,
anyone can help me?

The error is in this line of code:

oCS.Charts(0).SeriesCollection(0).SetData
oConstantes.chDimCategories,
0,
0

and the message is:

Runtime Error '1004'

Invalid Parameter

This the code in Visual Basic:

Private Sub Form_Load()
Dim oCn As New ADODB.Connection 'Conexión
Dim oCmd As New ADODB.Command 'Comando
Dim oDSC As New OWC10.DataSourceControl 'DataSourceControl para los
datos XML
Dim oCS As New OWC10.ChartSpace 'ChartSpace
Dim oConstantes 'Constantes del ChartSpace
Dim strSQL As String 'Sentencia SQL
Dim strIn As New Stream 'Stream para el ingreso de
datos
Dim strOut As New Stream 'Stream para los datos de
salida
Dim strXML As String 'XML obtenido de la
consulta
a
la base de datos
Dim strXMLFinal As String 'XML formateado

'Generar la sentencia SQL que devolverá los datos
strSQL = "<ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql'>"
strSQL = strSQL & "<sql:query>"
strSQL = strSQL & "SELECT VM_PLATE_F001 AS XValues, VM_TARA_F006 AS
YValues FROM TABLE_061_VEHICLE_MAINTENANCE WHERE FLAG_LAST = 1 FOR XML
RAW"
strSQL = strSQL & "</sql:query>"
strSQL = strSQL & "</ROOT>"

'Crear el objeto Stream de entrada y asignarle la plantilla de la
consulta
strIn.Open
strIn.WriteText strSQL, adWriteChar
strIn.Position = 0

'Crear y configurar la conexión a la base de datos
oCn.ConnectionString = "Provider=SQLOLEDB.1;Password=;Persist Security
Info=True;User ID=sa;Initial Catalog=myDataBase;Data Source=myServer"

'Abrir la conexión a la base de datos
oCn.Open

'Crear y configurar el comando
Set oCmd.CommandStream = strIn
Set oCmd.ActiveConnection = oCn

'Configurar el dialecto para ejecutar plantillas de consultas XML
oCmd.Dialect = "{5D531CB2-E6Ed-11D2-B252-00C04F681B71}"

'Crear el objeto Stream de salida y asignarle el resultado de la
consulta
strOut.Open

oCmd.Properties("Output Stream") = strOut

oCmd.Execute , , adExecuteStream

strOut.Position = 0

'Obtener el XML resultante
strXML = strOut.ReadText(adReadAll)

'Cerrar la conexión a la base de datos
oCn.Close

'Destruir los objetos utilizados
Set oCmd = Nothing
Set oCn = Nothing
Set strIn = Nothing
Set strOut = Nothing

'Formatear el XML resultante
strXML = Replace(strXML, "<ROOT
xmlns:sql=""urn:schemas-microsoft-com:xml-sql"">", "")
strXML = Replace(strXML, "</ROOT>", "")
strXML = Replace(strXML, "<row", "<z:row")

'Agregar los elementos XML que dan forma al documento
strXMLFinal = "<xml
xmlns:s=""uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882""
xmlns:dt=""uuid:C2F41010-65B3-11d1-A29F-00AA00C14882""
xmlns:rs=""urn:schemas-microsoft-com:rowset"" xmlns:z=""#RowsetSchema"">"
strXMLFinal = strXMLFinal & "<s:Schema id=""RowsetSchema"">"
strXMLFinal = strXMLFinal & "<s:ElementType name=""row""
content=""eltOnly"">"
strXMLFinal = strXMLFinal & "<s:attribute type=""XValues""/>"
strXMLFinal = strXMLFinal & "<s:attribute type=""YValues""/>"
strXMLFinal = strXMLFinal & "<s:extends type=""rs:rowbase""/>"
strXMLFinal = strXMLFinal & "</s:ElementType>"
strXMLFinal = strXMLFinal & "<s:AttributeType name=""XValues""
rs:number=""1"" rs:nullable=""true"">"
strXMLFinal = strXMLFinal & "<s:datatype dt:type=""string""
dt:maxLength=""10""/>"
strXMLFinal = strXMLFinal & "</s:AttributeType>"
strXMLFinal = strXMLFinal & "<s:AttributeType name=""YValues""
rs:number=""2"">"
strXMLFinal = strXMLFinal & "<s:datatype dt:type=""i2""
dt:maxLength=""2"" rs:precision=""5"" rs:fixedlength=""true""
rs:maybenull=""false""/>"
strXMLFinal = strXMLFinal & "</s:AttributeType>"
strXMLFinal = strXMLFinal & "</s:Schema>"
strXMLFinal = strXMLFinal & "<rs:data>"
strXMLFinal = strXMLFinal & strXML
strXMLFinal = strXMLFinal & "</rs:data>"
strXMLFinal = strXMLFinal & "</xml>"

'Agregar los datos XML al DataSource
If (Len(oDSC.ConnectionString) = 0) Then
oDSC.ConnectionString = "provider=mspersist"
oDSC.UseXMLData = True
oDSC.XMLLocation = dscXMLEmbedded
oDSC.XMLDataTarget = strXMLFinal
End If

'Obtener una referencia a la colección de constantes del
contenedor
de
gráficos
Set oConstantes = oCS.Constants

'Limpiar el contenedor del gráfico
oCS.Clear

'Configurar el DataSource del contenedor del gráfico
oCS.DataSource = oDSC
oCS.DataMember = "ChartData"

'Configurar el gráfico
oCS.Charts(0).Type = oConstantes.chChartTypeLineMarkers
oCS.Charts(0).HasLegend = True
oCS.Charts(0).Legend.Position = oConstantes.chLegendPositionTop
oCS.Charts(0).HasTitle = True
oCS.Charts(0).Title.Caption = "Ejemplo con Datos XML"

'Configurar la serie de datos
'oCS.Charts(0).SeriesCollection(0).Name = "Tara (Tn.)"
'oCS.Charts(0).SeriesCollection(0).Caption = oSerie.Name
'oCS.Charts(0).SeriesCollection(0).Marker.Size = 4

'Configurar datos para el eje Y (YValues)
oCS.Charts(0).SeriesCollection(0).SetData oConstantes.chDimCategories,
0, 0

'Configurar los datos para el eje X (XValues)
oCS.Charts(0).SeriesCollection(0).SetData
oConstantes.chDimValues,
0,
1

'Configurar el Tick para el eje
oChart.Axes(oConstantes.chAxisPositionBottom).TickLabelSpacing =
oChart.SeriesCollection(0).Points.Count / 10

'Exportar el gráfico a un archivo de imagen
oCS.ExportPicture "c:\chart.gif", "gif", 330, 230

'Destruir los objetos utilizados
Set oConstantes = Nothing
Set oCS = Nothing
Set oDSC = Nothing
End Sub

And XML source is:

<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
<s:ElementType name="row" content="eltOnly">
<s:attribute type="XValues"/>
<s:attribute type="YValues"/>
<s:extends type="rs:rowbase"/>
</s:ElementType>
<s:AttributeType name="XValues" rs:number="1" rs:nullable="true">
<s:datatype dt:type="string" dt:maxLength="10"/>
</s:AttributeType>
<s:AttributeType name="YValues" rs:number="2">
<s:datatype dt:type="i2" dt:maxLength="2" rs:precision="5"
rs:fixedlength="true" rs:maybenull="false"/>
</s:AttributeType>
</s:Schema>
<rs:data>
<z:row XValues="AQ-2569" YValues="250.00"/>
<z:row XValues="PR-5236" YValues="360.25"/>
<z:row XValues="XS-5898" YValues="458.70"/>
<z:row XValues="XS-5898" YValues="458.70"/>
<z:row XValues="XS-5898" YValues="458.70"/>
<z:row XValues="AA-2368" YValues="253.60"/>
<z:row XValues="AA-2369" YValues="54.00"/>
<z:row XValues="HH-8569" YValues="253.69"/>
<z:row XValues="sq-8925" YValues="1000.00"/>
<z:row XValues="AQA-713" YValues="500.00"/>
</rs:data>
</xml>

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top