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";
                                      RadChart1.Series.Clear();
                                      ChartSeries chartSeries = new ChartSeries();
                                      chartSeries.Name = "Hours Watched";
                                      chartSeries.DataYColumn = "HoursWatched";
                                      RadChart1.Series.Add(chartSeries);
                                      lblHours.Font.Underline = true;
                                      break;
  2. Ves
    Admin
    Ves avatar
    2879 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,
    Ves
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top