Series.DefaultLabelValue format to ShortDate

Thread is closed for posting
2 posts, 0 answers
  1. Fernan
    Fernan avatar
    15 posts
    Member since:
    May 2010

    Posted 28 Dec 2010 Link to this post


    I am using RadChart to show datetime values in X Axis. I need to show in the values, both values: x and y.

    I use the property DefaultLabelValue in Series object: this.radChart1.Series[0].DefaultLabelValue = "#Y";      

    I need show X value in shortdate format. If I write this.radChart1.Series[0].DefaultLabelValue = "#X,#Y"; , the values are doubles and not datetime.

  2. Evgenia
    Evgenia avatar
    1437 posts

    Posted 29 Dec 2010 Link to this post

    Hello Fernan,

    To be able to show Series Labels as DateTime you can use the Label property of each ChartSeriesItem and you convert the OADate to DateTime. Here is what I mean:
    public partial class Form1 : Form
            public Form1()
                RadChart RadChart1 = new RadChart();
                DataTable chartdata = new DataTable();
                chartdata.Columns.Add("date", typeof(DateTime));
                chartdata.Columns.Add("value", typeof(double));
                List<string> dates = new List<string>();
                List<double> values2 = new List<double>();
                int k = 0;
                foreach (string strdate in dates)
                    DataRow cdr = chartdata.NewRow();
                    cdr[0] = DateTime.Parse(strdate);
                    cdr[1] = values2[k];
                ChartSeries series2 = RadChart1.CreateSeries("value", Color.LightGreen, Color.LightGreen, ChartSeriesType.StackedBar);
                foreach (DataRowView drv in chartdata.DefaultView)
                    ChartSeriesItem item = new ChartSeriesItem();
                    item.XValue = DateTime.Parse(drv["date"].ToString()).ToOADate();
                    item.YValue = Math.Round(double.Parse(drv["value"].ToString()), 1);
                    item.Label.TextBlock.Text = DateTime.FromOADate(item.XValue).ToShortDateString();
                RadChart1.AutoLayout = true;
                RadChart1.PlotArea.XAxis.AutoScale = false;
                RadChart1.PlotArea.XAxis.LayoutMode = Telerik.Charting.Styles.ChartAxisLayoutMode.Inside;
                RadChart1.PlotArea.XAxis.Appearance.ValueFormat = Telerik.Charting.Styles.ChartValueFormat.ShortDate;
                RadChart1.PlotArea.XAxis.Appearance.CustomFormat = "MMM-yyyy";
                double step = DateTime.Parse("2010-06-01").AddMonths(1).ToOADate();
                RadChart1.PlotArea.XAxis.AddRange(DateTime.Parse("2010-06-01").ToOADate(), DateTime.Parse("2010-12-01").ToOADate(), 31);
                RadChart1.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = -45;
                RadChart1.PlotArea.YAxis.AutoScale = true;

    Best wishes,
    the Telerik team
    Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
Back to Top