SharePoint Pals
 | Sign In
Google Charts in SharePoint
by Ahamed Fazil Buhari 20 Aug 2016
SharePoint Developer
Today  :   7     Total  :    1176

Hello everyone, in this article we will look into how to embed google charts into our SharePoint page.

When it comes to the end user, the look & feel and how we display the actual data is very important. One of the best way to show the data is by using Charts and there are lots of charts available, each one has its own advantage. We need to pick up the right chart to display the right data.

Here comes the big picture “Google Charts” to satisfy the above stuff which we talked about. I’m not going to explain much about ‘what Google Chart is’, you can find it here in there official site Google Charts.

I can say, there will be very least or 0% work on CSS, HTML when we create this Google chart. Definitely, this will save your time. A <div></div> tag in your page that’s all we want. The most common method to use Google Chart is by using JavaScript.

Let’s consider that we need to show the data available inside SharePoint list as a Bar Chart,


In this example, I’ve used JQuery, SPServices (To retrieve list data) and added below scripting.

 <script type="text/javascript" src="../SiteAssets/jquery-1.10.2.js"></script>
 <script type="text/javascript" src="../SiteAssets/jquery.SPServices-2014.02.min.js"></script>
 <script type="text/javascript" src=""></script>
 <script type="text/javascript">
 //Declared Json Obj globally so that it can be retrieved from anywhere
 var jsonObj_Chart = {};
 $(document).ready(function () {
 /* google.charts.load("current", {packages:['corechart']}); -> should be loaded only once, if we want to have multiple charts in our page then please have this in common and load only once.
 Here, in this example I've used "google.charts.load('current', {'packages':['bar']});",
 just because google.charts.Bar is not a constructor. So need to specify this explicitly
 google.charts.load('current', {'packages':['bar']});
 	//Function to read data from SharePoint list using SPServices
 	//Function to generate Bar chart
 function ReadData(){
             operation: "GetListItems",
             async: false,
             listName: "Phone",
             CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='People_x0020_using' /></ViewFields>",            
             completefunc: function (xData, Status) {
                 $(xData.responseXML).SPFilterNode("z:row").each(function () {
                     var title = $(this).attr("ows_Title");
                     var people = $(this).attr("ows_People_x0020_using");
                     //Converting decimal number to whole number, for example ->3.000 to 3
                     people = Math.floor(people);
                     //creating json Object to save the values
                     var jsonObj_Values = {};
                     jsonObj_Values["Title"] = title;	
                     jsonObj_Values["People"] = people;
                     //Adding jsonObj_Values to main json
                     jsonObj_Chart[title] = jsonObj_Values;                   
 function GenerateChart(){
 //After the Google Visualization API is loaded, it will be set to run.
     function drawChart() {
       /*Either we can use google.visualization.DataTable() or google.visualization.arrayToDataTable([,]); to store the data      
 	      var data = google.visualization.arrayToDataTable([
 	        ["Phone", "No. of ppl"],
 	        ["iPhone", 100],
 	        ["Samsung", 150],
 	        ["BlackBerry", 50],
 	        ["mi", 130]
   Here I've used google.visualization.DataTable() for retrieving data and store it in a DataTable, */
       var data = new google.visualization.DataTable();
       data.addColumn('string', 'Phone');
 	  data.addColumn('number', 'No. of ppl');
 	 //Looping through jsonObj_Chart which has [Title,No of ppl]
       $.each(jsonObj_Chart, function(key, value) {
 		data.addRow([value.Title, value.People]);
 	  /* options - one of the very important variable to customize the chart, the actual customization should be done through this 'options'
 	  There are too many elements are available under this 'options' as key, value pair – Each chart types have their own options, I strongly suggest to visit there official site to know more about this*/
       var options = {
           chart: {
             title: 'Phone',
             subtitle: 'No. of ppl usage',
       var chart = new google.charts.Bar(document.getElementById("Barchart_Phone"));
       chart.draw(data, options);
 <!-- div width and height will affect the chart size !-->
 <div id="Barchart_Phone" style="width: 900px; height: 300px;">

Everything has explained in comments. To know more about Technical background on Google Chart, please refer here.





Google APIs - terms of service do not allow us to download the google.load or google.visualization code to use offline. End user computers must have access to in order to use charts.

To know more about hosting or downloading the chart code locally, or on an intranet or to use Chart offline - Google Chart - FAQ

Happy Coding


blog comments powered by Disqus

SharePoint Pals

SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile


Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community

SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to in a word document.

Related Resources

Recent Tweets

Twitter October 23, 22:21
How to Add/Remove User Custom Actions (in Site Actions Menu) Programmatically using CSOM PNP in SharePoint -

Twitter October 21, 21:34
How to Add a JS Link Reference to the Display Form or Any other ASPX Programmatically using CSOM PNP in SharePoint -

Twitter October 20, 13:01
How to Add a JS Link Reference to the NewForm and EditForm Programmatically using CSOM PNP in SharePoint Office 365-

Twitter October 12, 12:15
How to Deploy Provider Hosted Apps (Add-Ins) by App Stapling in SharePoint Office 365 -

Twitter October 11, 13:39
How to Deploy Provider HostedApp programmatically using CSOM in SharePoint Office 365 Activating Developer Feature -

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation