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

How to change XAxis Label in telerik chart Programmatically?

1 Answer 158 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
mahmoud
Top achievements
Rank 1
mahmoud asked on 05 Feb 2014, 10:35 AM
I have chart with some values as shown on the picture. I want X label value to be project name, but now I have data in series and on x i have (1) not the project name. so How to force X values to bound the project name from database Programmatically ?
 heres my code:

ChartSeries series1 = new ChartSeries("Estimated Hours", ChartSeriesType.Bar);
ChartSeries series2 = new ChartSeries("Actual Hours", ChartSeriesType.Bar);
ChartSeries series3 = new ChartSeries("Variance", ChartSeriesType.Bar);

foreach (DataRow dtrow in dt.Rows)
{
series1.Items.Add(new ChartSeriesItem(Convert.ToDouble(dtrow["estimated_total"]), dtrow["estimated_total"].ToString()));
series2.Items.Add(new ChartSeriesItem(Convert.ToDouble(dtrow["actual_total"]), dtrow["actual_total"].ToString()));
series3.Items.Add(new ChartSeriesItem(Convert.ToDouble(dtrow["variance_total"]), dtrow["variance_total"].ToString()));

}

RadChart1.Series.Clear();
RadChart1.Series.Add(series1);
RadChart1.Series.Add(series2);
RadChart1.Series.Add(series3);

1 Answer, 1 is accepted

Sort by
0
mahmoud
Top achievements
Rank 1
answered on 05 Feb 2014, 11:32 AM
I found the solution in older posts so i'd like to share it with y'all
out of the foreach loop I did this:

       RadChart1.PlotArea.XAxis.AutoScale = false;
        RadChart1.PlotArea.XAxis.Items.Clear();

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            //CURRENT_FIELD is a constant string holding the appropriate column name
            ChartAxisItem axisItem = new ChartAxisItem(dt.Rows[i]["project_name"].ToString());
            RadChart1.PlotArea.XAxis.Items.Add(axisItem);
        }
and it works awesome now :)
Tags
Chart (Obsolete)
Asked by
mahmoud
Top achievements
Rank 1
Answers by
mahmoud
Top achievements
Rank 1
Share this question
or