Reading a CSV or JSON Formatted DATA FILE into the HTML5-based Chart instead of Embedding it into the CODE?

55 views
Skip to first unread message

Lee Deneault

unread,
Sep 1, 2016, 6:16:54 PM9/1/16
to Google Visualization API
Dear Google Groups,

Instead of EMBEDDING the following DATA, seen below, into HTML5 Code...

    function drawChart() {
       
var data = google.visualization.arrayToDataTable([
         
['Year', 'Sales', 'Expenses'],
         
['2004',  1000,      400],
         
['2005',  1170,      460],
         
['2006',  660,       1120],
         
['2007',  1030,      540]
       
]);

I would like to be able to actually READ this very same data from either a CSV or a JSON formatted DATA FILE!
Needless to say, any insight would be GREATLY appreciated!
Thanks, in advance, for your time and consideration!
Best Regards,
LEE

Simon Roberts

unread,
Sep 9, 2016, 5:14:03 AM9/9/16
to Google Visualization API
Hello Lee,

Maybe something like this -

$(document).ready(function () {

        $.ajax({
           url: "/Reporting/LeaveList",
           data: "",
           dataType: "json",
           type: "POST",
           contentType: "application/json; chartset=utf-8",
           success: function (data) {
               chartData = data;
           },
           error: function () {
               alert("Error loading data! Please try again.");
           }
       }).done(function () {
           // after complete loading data
           google.setOnLoadCallback(drawChart);
            drawChart();
        });
   });


Lee Deneault

unread,
Sep 9, 2016, 9:34:44 AM9/9/16
to google-visua...@googlegroups.com
Hi Simon!

...WOW!

Many thanks...!

I am truly very eager to try this out and I promise to get back to you!

Thanks again!

LEE


 

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/styZhyyAGMA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/4d244bdd-b529-4b5c-a34e-48e0b3dc971b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages