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

Binding scatterline to local data with date axis does not work

1 Answer 51 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Iron
Tom asked on 13 Mar 2019, 01:07 PM

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.

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 15 Mar 2019, 09:44 AM
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.
Tags
Chart
Asked by
Tom
Top achievements
Rank 1
Iron
Answers by
Tsvetina
Telerik team
Share this question
or