Custom X Axis Labels

Thread is closed for posting
3 posts, 0 answers
  1. Gordon
    Gordon avatar
    3 posts
    Member since:
    Jul 2007

    Posted 13 Aug 2007 Link to this post

    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);

    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. Kiril
    Kiril avatar
    158 posts

    Posted 13 Aug 2007 Link to this post

    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;  
    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)));  

    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.


    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Gordon
    Gordon avatar
    3 posts
    Member since:
    Jul 2007

    Posted 13 Aug 2007 Link to this post

    Many many thanks. This worked perfectly.

    Thank you again.
Back to Top