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

Iterate through Yaxis Major tick labels?

5 Answers 146 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 2
Joel asked on 13 Sep 2010, 08:42 PM
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?






5 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 15 Sep 2010, 06:23 PM
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
0
Michael Warden
Top achievements
Rank 1
answered on 10 Apr 2011, 10:46 PM
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)

0
Evgenia
Telerik team
answered on 13 Apr 2011, 03:48 PM
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.

0
Michael Warden
Top achievements
Rank 1
answered on 13 Apr 2011, 04:06 PM
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.

0
Evgenia
Telerik team
answered on 18 Apr 2011, 08:44 AM
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.

Tags
Chart (Obsolete)
Asked by
Joel
Top achievements
Rank 2
Answers by
Evgenia
Telerik team
Michael Warden
Top achievements
Rank 1
Share this question
or