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

How to hide the x-axis scale and show a user custom label?

1 Answer 71 Views
Chart
This is a migrated thread and some comments may be shown as answers.
PEIYANG
Top achievements
Rank 1
PEIYANG asked on 13 Sep 2012, 06:27 PM
At first the x-axis is show scale ( 5,6,7,8,9,10,11) normally, now I want to hide the scale axis,and use "A" to replace 5,and use "B" to replace 10 as x-axis label? How to do that? This is the picture:https://www.yousendit.com/download/TEhXTG0rcTJwaFF3anNUQw

This is my code,but seems wrong.
this.RadChart1.DefaultView.ChartArea.AxisX.AxisLabelsVisibility = Visibility.Collapsed;
             for (int i = 0; i < RadChart1.SeriesMappings.Count; i++)
             for(int j=0;j< RadChart1.SeriesMappings[i].ItemMappings.Count;j++)
             {
                 //if( RadChart1.SeriesMappings[i].ItemMappings[j]
                // RadChart1.SeriesMappings[i].ItemMappings[j].DataPointMember.ToString();
                 if(??==5)
                     ??.xlabel="A";
             }

1 Answer, 1 is accepted

Sort by
0
Accepted
Petar Kirov
Telerik team
answered on 18 Sep 2012, 03:38 PM
Hi Peiyang,

If you don't need to know the exact XValue-s of the data points (and want only A, B, C... to be shown for each item on the X Axis) then you don't need to specify ItemMapping for the XValue, and on the DataBound you can set each of the datapoints an XCategory value of A, B, C, etc.
radChart.DataBound += new EventHandler<ChartDataBoundEventArgs>(chart_DataBound);
 
void chart_DataBound(object sender, ChartDataBoundEventArgs e)
{
    char c = 'A';
 
    foreach (var item in chart.DefaultView.ChartArea.DataSeries[0])
    {
        item.XCategory = "" + c;
        c++;
    }
}

Or you can listen to the RangeChanged event of the Axis X and change the TickMark labels:
chart.DefaultView.ChartArea.AxisX.RangeChanged +=new EventHandler(AxisX_RangeChanged);
 
void AxisX_RangeChanged(object sender, EventArgs e)
{
    char c = 'A';
 
    foreach (var item in chart.DefaultView.ChartArea.AxisX.TickPoints)
    {
        item.Label = "" + c;
        c++;
    }
}

 I hope this helps.

All the best,
Petar Kirov
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Tags
Chart
Asked by
PEIYANG
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Share this question
or