Date on x-axis

Thread is closed for posting
3 posts, 0 answers
  1. John
    John avatar
    24 posts
    Member since:
    May 2008

    Posted 24 Jun 2008 Link to this post

    Hi,
    I am creating a chart at runtime(on the click event of a button) on to a page. The x-axis, by default expects double values. But my requirement is to plot Date in the format 'MM/DD/YYYY' format. The CustomFormat option  is not working. May be  i have coded it wrong. This is my code. Please give necessary help. Thanks in advance.

     RadChart rChart = new RadChart();
    rChart.PlotArea.XAxis.Appearance.CustomFormat = "MM/DD/YYYY";
                ChartSeries cSeries = new ChartSeries();
                cSeries.Name = "NewChart";
                ChartSeriesItem csItem1 = new ChartSeriesItem();
                csItem1.YValue = 10;
                csItem1.XValue = double.Parse("10/10/2002");
                ChartSeriesItem csItem2 = new ChartSeriesItem();
                csItem2.YValue = 20;
                csItem1.XValue = double.Parse("10/10/2003");
                ChartSeriesItem csItem3 = new ChartSeriesItem();
                csItem3.YValue = 30;
                csItem1.XValue = double.Parse("10/10/2004");
                ChartSeriesItem csItem4 = new ChartSeriesItem();
                csItem4.YValue = 40;
                csItem1.XValue = double.Parse("10/10/2005");
                ChartSeriesItem csItem5 = new ChartSeriesItem();
                csItem5.YValue = 50;
                csItem1.XValue = double.Parse("10/10/2007");

                cSeries.AddItem(csItem1);
                cSeries.AddItem(csItem2);
                cSeries.AddItem(csItem3);
                cSeries.AddItem(csItem4);
                cSeries.AddItem(csItem5);

               
                rChart.AddChartSeries(cSeries);


                placeHolder1.Controls.Add(rChart);
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 24 Jun 2008 Link to this post

    Hello John,

    We would suggest you to review this online example here that demonstrates how you can use DateTime data with the numerical axes of the RadChart control. The Appearance.ValueFormat / CustomFormat properties do not specify a custom format for parsing strings into doubles -- instead you need to pass a valid double value to the chart control via DateTime.ToOADate( ) method, then you can use the ValueFormat / CustomFormat properties to format the display of the double values that actually are your DateTime data values.

    Hope this helps.


    All the best,
    Manuel
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. John
    John avatar
    24 posts
    Member since:
    May 2008

    Posted 25 Jun 2008 Link to this post

    Even though the example you gave didnt help me much... it paved the way for the successful enhancement :). Thanks a Lot Manuel.
Back to Top