Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
695
Invalid Data Type from Data Source.
posted

I've got a chart of type ScatterLine which i am binding to a datatable. The datatable has a DateTime column and a double column. Everytime i bind to datasource i am getting the error "Invalid Data type from Data Source". I've implemented the DateTimeConverter as indicated in the documentation but to no avail. If I change the value from a dateTime to a double using the ToOADate in the table directly than it works fine. Any idea what i am doing wrong?

 

  • 28496
    Verified Answer
    Offline posted

    if you evaluate the DataType property of your DataColumn (on your DataTable), does it return DateTime?  could you change this property so that the column is typed as DateTime?

    this code works for me to create a scatterline chart with the X axis time-based.

    Series scatterLineSeries = new Series();
    scatterLineSeries.ChartType = ChartType.ScatterLine;
    this.theChart.Series.Add(scatterLineSeries);

    DataTable table = new DataTable();
    table.Columns.Add("Time", typeof(DateTime));
    table.Columns.Add("Value", typeof(double));
    table.Rows.Add(new object[ { DateTime.Now.AddDays(0.0), 0.0 });
    table.Rows.Add(new object[ { DateTime.Now.AddDays(1.0), 1.0 });
    table.Rows.Add(new object[ { DateTime.Now.AddDays(2.0), 2.0 });
    table.Rows.Add(new object[ { DateTime.Now.AddDays(4.0), 4.0 });


    scatterLineSeries.DataSource = table;
    scatterLineSeries.DataMapping = "ValueX = Time; ValueY = Value";