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

Change the left axis to descending order

6 Answers 171 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
John Schroeder
Top achievements
Rank 1
John Schroeder asked on 05 Oct 2010, 09:19 PM
I have a unique situation where I want the left Y axis in my line chart to show the values so that the larger number is at the bottom... for example 100 up to 0, vs the standard format of a bottom 0 line that increments up to 100.  Basically I just want to reverse the order of the left Y axis data.

Is there any easy way to do this?

Any help is greatly appreciated.

John

6 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 07 Oct 2010, 07:54 AM
Hello John,

You can set reverse order for axis Y labels with this approach:
Subscribe for ItemDataBound event of the chart and then make series items' YValue negative like this:

void myRadChart_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
    {
        e.SeriesItem.YValue = -e.SeriesItem.YValue;
    }

This will affect the axis too - it will show negative values with 0 at the top. The key in the clue is to set Custom Format Strings (http://msdn.microsoft.com/en-us/library/0c899ak8.aspx) to the property CustomFormat of the YAxis.
What you need is the "##;##" custom format - this will suppress the "-" sign for negative values. You can set it like this:

myRadChart.PlotArea.YAxis.Appearance.CustomFormat = "##;##";

Hope this helps.

All the best,
Evgenia
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Richard
Top achievements
Rank 1
answered on 13 Jun 2011, 04:44 AM
Hi,

I am trying to apply your suggestion to my code although the value of -e.SeriesItem.XValue  is 1.#QNAN.

The difference in my scenario is that i have my seriesOrientation set to horizontal so i have my X Axis on the left and I have my YAxis2 on the top of the chart

You can see my code here: http://www.telerik.com/community/forums/aspnet-ajax/chart/horizontal-x-axis-reversed-values.aspx

If you can help me get this of my chest it will greatly be appreciated.

Cheers

Richard.
0
Evgenia
Telerik team
answered on 15 Jun 2011, 02:33 PM
Hi Richard,

The project attached is a modified version of the code snippets that you provided in the forum post. The XAxis Labels are shown in reverse order using the approach I mentioned in my post below. 

Regards,
Evgenia
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Richard
Top achievements
Rank 1
answered on 17 Jun 2011, 04:36 AM
Hi Evgenia

Thank you for your help I can now see the reverse order. Although I see that you have removed the following code:

RadChart1.PlotArea.XAxis.AutoScale = False

I require this so i can set the min and max values to the Xaxis (this is my previous post: http://www.telerik.com/community/forums/aspnet-ajax/chart/x-axis-min-and-max-value-issue.aspx

But i notice that once I add this statement in (RadChart1.PlotArea.XAxis.AutoScale = False) The X Axis is no longer in reverse order...

Sorry for being so difficult but if this is possible to accomplish, please advise.

Thank you

Regards
Richard.
0
Evgenia
Telerik team
answered on 22 Jun 2011, 02:56 PM
Hi Richard,

Have in mind that you can not use custom Range for XAxis (AutoScale = false) and binded XAxis Labels - chartSeries.DataXColumn = "Depth" since the bound labels will override those set when AutoScale is false. What you can do is populate your DataTable with data so that you have the required step and values. This way you will be able to use the given Inverse Axis approach.

Greetings,
Evgenia
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Sérgio
Top achievements
Rank 1
answered on 26 Feb 2013, 06:03 PM
This solution only works if RadChart is databounded (it will call ItemDataBound event).

I think there is a better and simple solution and will also resolves adding items manually (through server code), throught the BeforeLayout event. Here is a sample code:

    protected void RadChart1_BeforeLayout(object sender, EventArgs e)
    {
        int count = RadChart1.PlotArea.YAxis.Items.Count;

        for (int i = 0; i < count; i++)
        {
            RadChart1.PlotArea.YAxis.Items[i].TextBlock.Text = (count - i).ToString();
        }
    }
Tags
Chart (Obsolete)
Asked by
John Schroeder
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Richard
Top achievements
Rank 1
Sérgio
Top achievements
Rank 1
Share this question
or