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

Add Labes to x-axis manually

2 Answers 123 Views
Chart (obsolete as of Q1 2013)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Glen Fernandes
Top achievements
Rank 1
Glen Fernandes asked on 04 May 2009, 06:23 AM
i have a chart with dates on X-axis , Chart is bound to a dataSource and there are 700 items  .
with the default settings all the dates are displayed as labels and there is a overlap of labels on X-axis. 

what i want to do is have only three labels on x-axis.
 1) at start   i.e Min of Dates (the x-axis starts from here)
2) at end i.e Max of Dates (the x-axis Ends here)
3) at  the middle (approximately)  (between the min and max date)

in Chart wizard, labels can be added to axis manually . but it only accepts INT's.
How can i achieve this with dates?

below is the code generated by the designer while adding labels manually for INT Data types

 

 

 

            Telerik.Charting.ChartAxisItem chartAxisItem1 = new Telerik.Charting.ChartAxisItem();  
            Telerik.Charting.ChartAxisItem chartAxisItem2 = new Telerik.Charting.ChartAxisItem();  
            Telerik.Charting.ChartAxisItem chartAxisItem3 = new Telerik.Charting.ChartAxisItem();  
            chartAxisItem1.Value = new decimal(new int[] {1, 0,0,0});  
            chartAxisItem2.Value = new decimal(new int[] {6,0,0,0});  
            chartAxisItem3.Value = new decimal(new int[] {11,0,0,0});  
            this.radChart1.PlotArea.XAxis.Items.AddRange(new Telerik.Charting.ChartAxisItem[] {  
            chartAxisItem1,  
            chartAxisItem2,  
            chartAxisItem3}); 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Ves
Telerik team
answered on 06 May 2009, 07:47 AM
Hi Glen ,

One possible solution here would be to use the LabelStep property of the XAxis. This property defines how often the labels will appear along the axis -- setting it to 3 would force every third label to be visible, while the rest will be hidden. For more detailed control, you can wire the BeforeLayout event. At this moment the axis items are already created (using the default AutoScale=true, that is you will not need to add items manually), so you can loop through them and hide those that you do not need. Here is an example:

void radChart1_BeforeLayout(object sender, EventArgs e) 
        { 
            int count = radChart1.PlotArea.XAxis.Items.Count; 
            foreach (var item in radChart1.PlotArea.XAxis.Items) 
            { 
                int ind = radChart1.PlotArea.XAxis.Items.IndexOf(item); 
                if (ind != 0 && ind != count / 2 && ind != count - 1) 
                    item.Visible = false
            } 
        } 


Kind regards,
Ves
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Glen Fernandes
Top achievements
Rank 1
answered on 07 May 2009, 11:36 PM
Thanks for the reply Ves. it was helpful
Tags
Chart (obsolete as of Q1 2013)
Asked by
Glen Fernandes
Top achievements
Rank 1
Answers by
Ves
Telerik team
Glen Fernandes
Top achievements
Rank 1
Share this question
or