Horizontal Bar Chart Issue

4 posts, 0 answers
  1. Muhammad Irfan
    Muhammad Irfan avatar
    13 posts
    Member since:
    Oct 2007

    Posted 16 Oct 2012 Link to this post

    Hi Guys,

    I have a horitontal bar chart with XAxis and YAxis2. YAxis2 Item labels appear on the top from left to right in ascending order. Take a look at the attached image. However, XAxis item labels start from bottom to top in ascending order. I want them to appear from top to bottom so that they look consitent with YAxis2 items labels. Is this possible?

    Many thanks.
    Irfan
  2. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 19 Oct 2012 Link to this post

    Hi Irfan,

    The axes of the ASP.NET RadChart don't expose an API for reversing, however a relatively easy workaround exists.
    Basically you have to change the Series Items' XValue sign to the opposite one in the DataBound event, and in the BeforeLayout, you have to change axis labels numbers sign back to the original state. Here is a code example: 
    //Register for the events before the DataBind() method is called
    this.RadChart1.DataBound +=
            new EventHandler(RadChart1_DataBound);
    this.RadChart1.BeforeLayout +=
            new EventHandler<EventArgs>(RadChart1_BeforeLayout);
    this.RadChart1.DataBind();
     
    void RadChart1_DataBound(object sender, EventArgs e)
    {
        foreach (var series in RadChart1.Series)
        {
            foreach (var seriesItem in series.Items)
            {
                seriesItem.XValue *= -1.0;
            }
        }
    }
     
    void RadChart1_BeforeLayout(object sender, EventArgs e)
    {
        foreach (var axisItem in RadChart1.PlotArea.XAxis.Items)
        {
            axisItem.TextBlock.Text =
                (double.Parse(axisItem.TextBlock.Text) * -1.0).ToString();
        }
    }

     

    All the best,
    Petar Kirov
    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.
  3. Muhammad Irfan
    Muhammad Irfan avatar
    13 posts
    Member since:
    Oct 2007

    Posted 21 Oct 2012 Link to this post

    Hi Petar,

    Very clever. I will try that. One more question, I am keeping both the required registered directives (see below) on the page itself for the chart to work. Is it possible to put them in the web.config?

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Charting" TagPrefix="telerik" %>

    Thanks.
  4. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 24 Oct 2012 Link to this post

    Hi Irfan,

    Yes it is possible. You can find it described in this blog post.
     
    Kind regards,
    Petar Kirov
    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