如何在asp图表控件中将错误信息显示到图表中

本文关键字:错误 信息 显示 控件 asp | 更新日期: 2023-09-27 17:49:33

我有一个图表,我必须显示消息为"No Data Present",当行。Count == 0

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

如何在asp图表控件中将错误信息显示到图表中

试试这个:

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

谢谢