将 SPLitsItem 数据转换为某种图表或图形

Convert SPLitsItem data to some kind of chart or graph

我是 sharepoint 2016 编程的新手。我搜索了一些关于用 SPListItem 中的数据填充 graph/chart 的信息,我看到了很多令人困惑的答案。

有谁知道做这件事真的很不错,有什么好的指南或教程吗?

提前致谢。

您可以在 Web 部件中使用 SharePoint 列表数据构建图表,例如:

<asp:Chart ID="Chart1" runat="server" Width="500"> 
    <series> 
         <asp:Series 
                Name="Population" 
                XValueMember="Year" 
                YValueMembers="Population" 
                IsVisibleInLegend="true"> 
        </asp:Series> 
    </series> 
    <chartareas> 
        <asp:ChartArea 
                Name="ChartArea1" 
                Area3DStyle-Enable3D="true"> 
               <AxisX LineColor="DarkGreen"> 
                   <MajorGrid LineColor="LightGray" /> 
               </AxisX> 
               <AxisY LineColor="DarkGreen"> 
                   <MajorGrid LineColor="LightGray" /> 
               </AxisY> 
         </asp:ChartArea> 
    </chartareas> 
    <Legends> 
        <asp:Legend></asp:Legend> 
    </Legends> 
</asp:Chart>

后面的代码:

 try
        {
            var table = new DataTable();
            table.Columns.Add("Year", typeof(int));
            table.Columns.Add("Population", typeof(long));
            table.Columns.Add("Lbl");

            using (SPSite site = new SPSite(YourSiteUrl))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList _bugetlist = web.Lists["YearTotal"];
                    foreach (SPListItem _item1 in _bugetlist.Items)
                    {
                        var row = table.NewRow();
                        row["Year"] = Convert.ToInt16(_item1["Year"]);
                        row["Population"] = Convert.ToInt16(_item1["Population"]);
                        table.Rows.Add(row);
                    }
                }
            }
            Chart1.ChartAreas["ChartArea1"].AxisY.Title = "Population";
            Chart1.ChartAreas["ChartArea1"].AxisX.Title = "Years";


            Chart1.DataSource = table;
            Chart1.DataBind();

参考:

How to Create Custom Chart with data from SharePoint List