Heres a sample web service - sorry for the VB.net... ;) Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.Data Imports System.Data.SqlClient Imports System.Web.Script.Services
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. <System.Web.Script.Services.ScriptService()> _ <WebService(Namespace:="http://tempuri.org/")> _ <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Public Class Lifecycle Inherits System.Web.Services.WebService <WebMethod()> _ <ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)> _ Public Function GetAllData() As String Dim myDT As DataTable = GetData("SELECT * FROM mySQLTable", "mySQLTable") Return DataTableToJSON(myDT) End Function Private Function GetData(SQLCommand As String, TableName As String) As DataTable Dim myCMD As String = "" Dim conn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString) conn.Open() Dim myDA As New SqlDataAdapter(SQLCommand, conn) Dim dsData As New DataSet(TableName) dsData.EnforceConstraints = False myDA.FillSchema(dsData, SchemaType.Source, TableName) myDA.Fill(dsData, TableName) Dim tblDT As DataTable tblDT = dsData.Tables(TableName) conn.Close() Return tblDT End Function Private Function DataTableToJSON(myDT As DataTable) As String Dim serializer As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer() serializer.MaxJsonLength = Int32.MaxValue Dim rows As New List(Of Dictionary(Of String, Object)) Dim row As Dictionary(Of String, Object) For Each dr As DataRow In myDT.Rows row = New Dictionary(Of String, Object) For Each col As DataColumn In myDT.Columns row.Add(col.ColumnName, dr(col)) Next rows.Add(row) Next Return serializer.Serialize(rows) End Function End Class >From your javascript setting up the Charts, its then simply a matter of calling this service to get the data.... function getAllData() { $.ajax({ type: 'GET', dataType: 'json', contentType: 'application/json', url: '/Services/Lifecycle.asmx/GetAllData', success: function (response) { setTable(response.d); } }); } function setTable(dataValues) { var result = JSON.parse(dataValues); var data = new google.visualization.DataTable(); data.addColumn('string', 'ColumnName'); data.addColumn('datetime', 'Start'); data.addColumn('datetime', 'End'); data.addColumn('string', 'ProductType'); data.addColumn('number', 'EndDateYear'); for (var i = 0; i < result.length; i++) { data.addRow([ result[i].FullProduct, result[i].Event, new Date(result[i].StartDateYear, result[i].StartDateMonth - 1, result[i].StartDateDay), new Date(result[i].EndDateYear, result[i].EndDateMonth - 1, result[i].EndDateDay), result[i].ProductType, result[i].EndDateYear ]); } doCharts(data); } -- You received this message because you are subscribed to the Google Groups "Google Visualization API" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-visualization-api. For more options, visit https://groups.google.com/d/optout.
