c# - 如何在asp图表控件中将错误消息显示到图表中

标签 c# asp.net aspchart

我有一个图表,当 rows.count == 0 时,我必须将消息显示为“无数据” 否则像往常一样显示条形图。

我可以知道如何显示该消息吗?

提前致谢。

最佳答案

试试这个:

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);
    }
}

谢谢

关于c# - 如何在asp图表控件中将错误消息显示到图表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14051948/

相关文章:

java - 数据传输 JAVA ->C# - 澄清?

c# - 从 c# ASP.NET 应用创建和保存文本文件

c# - ASP.NET DropDownList SelectedIndex 在第一个元素上未更改

c# - 当子类的对象作为父类(super class)调用时,子类中重写的方法是否仍然被调用?

c# - 为什么 Main() 方法应该是静态的?

c# - 将 .asp.net 图表标签更改为值,然后仅格式化图表,而不是图例

c# - ASP :Chart number localised formatting without changing culture

asp.net - 在 Asp :Chart 中将不重复设置为背景图像

c# - 使用 .NET 远程读取事件日志

c# - 最佳 Web .net 查询生成器