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

2 posts, 1 answers
    PEIYANG avatar
    65 posts
    Member since:
    Jul 2012

    Posted 13 Sep 2012 Link to this post

    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:

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

  2. Answer
    Petar Kirov
    Petar Kirov avatar
    425 posts

    Posted 18 Sep 2012 Link to this post

    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;

    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;

     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.

Back to Top