Home › Forums › SPJS Charts for SharePoint › Chart V7 Custom Data Source
- This topic has 2 replies, 2 voices, and was last updated 2 years, 2 months ago by Alexander Bautz.
-
AuthorPosts
-
-
September 20, 2022 at 09:33 #36130
Hi Alex,
I’m trying to get data from an external source using the Custom Datasource function in Charts. I get the attached error, can you help please.
Kind regards
Ian
Here is the Custom Object:
{
“type”:”function”,
“functionName”:”getChartCustomData”,
“columns”:[
{“fin”:”PeriodStartString”,”label”:”Date”,”type”:”date”,”dataType”:”date”,”role”:””},
{“fin”:”StringValue”,”label”:”Despatch Delivery”,”type”:”Text”,”dataType”:”number”,”role”:””} ]
}This is the code for the function, it fetches the data from our server and returns this data:
[{“StringValue”:”88″,”PeriodStartWeb”:”2022-08-01T00:08:00Z”},{“StringValue”:”96″,”PeriodStartWeb”:”2022-07-01T00:07:00Z”},{“StringValue”:”89″,”PeriodStartWeb”:”2022-06-01T00:06:00Z”},{“StringValue”:”92″,”PeriodStartWeb”:”2022-05-01T00:05:00Z”},{“StringValue”:”94″,”PeriodStartWeb”:”2022-04-01T00:04:00Z”},{“StringValue”:”94″,”PeriodStartWeb”:”2022-09-01T00:09:00Z”}]async function postData(url = ”, data = {}) {
// Default options are marked with *
const response = await fetch(url, {
method: ‘POST’, // *GET, POST, PUT, DELETE, etc.
mode: ‘cors’, // no-cors, *cors, same-origin
cache: ‘no-cache’, // *default, no-cache, reload, force-cache, only-if-cached
credentials: ‘same-origin’, // include, *same-origin, omit
headers: {
‘Content-Type’: ‘text/plain’
// ‘Content-Type’: ‘application/x-www-form-urlencoded’,
},
redirect: ‘follow’, // manual, *follow, error
referrerPolicy: ‘no-referrer’, // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify(data) // body data type must match “Content-Type” header
});
return response.text(data);
}function getChartCustomData(chartId){
var data=[];
postData(‘https://ourserver/data/getdata.php’, { answer: 42 })
.then((data) => {
return data;// console.log(data);
}Attachments:
-
September 20, 2022 at 13:51 #36132
Hi Alex,
Sorry to have bothered you. For anyone else I wrote this function:
function getChartCustomData() {
var deferred = jQuery.Deferred();
jQuery.get(‘https://ourServer/data/getdata.php?ACTION=Test’,data = {}).done(function(data){
deferred.resolve(data);
});
return deferred.promise();All works great now
Cheers -
September 20, 2022 at 16:33 #36133
I’m glad you figured it out.
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.