RadChart Month Name on XAxis

Thread is closed for posting
2 posts, 0 answers
  1. Tahir Ahmed
    Tahir Ahmed avatar
    11 posts
    Member since:
    May 2011

    Posted 04 Jul 2012 Link to this post

    Hello there,

    I am getting two columns from database (using SQL Data Source) namely points and month, I am summing the points based on month number for example a person gained 500 points in month 6 (which means June). The data appears in this format.

    500, 6
    1100, 7
    900, 8
    430 9

    and so on...

    Now I am binding the points (the first column) to y-axis of rad chart and month number to x-axis. But I want x-axis values to appear as month names instead of numeric values like June or Jun for 6, July or Jul for 7 and so on...

    How can I convert xaxis numeric values to month names ?

  2. Petar Kirov
    Petar Kirov avatar
    425 posts

    Posted 09 Jul 2012 Link to this post

    Hello Tahir Ahmed,

    A straight forward solution would be to use the BeforeLayout event of the RadChart to change the labels of the X-Axis (after the data is loaded ) from numbers to month names. Here is how to implement this in code behind:

    Create the event handler and attach it to your RadChart. You can do this on Page_Load.
    this.radChart.BeforeLayout += new EventHandler<EventArgs>(radChart_BeforeLayout);

    Implement your own converter in the BeforeLayot event handler:
    void radChart_BeforeLayout(object sender, EventArgs e)
            string[] months = new string[] { "Jan", "Feb", "Mar", "Apr",
                    "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
            foreach (var axisItem in this.radChart.PlotArea.XAxis.Items)
               axisItem.TextBlock.Text = months[Int32.Parse(axisItem.TextBlock.Text) - 1];     

    Please note that you should probably sort your data by month so that it looks correctly.

    Petar Kirov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top