>
> 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 
> <http://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', 'ColumnName2');
>
>     for (var i = 0; i < result.length; i++) {
>         data.addRow([
>             result[i].ColumnName,
>             result[i].ColumnName2
>         ]);
>     }
>     doCharts(data);
> }
>
>
Hope that makes sense - in the web service you can manipulate the data, do 
anything .Net to it you deem fit, that then gets translated into JSON and 
served on request to your javascript file.

-- 
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.

Reply via email to