In this article, we shall see how to create a Bar Chart using HighCharts and bind dynamic values using SPServices GetListItems.
Before starting make sure you have all these reference files.
- jquery-1.10.2.js
- highcharts-custom.js
- exporting.js
- jquery.SPServices-0.7.2.min.js
Using SPservices - GetListItem:
- //Getting Current Site URL
- var CsiteUrl = _spPageContextInfo.webServerRelativeUrl;
- //Getting the CAML Queries
- var ViewFields = "<ViewFields><FieldRef Name='Selection' /><FieldRef Name='Integer' /><FieldRef Name='Int' /></ViewFields>";
- var FilteredValue = "<Query><Where><IsNotNull><FieldRef Name='Selection' /></IsNotNull></Where></Query>";
- //Declaring 2 arrays - Categories and Series for passing the values to chart.
- var ogetCountries = [];
- var oPopulateData = [];
- //Writing the GetListItem SPServices
- $().SPServices
- ({
- operation: "GetListItems",
- async: false,
- webURL: CsiteUrl,
- listName: "PieChart",
- CAMLViewFields: ViewFields,
- CAMLQuery: FilteredValue,
- completefunc: function(xData, Status)
- {
- // alert(xData.responseText+ " " + Status);
- $(xData.responseXML).SPFilterNode("z:row").each(function()
- {
- oData = $(this).attr("ows_Population")
- oPlaces = $(this).attr("ows_Country");
- oPopulateData.push(oData); //Storing the Population values in the Array
- ogetCountries.push(oPlaces); //Storing the Countries values in the Array
- });
- }
- });
Join the conversation! Your thoughts help the community grow.