Intermittent Error Rendering RadChart

Thread is closed for posting
3 posts, 0 answers
  1. Henry
    Henry avatar
    5 posts
    Member since:
    Aug 2012

    Posted 13 Feb 2013 Link to this post

    Often seen on the first (asynchronous) load.  In the Firefox console, I see this

    [11:42:31.052] The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature. @ https://.../Dashboard/ChartImage.axd?UseSession=true&ChartID=6a20948d-8463-41a9-9282-158c82e54707_chart_ctl00$campaignChart&imageFormat=Png&random=3e42c05b-36d6-43bb-aa0a-9f202bb8b2cd

    If I don't get the error, I don't see that log.

    What we're doing is pretty standard: 

    Control ascx
    <telerik:RadChart ID="campaignChart" runat="server" DefaultType="Bar" Skin="Web20" Width="150px" Height="230px"
           PlotArea-YAxis-Appearance-MinorGridLines-Visible="false"  PlotArea-YAxis-Appearance-MajorGridLines-Visible="false"
            PlotArea-XAxis-Appearance-MajorTick-Visible="false" PlotArea-XAxis-Appearance-LabelAppearance-Visible="false"
             PlotArea-YAxis-Appearance-MinorTick-Visible="false" >
     
           </telerik:RadChart>

    Code behind C#

    List<lastCampaignActivityStats> chartData = new List<lastCampaignActivityStats>();
     chartData.Add(new lastCampaignActivityStats("total", total));
     ...
     chartData.Add(new lastCampaignActivityStats("clicked", clicked));
     
     
     ChartSeries emailChartSeries = new ChartSeries();
     emailChartSeries.Type = ChartSeriesType.Bar;
     
     //styles for disabling all the default
     emailChartSeries.Appearance.Border.Visible = false;
     emailChartSeries.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.Nothing;
     emailChartSeries.Appearance.DiameterScale = 1;
     emailChartSeries.Appearance.TextAppearance.Visible = false;
     emailChartSeries.Appearance.LabelAppearance.Visible = false;
     emailChartSeries.Appearance.LabelAppearance.LabelConnectorStyle.Visible = false;
     
     
     campaignChart.Appearance.Border.Visible = false;
     campaignChart.ChartTitle.Visible = false;
     campaignChart.ChartTitle.Appearance.Visible = false;
     campaignChart.Legend.Visible = false;
     campaignChart.Legend.Appearance.Visible = false;
     campaignChart.PlotArea.Appearance.Dimensions.Margins = new Telerik.Charting.Styles.ChartMargins(10, 0, 10, 50);
     campaignChart.PlotArea.Appearance.Border.Visible = false;
     campaignChart.IntelligentLabelsEnabled = false;
     
     
     
     //data source
     campaignChart.DataSource = chartData;
     //add series
     campaignChart.Series.Add(emailChartSeries);
     campaignChart.Series[0].DataYColumn = "Value";
     campaignChart.Series[0].PlotArea.YAxis.LabelStep = 5;
     
      campaignChart.DataBind();

    Except that it's asynchronously loaded - the data can take a while to be available via a WebHandler
               /// <summary>
            /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler" /> interface.
            /// </summary>
            /// <param name="context">An <see cref="T:System.Web.HttpContext" /> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
            public void ProcessRequest(HttpContext context)
            {
                using (var writer = new StringWriter())
                {
                    var pageHolder = new Page();
                    var control = (UserControl)pageHolder.LoadControl("~/Dashboard/UserControls/LastEmailCampaignActivity.ascx");
                    pageHolder.Controls.Add(control);
                    context.Server.Execute(pageHolder, writer, false);
                    context.Response.ContentType = "text/html";
                    context.Response.Write(writer.GetStringBuilder().ToString());
                }
            }

  2. Henry
    Henry avatar
    5 posts
    Member since:
    Aug 2012

    Posted 14 Feb 2013 Link to this post

    Big AHA here - we'd recently changed to a 2 process web garden.  When I set my localhost as a web garden and drove it with two browsers, I got the same error.

    We've rolled back to one worker process.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 18 Feb 2013 Link to this post

    Hello Henry,

    There are some specifics about RadChart and multi-server or multi-process environment. Here is how RadChart works. When a page with RadChart is requested the image is generated and placed in the session. An <img> tag is rendered in the page. Later, when the browser requests that image, it might happen so, that another machine/process handles that request, so it would not be the same session state and the image would not be found (hence the intermittent nature of the problem). If the problem is related to the image availability in the session, possible solutions here include sticky session implementation (so that all the requests from a single user are handled by the same process/machine),  StateServer or SQLServer session mode, so that there is a common session state.

    Alternatively, RadChart allows you to forbid session usage. You can set UseSession property to false and provide a value for the TempImagesFolder property. It should be a path to a folder within the web application root, where asp.net process has rights to write. This folder should point to common storage, where all the processes have access. This way RadChart will create the image and write it there. Later, when requested by the browser any process will be able to retrieve the image.

    In addition, you can try to isolate the problem in a small example on your own -- create an HttpHander that retrieves an image from the session and returns it (this would replace ChartHttpHandler). Then create a user control that renders an <img> tag with src attribute set to a path like MyHandler.axd and try to load that user control in your web handler. 

    Best regards,
    Ves
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top