This example creates a chart from data returned by an SQL query. A data source control is used to connect to the SQL database and run the query. The chart workspace data source is then set to the data source control, and the data member is set to the created recordset. Finally, the SetData method is used to set the chart categories and values using fields in the recordset.
To run this example, copy the remainder of the text in this topic into an HTML page.
<object id=ChartSpace1 classid=CLSID:0002E500-0000-0000-C000-000000000046 style="width:100%;height:480"></object>
<object id=DataSourceControl1 classid=CLSID:0002E530-0000-0000-C000-000000000046></object>
<script language=vbs>
Sub window_onLoad()
Dim rsd
DataSourceControl1.ConnectionString = "DRIVER={SQL Server};SERVER=vdata;DATABASE=pubs;UID=sa;PWD=;"
Set rsd = DataSourceControl1.RecordsetDefs.AddNew("SELECT lname, job_lvl FROM Employee ORDER BY lname DESC", 3)
Set c = ChartSpace1.Constants
ChartSpace1.DataSource = DataSourceControl1
ChartSpace1.DataMember = rsd.Name
ChartSpace1.Charts.Add
ChartSpace1.Charts(0).Type = c.chChartTypeBarClustered
ChartSpace1.Charts(0).SetData c.chDimCategories, 0, "lname"
ChartSpace1.Charts(0).SetData c.chDimValues, 0, "job_lvl"
End Sub
</script>