How to save visualization chart as an image on server programatically.

3,934 views
Skip to first unread message

Ghulam Jafar

unread,
May 25, 2015, 2:13:06 AM5/25/15
to google-visua...@googlegroups.com
how can i save the chart as an image on server. I am using the following code.

<head runat="server">
    <title></title>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load("visualization", "1", { packages: ["corechart"] });
        google.setOnLoadCallback(drawChart);
        function drawChart() {
            var data = google.visualization.arrayToDataTable([
              ['Month', 'Bad', 'Good', 'Very Good', 'Excellent'],
              ['Jan', 10, 40, 30, 20],
              ['Feb', 08, 30, 30, 32],
              ['Mar', 10, 20, 20, 50],
              ['Apr', 15, 15, 40, 30]
            ]);

            var options = {
                chart: {
                    title: 'Feedback Odenplan'
                },
                series: {
                    0: { color: 'Red' },
                    1: { color: 'Brown' },
                    2: { color: 'Yellow' },
                    3: { color: 'Green' }
                }
            };

            var chart = new google.visualization.ColumnChart(document.getElementById('columnchart_material'));

            chart.draw(data, options);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div id="columnchart_material" style="width: 900px; height: 500px;"></div>
    </form>
</body>
</html>

Ghulam Jafar

unread,
May 26, 2015, 7:51:44 AM5/26/15
to google-visua...@googlegroups.com
Please Help, Actually i want to save images(png,jpg) on server. How i can do in this code?

Daniel LaLiberte

unread,
May 26, 2015, 8:40:00 AM5/26/15
to google-visua...@googlegroups.com
Ghulam,

Since Google Charts is a client-side library that runs in browsers, you can only generate charts in the browser.  However, you could generate an image from the chart using the getImageURI() method described on https://developers.google.com/chart/interactive/docs/printing and then submit the image URI back to your server, which could then fetch the image using a simplified client that runs in your server.  This page might help you if you are using php on your server: http://stackoverflow.com/questions/11511511/how-to-save-a-png-image-server-side-from-a-base64-data-string


--
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 google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA

Ifiok Idiang

unread,
Dec 1, 2018, 12:59:05 AM12/1/18
to Google Visualization API
Hi Ghulam,
Did you get around this and if yes, how?
Reply all
Reply to author
Forward
0 new messages