c# - 将 SPLitsItem 数据转换为某种图表或图形
问题描述
我是 sharepoint 2016 编程的新手。我搜索了一些关于用 SPListItem 中的数据填充图形/图表的信息,但我看到了很多令人困惑的答案。
任何人都知道这样做真的很好,有什么好的指南或教程吗?
提前致谢。
解决方案
您可以在 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();
参考:
推荐阅读
- node.js - 路由在 src/index.html 角度不起作用
- asp.net-core - Shieldui - ASP.Net Core CRUD 操作 - 弹出编辑
- regex - Notepad++ 书签行包含特定字符并使用正则表达式从字符串中间开始
- android - 为什么gradlew assembleDebug不运行jetifier,而react-native run-android运行jetifier?
- jquery - 如何删除 jQuery 数据表中的隐藏复选框
- python - 在Python中检查目录是否为空的最快方法是什么
- android - 如果他们在android中没有jsonobject,如何从Jsonarray获取Jsonarray
- vue.js - vue 多次发出一次
- c# - UWP:导航到新页面时无法输入文本框
- javascript - 带有样式组件的样式函数中的 React.useContext