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

Custom X Axis Labels

2 Answers 285 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.
Gordon
Top achievements
Rank 1
Gordon asked on 13 Aug 2007, 06:55 AM
Is it possible at all to add custom labels to the XAxis programmatically? I am using the following code

ChartSeries pSeries = new ChartSeries();  
for (int i = 0; i < iCount; i++) {
    // Add a new item
    pSeries.AddItem((double)pGroup.GroupCount, pGroup.GroupName);
}
radChart.Series.Add(pSeries);

However the XAxis is always just labelled 1,2,3,4,5 etc.

Is there a way to set this label as I add items to the series?

2 Answers, 1 is accepted

Sort by
0
Kiril
Telerik team
answered on 13 Aug 2007, 12:18 PM

Hello Gordon,

Thank you for bringing the custom axis label issue to our attention. We do need to simplify using custom axis labels, and we need to make a clearer distinction between dataitem label (the label that appears on top of the bar, or line point), and the axis label.

The code you have sent us sets data value labels (the ones on top of the data point in the plot area).  Adding custom axis labels cannot be done by adding items to the items collection of the series. Instead, you have to work directly with the Items collection of the XAxis in the PlotArea of the RadChart.

To add your own labels to the XAxis, please use the following codeblock. I have incorporated the solution in the code you have sent us:

ChartSeries pSeries = new ChartSeries();  
int iCount = 5;  
radChart1.PlotArea.XAxis.AutoScale = false;  
radChart1.PlotArea.XAxis.Items.Clear();  
for (int i = 0; i < iCount; i++)  
{  
    // Add a new item  
    pSeries.AddItem((double)i * 2, Convert.ToString(i*2));  
    radChart1.PlotArea.XAxis.Items.Add(new ChartAxisItem(Convert.ToString(iCount - i)));  
}  
 
radChart1.Series.Add(pSeries); 

The last line in the for cycle in the codeblock above sets the Xaxis labels to descending values from the value of the iCount down to 0.

Please note the line:

radChart1.PlotArea.XAxis.AutoScale = false;   

Setting this property to false is required for the custom axis labels to work.

Please let me know if you need any additional help with this problem. Your feedback is very important to us, as it shows us the areas we need to improve most rapidly. Thanks again.

 
Greetings,

Kiril
the Telerik team


Instantly find answers to your questions at the new Telerik Support Center
0
Gordon
Top achievements
Rank 1
answered on 13 Aug 2007, 03:48 PM
Many many thanks. This worked perfectly.

Thank you again.
Tags
Chart (obsolete as of Q1 2013)
Asked by
Gordon
Top achievements
Rank 1
Answers by
Kiril
Telerik team
Gordon
Top achievements
Rank 1
Share this question
or