I am trying to build some visuals in Sharepoint to present the list data in a more useful fashion.

charts.js appears to be a free resource for this purpose so i have been playing with that and have managed to have some working charts.

This link showed me how to extract data

The above link used the code

function GetChartData() {
seriesarray = [];
var currentcontext = new SP.ClientContext.get_current();
var splist = currentcontext.get_web().get_lists().getByTitle('Fruit Consumption');
var splistquery = new SP.CamlQuery();
splistitems = splist.getItems(splistquery);

Which worked fine when on the page containing the list. allitems.aspx However when I use that same code to add into a webpart on a new page it doesn't call the list data.

I guess something needs to be changed in

var splist = currentcontext.get_web().get_lists().getByTitle('Fruit Consumption');

due to the data being on a different page.

Would anyone know what I need to change to make it work?

Many thanks

  • Use a REST query instead. You would need to change the function to parse the json response but that should be relatively straight forward. – Bunzab Sep 29 '17 at 12:27
  • Thanks for the speedy response. I have no idea how to do that yet! I will google it and try and learn now. – David Bentley Sep 29 '17 at 12:44

You can use SPServices or SharePointPlus but I suggest you to use SharePointPlus to get data from list. You can use SQL like syntax and it is really easy to use.

SharepointPlus ($SP) is a JavaScript library which offers some extended features for SharePoint entirely on client side (requires no server install). $SP will simplify your interactions with the Sharepoint Web Services and will help you to deal with the List Forms.

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.