How to display Error message into chart in asp chart controls

落爺英雄遲暮 提交于 2019-12-11 06:24:18

问题


I have a chart where I have to display message as "No Data Present",when rows.count == 0 else the bar chart as usually.

May i know how to display that message.

Thanks in advance.


回答1:


Try this :

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

Thanks



来源:https://stackoverflow.com/questions/14051948/how-to-display-error-message-into-chart-in-asp-chart-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!