Change the left axis to descending order

Thread is closed for posting
7 posts, 0 answers
  1. John Schroeder
    John Schroeder avatar
    11 posts
    Member since:
    Nov 2009

    Posted 05 Oct 2010 Link to this post

    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
  2. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 07 Oct 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Richard
    Richard avatar
    9 posts
    Member since:
    Feb 2010

    Posted 12 Jun 2011 Link to this post

    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.
  5. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 15 Jun 2011 Link to this post

    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.

  6. Richard
    Richard avatar
    9 posts
    Member since:
    Feb 2010

    Posted 16 Jun 2011 Link to this post

    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.
  7. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 22 Jun 2011 Link to this post

    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.

  8. Sérgio
    Sérgio avatar
    9 posts
    Member since:
    Aug 2008

    Posted 26 Feb 2013 Link to this post

    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();
            }
        }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017