Iterate through Yaxis Major tick labels?

Thread is closed for posting
6 posts, 0 answers
  1. Joel
    Joel avatar
    166 posts
    Member since:
    Oct 2006

    Posted 13 Sep 2010 Link to this post

    Is there a way to change the value of Yaxis major tick labels once the graph is established?

    I am passing -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5  for the Y axis.  Client wants all values to show as positive, but respecting the negative position  5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5 on the same Y axis.

    Is there a way to step through axis labels and if the value is less than 1, multiply by -1, or just abs() all the ticks?






  2. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 15 Sep 2010 Link to this post

    Hi Joel,

    Generally the concepts of the axis item label and the underlying axis item value are separated in RadChart so you can achieve the desired effect by modifying the label and keeping the underlying value intact like this:

    ASPX
    <telerik:RadChart ID="RadChart1" runat="server" AutoLayout="true" SeriesOrientation="Horizontal" OnBeforeLayout="RadChart1_BeforeLayout">
        <Series>
            <telerik:ChartSeries Type="Gantt">
                <Appearance BarWidthPercent="5" ShowLabels="false" LegendDisplayMode="Nothing" />
                <Items>
                    <telerik:ChartSeriesItem YValue="-4" YValue2="2" />
                    <telerik:ChartSeriesItem YValue="-1" YValue2="4" />
                </Items>
            </telerik:ChartSeries>
        </Series>
        <PlotArea>
            <YAxis AutoScale="false" MinValue="-5" MaxValue="5" Step="1" />
        </PlotArea>
    </telerik:RadChart>

    C#
    protected void RadChart1_BeforeLayout(object sender, EventArgs e)
    {
        foreach (ChartAxisItem axisItem in RadChart1.PlotArea.YAxis.Items)
        {
            axisItem.TextBlock.Text = Math.Abs(axisItem.Value).ToString();
        }
    }

    Hope this helps.


    Kind regards,
    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. Michael Warden
    Michael Warden avatar
    19 posts
    Member since:
    Jan 2004

    Posted 10 Apr 2011 Link to this post

    i'm trying to interate through my Y  Axis items just like in this example.  except i'm generating my chart dynamically.  there is no RadChart server-side tag on my aspx page so i have no BeforeLayout event.  i'm creating my chart basically like below and putting it in a tablecell.  but the For Each statement isn't actually working, i can't get the Y Labels to change at all.

     

    Dim NewChart As New RadChart

     

     

    NewChart.Width = Unit.Pixel(980)

     

    NewChart.Chart.DefaultType = Telerik.Charting.ChartSeriesType.Line

     

    NewChart.PlotArea.YAxis.AutoScale =

    False

     

    NewChart.PlotArea.XAxis.DataLabelsColumn =

    "PrettyDate"

     

     

    NewChart.Skin =

    "Hay"

     

     

    NewChart.AutoLayout =

     

    True

     

     

     

    For Each YI As Telerik.Charting.ChartAxisItem In NewChart.PlotArea.YAxis.Items

     

        YI.TextBlock.Text =

    "SomethingNew"

     

     

     

     

     

     

     

     

     

    Next

     

     

     

     

     

     

     

    TableCell.Controls.Add(NewChart)

  5. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 13 Apr 2011 Link to this post

    Hello Michael,

    You can set custom Axis Labels Programmatically as described in our help topic with code sample.

    Kind 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. Michael Warden
    Michael Warden avatar
    19 posts
    Member since:
    Jan 2004

    Posted 13 Apr 2011 Link to this post

    the problem is i'm not adding the axis items manually like in that example.  i'm just creating a databound chart and the y-axis items get created automatically.  the problem seems to be that after i dynamically create the databound chart and immediately aftwards call

    NewChart.PlotArea.YAxis.Items.Count.ToString

    that count turns out to be 0, even though there are clearly items on the y-axis of the chart.

  7. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 18 Apr 2011 Link to this post

    Hi Michael,

    To be able to have the actual count of the Axis Items and not 0 you should subscribe to the BeforeLayout event of the Chart.

    All the best,
    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.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017