如何将DataTable绑定到mschart中的图例

我用excel来绘制一张图片如下: http://i.stack.imgur.com/hNMKy.png

请注意红色区域的高光

我的问题是:如何将数据表绑定到mschart的图例? 所以除了图例颜色之外,人们也可以从图例中看到细节数据。

或者,你们可以告诉在mschart中绑定是否可行? 提前致谢!

据我所知,在API中没有任何东西可以让你简单地将你的DataTable绑定到图例上。

但是你仍然可以用一些代码来pipe理这样的事情:

var l = chart1.Legends[0]; l.LegendStyle = LegendStyle.Table; l.TableStyle = LegendTableStyle.Tall; l.BorderColor = Color.OrangeRed; l.Docking = Docking.Bottom; l.LegendStyle = LegendStyle.Table; l.HeaderSeparator = LegendSeparatorStyle.DashLine; l.HeaderSeparatorColor = Color.Red; var firstColumn = new LegendCellColumn(); l.ColumnType = LegendCellColumnType.SeriesSymbol; l.CellColumns.Add(firstColumn); var secondColumn = new LegendCellColumn(); l.ColumnType = LegendCellColumnType.Text; secondColumn.Text = "#SER"; l.CellColumns.Add(secondColumn); foreach (DataRow row in dt.Rows) { var column = new LegendCellColumn(); column.ColumnType = LegendCellColumnType.Text; column.HeaderText = row["x"].ToString(); column.Text = "#VALY"; l.CellColumns.Add(column); } 

但是,我的build议是将数据包含在单独的控件中,而不是作为图表本身的一部分。 如果您将其保存在一个用于表格数据的.net控件中,无论您使用的是winforms还是webforms,使用起来都会容易得多。