2014-10-08 42 views
0

這張截圖在圖表上點 - http://imgur.com/oBsFLvZ - 顯示以下項目試圖把使用SharePoint列表和Highcharts

一)什麼我目前得到(沒有數據點)

B)我願我的結果看起來像

三)我的SharePoint列表的樣子

(對不起,我沒有足夠的StackOverflow點張貼圖片還)

下面是代碼我現在有

$(document).ready(function() { 
 
    
 
var yearmontharray = []; 
 
var valuesarray = []; 
 
    
 
$().SPServices({ 
 
    operation: "GetListItems", 
 
    async: false, 
 
    listName: "List", 
 
    CAMLViewFields: "<viewfields><fieldref Name='Title' /><fieldref Name='values' /></ViewFields>", 
 
    CAMLQuery: "<query><orderby><fieldref Name='Title' Ascending='True' /></OrderBy></Query>", 
 
    completefunc: function (xData, Status) { 
 
    $(xData.responseXML).SPFilterNode("z:row").each(function() { 
 
    var yearmonth = ($(this).attr("ows_Title")); 
 
    var values = Math.round($(this).attr("ows_values")); 
 
    
 
    yearmontharray.push(yearmonth); 
 
    valuesarray.push(values); 
 
    }); 
 
    } 
 
}); 
 
    
 
chart = new Highcharts.Chart({ 
 
      chart: { 
 
       renderTo: 'container', 
 
       type: 'line', 
 
       marginRight: 130, 
 
       marginBottom: 25 
 
      }, 
 
      title: { 
 
       text: 'Total values', 
 
       x: -20 
 
      }, 
 
      subtitle: { 
 
       text: 'This chart shows value from SharePoint', 
 
       x: -20 
 
      }, 
 
      xAxis: { 
 
       categories: yearmontharray 
 
      }, 
 
      yAxis: { 
 
       title: { 
 
        text: 'values' 
 
       }, 
 
       plotLines: [{ 
 
        value: 0, 
 
        width: 1, 
 
        color: '#808080' 
 
       }] 
 
      }, 
 
      legend: { 
 
       layout: 'vertical', 
 
       align: 'right', 
 
       verticalAlign: 'top', 
 
       x: -10, 
 
       y: 100, 
 
       borderWidth: 0 
 
      }, 
 
      series: [{ 
 
       name: 'values', 
 
       data: valuesarray 
 
      }] 
 
     }); 
 
    
 
    
 
    
 
});

任何幫助將不勝感激!

回答

1

您必須在完整函數內包含圖表的收縮。否則,致電Hightchart是在獲取數據之前完成的。

$(document).ready(function() { 

    var yearmontharray = []; 
    var valuesarray = []; 

    $().SPServices({ 
     operation: "GetListItems", 
     async: false, 
     listName: "List", 
     CAMLViewFields: "<viewfields><fieldref Name='Title' /><fieldref Name='values' /></ViewFields>", 
     CAMLQuery: "<query><orderby><fieldref Name='Title' Ascending='True' /></OrderBy></Query>", 
     completefunc: function (xData, Status) { 
      $(xData.responseXML).SPFilterNode("z:row").each(function() { 
       var yearmonth = ($(this).attr("ows_Title")); 
       var values = Math.round($(this).attr("ows_values")); 

       yearmontharray.push(yearmonth); 
       valuesarray.push(values); 
      }); 
      // Inside complete func <----- 
      var chart = new Highcharts.Chart({ 
       chart: { 
        renderTo: 'container', 
        type: 'line', 
        marginRight: 130, 
        marginBottom: 25 
       }, 
       title: { 
        text: 'Total values', 
        x: -20 
       }, 
       subtitle: { 
        text: 'This chart shows value from SharePoint', 
        x: -20 
       }, 
       xAxis: { 
        categories: yearmontharray 
       }, 
       yAxis: { 
        title: { 
         text: 'values' 
        }, 
        plotLines: [{ 
         value: 0, 
         width: 1, 
         color: '#808080' 
        }] 
       }, 
       legend: { 
        layout: 'vertical', 
        align: 'right', 
        verticalAlign: 'top', 
        x: -10, 
        y: 100, 
        borderWidth: 0 
       }, 
       series: [{ 
        name: 'values', 
        data: valuesarray 
       }] 
      }); 

     } 
    }); 
}); 
+0

感謝您的迴應最大。我對使用任何類型的代碼都很陌生。我將如何去完成函數內部的圖表收縮? – rb195048 2014-10-08 20:52:56

+0

我已經完成了它,複製並粘貼代碼。記得標記答案,如果工作。 – Max 2014-10-08 21:11:31

+0

粘貼了新的代碼,但仍然沒有在圖上得到任何值 – rb195048 2014-10-08 21:21:53