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

Set ChartSeries datatype

1 Answer 11 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 10 Aug 2012, 03:22 PM
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;

1 Answer, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 15 Aug 2012, 09:10 AM
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.
Tags
Chart (Obsolete)
Asked by
Sam
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or