Chart V7 Custom Data Source

Home Forums SPJS Charts for SharePoint Chart V7 Custom Data Source

Viewing 2 reply threads
  • Author
    Posts
    • #36130
      Ian Patrick
      Participant

        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);
        }

      • #36132
        Ian Patrick
        Participant

          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

        • #36133
          Alexander Bautz
          Keymaster

            I’m glad you figured it out.

            Alexander

        Viewing 2 reply threads
        • You must be logged in to reply to this topic.