【问题标题】:How can I bind an asp:chart (from microsoft) to a Dictionary<string,string>?如何将 asp:chart(来自 microsoft)绑定到 Dictionary<string,string>?
【发布时间】:2026-02-15 11:15:02
【问题描述】:

我正在为 ASP.Net 使用 MS 图表控件,但我无法确定绑定。 有人知道如何将 asp:chart(来自微软)绑定到字典吗?

【问题讨论】:

  • 你试过将Key和Value这两个词绑定成字段吗?

标签: c# asp.net charts datasource


【解决方案1】:
var employees = new Dictionary<int, string>
{
    {10,"Employee 1"},{20,"Employee 2"},{30,"Employee 3"}
};

Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;

foreach (KeyValuePair<int, string> employee in employees)
    Chart1.Series[0].Points.AddXY(employee.Value, employee.Key);

输出:

【讨论】: