Database Connections: ODBC (MySQL) Data Source

NOTE: Before trying to get this example to work, please make sure that the Basic Test worked.

In order for this example to work, you will need to set up the example mysql database included with this demo, as well as setup an ODBC data source for the mysql database in the Chilisoft Administrator. Follow these instructions: odbc_mysql_instructions.html


<% ' Instantiate Database Objects set myconn = Server.CreateObject("ADODB.Connection") set command = Server.CreateObject("ADODB.Command") set recordset = Server.CreateObject("ADODB.Recordset") ' Connect to Database myconn.Open "dsn=employees" ' Execute Query command.ActiveConnection = myconn command.CommandText="select firstname, lastname, weekhours, status FROM employee" set recordset = command.Execute() ' Parse through the record set and ' build a PCScript String containing the data to send to PopChart Server dim pcScript ' Transpose the data because it comes in the wrong way pcScript = "graph.Transposed(true)" ' Start by building data categories pcScript = pcScript & "graph.setCategories(Hours Worked)" ' Now build the data series do while not recordset.EOF pcScript = pcScript & "graph.setSeries(" & recordset("firstname") & " " & recordset("lastname") & ";" & recordset("weekhours") & ")" if recordset("status") = "78" then pcScript = pcScript & "graph.addNote(Hours Worked," & recordset("firstname") & " " & recordset("lastname") & ",On Leave)" recordset.MoveNext loop ' Close Connection myconn.close ' Set Title of PopChart pcScript = pcScript & "title.setText(Employee Work Hours\nWeek of August 26)" ' Change Data Label Format pcScript = pcScript & "graph.setDataLabelFormat(%_CATEGORY_NAME: %_VALUE hrs)" ' Instantiate PopChart Embedder Object set myPopChart = Server.CreateObject("PopChart.Embedder") ' Set PopChart Server Addresses myPopChart.externalServerAddress = "http://localhost:2001" myPopChart.internalCommPortAddress = "http://localhost:2002" ' Set Appearance File myPopChart.appearanceFile = "examples/apfiles/bar.pcxml" ' Set PopChart Image Size and format myPopChart.width = 540 myPopChart.height = 330 myPopChart.imageType = "FLASH" ' Set PCScript myPopChart.pcScript = pcScript ' Use PCXML to add SingleSeriesMultiColor myPopChart.addPCXML("") ' Write PopChart image to web page Response.Write myPopChart.getEmbeddingHTML() Response.Write "

PCScript generated by SQL query:

" Response.Write myPopChart.pcScript %>

If you see example data for car rentals in Atlanta and Boston, this worked!