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. This is a nice article..
    Its very easy to understand ..
    And this article is using to learn something about it..

    c#, dot.net, php tutorial

    Thanks a lot..!

    ReplyDelete
  2. 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
  3. Creating a good blog and also maintaining it is the real challenge
    QU-IT & QU

    ReplyDelete

Post a Comment

Popular posts from this blog

Customized Online Learning Dangerous as it is Necessary

The recent uprise in Online Learning Platform like Pluralsight, Coursera has raised some important questions over traditional learning system and also on traditional examination systems.
The fact that online learning courses are derived from what users need and not what should be actually taught has also raised serious concerns about what is finally going inside the heads of professionals.

Traditional system while teaching any subject also includes major things that might never be used in real life but still is important to actual context of that particular subject. The syllabus goes through the hands of experts before finally reaching the learners. Online education / Videos have completely disrupted this system and now only what is needed is taught leaving out all the motivational factors and context of the subject that brings glamour and other related attributes to the identity of the subject.

So yes while system has to evolve to teach students more than C++ in today's world bu…

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

publicstaticdynamic[] GetDynamicObject(DataTable dt, Dictionary<string, string> mapping)
        {
List<dynamic> returnList = newList<dynamic>();
foreach (DataRow row in dt.Rows)
            {
dynamic obj = newExpandoObject();
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 returnList.ToArray();
        }The static method here named "GetDynamicObject" simply takes a data table(which can be populated by the data in the database) and a dictionary of…