开发者

ASP.NET Chart control with empty data

开发者 https://www.devze.com 2022-12-26 18:53 出处:网络
I\'m using an ASP.NET Chart control, and it takes the data from a database. Sometimes, this 开发者_如何学JAVAdata is empty, and I can\'t find any way to show some text or similar instead of a blank sc

I'm using an ASP.NET Chart control, and it takes the data from a database. Sometimes, this 开发者_如何学JAVAdata is empty, and I can't find any way to show some text or similar instead of a blank screen. There is no attribute that allows me to do that.

Besides, I think that because of the empty data, I get an exception every time I try to show the chart without data:

16.48.27 ERROR: System.Web.HttpException: File does not exist.
   at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
   at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context)
   at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I suppose that it's because of the "ImageLocation" attribute on Chart object, because it doesn't create any image with empty data, so it cannot find that location.

This is the image I want to avoid:

alt text http://img532.imageshack.us/img532/6215/chartt.png

Question: Is there any way to detect when Chart receives empty data?


You could check the following:

  1. Check if chart's datasource is null.
  2. Check if datasource's tables used are empty (have 0 rows).
  3. Check if SQL query returns any result.


Actually, I'm using an ObjectDataSource, and finally what I've done is the following:

the ObjectDataSource has an event called Selected. I've used the method which captures these events to put Visible's property of the chart to false when the ReturnValue of the ObjectDataSourceStatusEventArgs has 0 elements, and put Visible's property of a Label to true indicanting the lack of data, like this:

protected void RcrBufferSizeODS_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
    if (((List<RcrBufferSize>)e.ReturnValue).Count == 0)
        {
            RcrBufferChart.Visible = false;
            EmptyDataLabel.Visible = true;
        }
        else
        {
            RcrBufferChart.Visible = true;
            EmptyDataLabel.Visible = false;
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号