Skip to main content

Problem with Google visualization API- DataTable

One of the most widely charting API is the Google visualization API. Which enables the developers to create charts using
javascript at runtime by supplying the data in a particular format.
I had to use this API with ASP.Net. So the major problem in
front of me was how to transfer the data in my database to the client side JavaScript.
Which I could solve by using .ashx pages. I created my own class for
transforming .Net DataTable to a JSON string.
The final problem that I faced was that when I transferred the
JSON string to the client side using Jquery AJAX method though it was parsing
the JSON correctly. The Google DataTable was being formed correctly the final
AnnonatedTimeline I was trying to make with that JSON data was showing errors. So
to debug I created a Google DataTable manually and converted it into JSON using
the method it provides. The JSON string that was given out by Google’s very own
DataTable and my JSON string were exact match still, still mine was showing
errors.
After hours of looking into the problem I finally could
solve it. Because I was using Jquery AJAX method which was parsing the JSON
string into the final objects and the Google Datatable’s date format does not
go by the standards so the final field which was supposed to be of “Date” type
was actually string
v              "Date(2011,2, 10)"          String
After realizing this the solution was simple and it was to
change the JavaScript object which I was using to create Google DataTable back
to a JSON string using the code below
J
data = JSON.stringify(data);
var dataTable = new
google.visualization.DataTable(data, 0.6);


Other userfull resources
Google DataTable
.Net DataTable
Jquery AJAX
JSON - Java Script Object Notation

Comments

  1. json is a very interesting language to be used. very good tutorial and can hopefully help me in building json in the application that I created for this lecture. thank you

    ReplyDelete
  2. Creating a good blog and also maintaining it is the real challenge
    QU-IT & QU

    ReplyDelete
  3. very interesting post!Thanks for sharing your experience suggestions.
    Articles submission sites
    Guest posting sites

    ReplyDelete

Post a Comment

Popular posts from this blog

Data manipulation in azure development storage by using web services – workaround

While developing the Azure project this was the biggest problem I came across and being just a newcomer in this area I could not solve it. So I figured a way around that worked perfectly well and then I used it to finally make a working project. Nearly all the solutions I came across in the different portals were about the same problem without the development storage anywhere in question but for the people who first need to make a working solution in the development storage using anything like the VS2010 there was no help nowhere. The problem was that while accessing data which was stored in a blob in cloud storage through a web service by a Silverlight client. It gives an impression to the storage of the cloud that this is being done by cross site scripting (this is what I got from all the different sources I read) and because this was not allowed the cloud project (webrole in my case) was blocking the request and was returning nothing in return. So this solution that I figured out i

ParameterLess construct

When I was creating my first cloud app that’s used Microsoft Azure for storage and computation purposes I came across a strange problem which wasn’t related to the Azure itself but was more related to the c# and the .net framework. When I was writing the code I made a Class which had no parameter less construct. Objects of this class were then used in the program. Because this class was derived from Ienumerator I could actually user Foreach() on the objects of this class but to my surprise the code shown below was showing error at the highlighted line. using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.WindowsAzure.StorageClient; using Microsoft.WindowsAzure; namespace WebRole1 { public class mspDataServiceContext : TableServiceContext { public mspDataServiceContext(string baseAddress, StorageCredentials credentials) : base(baseAddress, credentials) { } static int c; public IQueryable<msp> msps { get { retur

Dynaminism in .Net 4.0

few dayz ago came across THIS question. the solution to this can easily be figured out by the new dynamic features introduced in .Net 4.0. i have made a project to demonstrate this. the main code in the project goes like this public   static   dynamic [] GetDynamicObject( DataTable  dt,  Dictionary < string ,  string > mapping)         {              List < dynamic > returnList =  new   List < dynamic >();              foreach  ( DataRow  row  in  dt.Rows)             {                  dynamic  obj =  new   ExpandoObject ();                  var  objectDic = ( IDictionary < string ,  object >)obj;                  foreach  ( DataColumn  column  in  dt.Columns)                 {                     objectDic.Add(mapping!= null ?mapping.ContainsKey(column.ColumnName) ? mapping[column.ColumnName] : column.ColumnName:column.ColumnName,row[column]);                 }                 returnList.Add(obj);             }              return  returnLis