如果没有要绘制图表的数据,是否有办法在 MS 图表控件上显示“默认”消息?
我有一个图表,其中包含一些控件,允许用户选择各种日期范围。如果在该日期范围内没有要绘制图表的数据,则当前仅显示任何内容(或者至少显示图例和背景,仅此而已。)
我希望有一条消息说“此期间没有数据”或其他内容。
Thanks,
Ben
基于克里斯的回应,这里有一个更完整的例子:
在 ASPX 代码中,将 OnDataBound 处理程序添加到图表标记。这假设您使用 SqlDataSource 作为数据源。
<asp:Chart ID="ChartExample" runat="server"
DataSourceID="SqlDataSourceExample"
OnDataBound="ChartExample_DataBound">
在代码隐藏中,处理程序检查第一个系列是否有任何数据,如果没有,则插入红色注释。
protected void ChartExample_DataBound(object sender, EventArgs e)
{
// If there is no data in the series, show a text annotation
if(ChartExample.Series[0].Points.Count == 0)
{
System.Web.UI.DataVisualization.Charting.TextAnnotation annotation =
new System.Web.UI.DataVisualization.Charting.TextAnnotation();
annotation.Text = "No data for this period";
annotation.X = 5;
annotation.Y = 5;
annotation.Font = new System.Drawing.Font("Arial", 12);
annotation.ForeColor = System.Drawing.Color.Red;
ChartExample.Annotations.Add(annotation);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)