views:

261

answers:

2

Hi everyone,

I'm using an ASP.NET Chart control, and it takes the data from a database. Sometimes, this data 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

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

A: 

Hello,

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.
Narcís Calvet
A: 

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