Page 1 of 1

ADO Database access - PROBLEM

Posted: Fri Dec 17, 2004 1:07 pm
by 9080645
hello,

I've tried to collect data from SQL Server 2000 and add the data directly to chart. I use ASP pages and ActiveX TeeChart version 6.0.0.5. The basic data fetch is as follows:

dim MyChart : set MyChart = Server.CreateObject("TeeChart.TChart")
dim data : set data = Server.CreateObject("ADODB.Connection")
dim record : set record = Server.CreateObject("ADODB.RecordSet")
data.open "DSN=xxx;Database=yyy;UID=uname;PWD=pwd", "", ""

for i=0 to Session("NoCircuits")-1
if circuit(i).plotI=1 then
strQuery="SELECT DateTime, OutValue FROM tblData WHERE CircuitNo=" & i & " AND Type='I' AND CaseID=" & Session("CaseID") & " AND MONTH(DateTime)=6 AND YEAR(DateTime)=YEAR(GETDATE())"
record.open strQuery,data,3,3
response.write record.RecordCount & "<br>"
MyChart.AddSeries(6)
MyChart.Series(seriesIndex).DataSource = Record
MyChart.Series(seriesIndex).YValues.ValueSource = "OutValue"
MyChart.Series(seriesIndex).LabelsSource = "DateTime"
MyChart.Series(seriesIndex).CheckDataSource
MyChart.Series(newSeries).VerticalAxisCustom = axCurrent
end if
next


In the example above I fetch current data for various circuits, and if the client has selected the current to be plotted (=circuit(x).plotI=1). I fetch the data from the database, and get 19 records (for example).

How can I set the data to Series0 (and further data to Series1, Series2, etc.)? When I load the page, the graph is empty. I need full example codes of how to do this.

I've tried to search the tutorials and manuals etc. but I cannot seem to add data to any series directly from database....

Thanks for any advises.

mike turner

Posted: Mon Dec 20, 2004 10:34 am
by Pep
Hi Mike,

here, a simple example which gets data from Northwind Database :

Code: Select all

<!--METADATA NAME="TeeChart Pro v5 ActiveX Control" TYPE="TypeLib"
UUID="{B6C10482-FB89-11D4-93C9-006008A7EED4}"-->

%

  'Send output to browser. 1st time in call CreatePage
  'then call RunChart method to build Chart contents
    Response.BinaryWrite(RunChart)

  Function RunChart()

    dim img
    dim Chart
    dim MyVar

    'Create Chart
    Set Chart = CreateObject("TeeChart.TChart")

    'Setup Series
    Chart.AddSeries(scBar)
    'Chart.AddSeries(scBar)
    'Chart.Series(0).Marks.Visible=False
    'Chart.Series(0).asBar.BarStyle=bsPyramid
    'Chart.Series(1).Marks.Visible=False
    'Chart.Series(1).asBar.BarStyle=bsPyramid

    'Chart appearance
    'Chart.Legend.Visible=False
    Chart.Legend.TextStyle = ltsPercent
    Chart.Axis.Bottom.Labels.Angle=90
    Chart.Height=400
    Chart.Width=500
    Chart.Panel.Gradient.Visible=True
    Chart.Header.Text(0)="TeeChart NorthWind example"
    Chart.Header.Font.Bold=True
    Chart.Axis.Bottom.Title.Caption="OrderID"
    Chart.Axis.Bottom.Title.Font.Bold=True
    Chart.Axis.Left.Title.Font.Bold=True

   'Connect to database
    Set Conn = Server.CreateObject("ADODB.Connection")
    Set RSt = Server.CreateObject("ADODB.RecordSet")
    Conn.Open "DSN=Northwind;Initial Catalog=Northwind;"
  
   Rst.Open "select * from [Orders] where [ShipCountry] = 'France'", Conn, 1, 1

    'Connect Series to Recordset
      Chart.Series(0).Datasource = RSt
      Chart.Series(0).LabelsSource="CustomerID"
      Chart.Series(0).YValues.ValueSource="Freight"
      'Chart.Series(1).Datasource = RSt
      'Chart.Series(1).LabelsSource="Country"
      'Chart.Series(1).YValues.ValueSource="Value2"
    
    'Cleanup and set Chart to send to browser
    Rst.close
    Conn.close
    Set Rst=nothing
    Set Conn=nothing
    img=Chart.Export.asPNG.SaveToStream
    'Set Chart=nothing
    RunChart=img

  End function

%>