This is a migrated thread and some comments may be shown as answers.

Horizontal Bar Chart Issue

3 Answers 18 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Muhammad Irfan
Top achievements
Rank 1
Muhammad Irfan asked on 16 Oct 2012, 08:06 AM
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

3 Answers, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 19 Oct 2012, 08:16 AM
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.
0
Muhammad Irfan
Top achievements
Rank 1
answered on 21 Oct 2012, 09:17 AM
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.
0
Petar Kirov
Telerik team
answered on 24 Oct 2012, 12:02 PM
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.
Tags
General Discussions
Asked by
Muhammad Irfan
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Muhammad Irfan
Top achievements
Rank 1
Share this question
or