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

Series.DefaultLabelValue format to ShortDate

1 Answer 127 Views
Chart (obsolete as of Q1 2013)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Fernan
Top achievements
Rank 1
Fernan asked on 28 Dec 2010, 05:25 PM
Hi,

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.

Thanks,      

1 Answer, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 29 Dec 2010, 06:19 PM
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()
        {
            InitializeComponent();
            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>();
            dates.Add("2010-06-01");
            dates.Add("2010-07-01");
            dates.Add("2010-08-01");
            dates.Add("2010-09-01");
            dates.Add("2010-10-01");
            dates.Add("2010-11-01");
  
            List<double> values2 = new List<double>();
            values2.Add(197);
            values2.Add(441);
            values2.Add(425);
            values2.Add(396);
            values2.Add(108);
            values2.Add(170);
  
            int k = 0;
  
            foreach (string strdate in dates)
            {
                DataRow cdr = chartdata.NewRow();
                cdr[0] = DateTime.Parse(strdate);
                cdr[1] = values2[k];
  
                chartdata.Rows.Add(cdr);
  
                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();
                series2.Items.Add(item);
            };
  
            RadChart1.AutoLayout = true;
            RadChart1.Series.Add(series2);
  
            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;
            this.Controls.Add(RadChart1);
        }
    }

Best wishes,
Evgenia
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.
Tags
Chart (obsolete as of Q1 2013)
Asked by
Fernan
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or