SPServices Stories #2 – Charting List Data with HighCharts
- SPServices Stories #1 – How to Start a Workflow on Multiple Items in a List
- SPServices Stories #2 – Charting List Data with HighCharts
- SPServices Stories #3 – AddWebPart Method of the WebPartPages Web Service
- SPServices Stories #4 – Using SPServices to Process Files from a Non-Microsoft Source
- SPServices Stories #5 – Gritter and Sharepoint: Integrate Nifty Notifications in Your Intranet!
- SPServices Stories #6 – Custom Quizzing System
- SPServices Stories #7 – Example Uses of SPServices, JavaScript and SharePoint
- SPServices Stories #8 – CEWP, Nintex, jQuery, SPServices and the Client API
- SPServices Stories #9: Developing with Client-side Technologies: jQuery, REST, SPServices and jsRender
- SPServices Stories #10 – jqGrid Implementation Using SPServices in SharePoint
- SPServices Stories #11 – Using SPServices and jQuery to Perform a Redirect from a SharePoint List NewForm to EditForm
- SPServices Stories #12 – SharePoint and jQuery SPServices in Education: A Case Study
- SPServices Stories #13: Durandal SP3: Developing SharePoint SPAs Made Easy
- SPServices Stories #14: Create a Slide Show in SharePoint 2010 using an Announcements List and SPServices
- SPServices Stories #15: Custom Client-side Calendar Query for Office 365 SharePoint Site Using SPServices jQuery Library
- SPServices Stories #17: Multiple Form Fields Autocomplete for SharePoint 2010/2013 using JavaScript
- SPServices Stories #18 – Retrieve Managed Metadata Using JavaScript and SPServices
- SPServices Stories #19 – Folders in SharePoint are as necessary as evil. Make the best of it using jQuery and SPServices.
- SPServices Stories #20 – Modify User Profile Properties on SharePoint Online 2013 using SPServices
- SPServices Stories #22 : SPServices SharePoint Attachments in Internet Explorer 9
- SPServices Stories #21 – Redirect If User Clicked a Button Previously
Introduction
This submission comes to us from an anonymous reader, who can’t publish the details under his (or her) name due to confidentiality issues. However, s/he has been able to generate some very useful charts with HighCharts using SharePoint list data as the underlying data sources.
Charting List Data with HighCharts
In the following code, the source list contains columns with Year (string), Month (1-12), and Value (number with decimals).
While HighCharts isn’t free, the licensing costs are quite reasonable. A similar approach would work with other charting engines out there which may be free.
The page has a Content Editor Web Part dropped into it with the Content Link pointing to a file containing the following:
<!-- jquery and spservices are in the masterpage here this is a CEWP noConflict is on--> <script type="text/javascript"src="//code.highcharts.com/highcharts.js"></script> <script type="text/javascript" src="//code.highcharts.com/modules/exporting.js"></script> <script type="text/javascript"> function GetYearSeries(series, year) { var gotOne = false; var seriesOptions; jQuery.each (series, function(index, dataItem) { if (dataItem.name === year) { seriesOptions = dataItem; gotOne=true; } }); if (!gotOne) { seriesOptions = { name: year, data: [0,0,0,0,0,0,0,0,0,0,0,0] }; series.push (seriesOptions); } return seriesOptions; } jQuery(function($) { var CamlQuery = "<Query><OrderBy><FieldRef Name='Year' /><FieldRef Name='Month' Ascending='False' /></OrderBy></Query>"; $().SPServices({ operation: "GetListItems", async: true, listName: "Sales", CAMLQuery: CamlQuery, CAMLViewFields: "<ViewFields><FieldRef Name='Year' /><FieldRef Name='Month' /><FieldRef Name='Value' /></ViewFields>", completefunc: GraphIt }); function GraphIt(xmlResponse) { var options = { chart: { renderTo: 'container', type: 'column' }, title: { text: 'Sales' }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] }, yAxis: { title: { text: 'Value' } }, series: [] }; $(xmlResponse.responseXML).SPFilterNode("z:row").each(function() { var seriesOptions = GetYearSeries(options.series, $(this).attr('ows_Year')); var month=parseInt($(this).attr('ows_Month'))-1; seriesOptions.data[month]=parseFloat($(this).attr('ows_Value')); }); var chart = new Highcharts.Chart(options); } });//docReady </script> <div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
This generates a chart which looks something like this:
Interesting numbers
I’ve recently used spservices and highcharts…good stuff!!
can you pleasssse share the steps
Cool stuff, question, could you please explain how would I use stacked bars for sales and group the result by salesman / month / year ?
Hi Marc,
I am using PageViewer webpart to display a web site that uses highcharts, but I can’t make the exporting feature to work. Can you try to export the charts using the highcharts menu and tell me if it works for you. Also can you tell me if you did something special to make it work?
Thanks in advance
Arley:
I didn’t do the Highcharts work. The post came from someone else, and to be honest I’ve forgotten whom!
M.
I try but not working
I not know how to help.