Set ChartSeries datatype

Thread is closed for posting
2 posts, 0 answers
  1. Sam
    Sam avatar
    20 posts
    Member since:
    Apr 2011

    Posted 10 Aug 2012 Link to this post

    I am changing the chart series programmatically and the data type is not numeric it is a datetime field. How do I change this value type? here is my code so far:

    (it's a switch statement)

    case "HOURS":
                                      sdsProjectVideos.SelectCommand = "asGetVideosByProjectIDSortHours";
                                      RadChart1.ChartTitle.TextBlock.Text = "HOURS WATCHED";
                                      sdsProjectChart.SelectCommand = "asGetVideosByProjectIDSortHoursChart";
                                      ChartSeries chartSeries = new ChartSeries();
                                      chartSeries.Name = "Hours Watched";
                                      chartSeries.DataYColumn = "HoursWatched";
                                      lblHours.Font.Underline = true;
  2. Ves
    Ves avatar
    2926 posts

    Posted 15 Aug 2012 Link to this post

    Hi Sam,

    You can use the DateTime.ToOADate instance method to convert a DateTime value to a double value, which will be recognized by RadChart as shown in this example.

    There is another approach for databound chart -- you can wire ItemDataBound event and update each ChartSeriesItem's XValue:

    void RadChart1_ItemDataBound(object sender, Telerik.Charting.ChartItemDataBoundEventArgs e)
            e.SeriesItem.XValue = ((DateTime)(e.DataItem as DataRowView)["Date"]).ToOADate();

    Kind regards,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top