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

RadChart Month Name on XAxis

1 Answer 127 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Tahir Ahmed
Top achievements
Rank 1
Tahir Ahmed asked on 04 Jul 2012, 11:17 AM
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 ?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 09 Jul 2012, 02:37 PM
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.

Regards,
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.
Tags
Chart (Obsolete)
Asked by
Tahir Ahmed
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Share this question
or