Binding scatterline to local data with date axis does not work

2 posts, 0 answers
  1. Tom
    Tom avatar
    21 posts
    Member since:
    Apr 2016

    Posted 13 Mar Link to this post

    For my data in the following class:

    public class MyModel
    {
        public double Value { get; set; }
        public DateTime Date { get; set; }
    }

    I have a chart with the following configuration:

    @(Html.Kendo().Chart<MyModel>()
        .Name("MyChart")
        .Series(series =>
        {
            series.ScatterLine(MyIEnumerableData)
                .Fields("Date", "Value")
                .Style(ChartScatterLineStyle.Smooth)
                .Markers(m => m.Visible(false))
                .Highlight(h => h.Visible(false))
                .Labels(false)
                .Name("Series1");
        })
        .XAxis(x => x
            .Date()
            .Title(title => title.Text("Date"))
        )
        .YAxis(y => y
            .Numeric()
            .Title(title => title.Text("Value"))
        )
    )

    The axis range is correct, but the line is not displayed.

    Examining the data contained in the widget on the page, the Date field is populated with (example): "/Date(1156934074549)/" instead of correctly-formed datetimes.

    If I change my model to use a string instead of a datetime, and convert the datetime with .toString("yyyy-MM-dd HH:mm:ss"), the kendo widget appears to understand the data correctly, and it draws the line. This is fine as a workaround, but I should not need to convert the data like this.

    Why does the kendo widget not understand datetime data? There is no override when specifying the fields to indicate the data type, and there is no method in the series definition to do this, either.

  2. Tsvetina
    Admin
    Tsvetina avatar
    2481 posts

    Posted 15 Mar Link to this post

    Hello Tom,

    The Chart should be able to handle the data passed in such format because the XAxis has the Date() type specified explicitly. I tried your code and it works as expected in my test project. You can find it attached to this message. Could you tell what I need to modify to reproduce the problem with drawing the data?

    Additionally, you can consider using DataSource binding, like shown in this demo:
    Scatter Charts / Binding to remote data
    With this configuration, the DataSource generates a schema with explicit instructions about the data types in the loaded data items.


    Regards,
    Tsvetina
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top