How to change XAxis Label in telerik chart Programmatically?

Thread is closed for posting
2 posts, 0 answers
  1. mahmoud
    mahmoud avatar
    13 posts
    Member since:
    Feb 2014

    Posted 05 Feb 2014 Link to this post

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


  2. mahmoud
    mahmoud avatar
    13 posts
    Member since:
    Feb 2014

    Posted 05 Feb 2014 in reply to mahmoud Link to this post

    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;

            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());
    and it works awesome now :)
Back to Top