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

Date filter not working

3 Answers 163 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Jhon
Top achievements
Rank 1
Jhon asked on 10 Jan 2019, 03:10 PM

Hi, I´m using a date filter, but it shows all the data. I´ve done it like this:

On properties > Report parameters > Add > Type: DateTime Visible: True

On properties > Filters > on Expression I have =Trim(Fields.Date) on Operator = on Value = Fields.Date

On preview I choose a date, but all records appear.

3 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 14 Jan 2019, 01:28 PM
Hello, Jhon,

Thank you for trying out the Kendo UI for ASP.NET MVC chart.

I suspect that the Fields.Date property in the data is not a DateTime but it is rather a string type since the Trim() method is a string method. (Unless it is a custom static method of course).

You can see a runnable example which adds a filter as part of its data source and it works as expected:

https://dojo.telerik.com/@bubblemaster/iGofebeQ

So in case, the field is indeed a string, it needs to be transformed into a DateTime on the server or to use a data source with a schema in the Razor definition so that the Chart can work with the correct types:

Example of Razor data source with a schema:

.DataSource(d => d
   .Model(m => {
      m.Id(f => f.Id);
      m.Field("CreatedAt", typeof(DateTime));
   })

In case you need further assistance, it would be helpful to see the model as well as the Chart and data source declaration.

Kind Regards,
Alex Hajigeorgieva
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.
0
Jhon
Top achievements
Rank 1
answered on 14 Jan 2019, 02:46 PM
Hi. But the data comes from a data base, do you have an example with one?
0
Alex Hajigeorgieva
Telerik team
answered on 14 Jan 2019, 04:00 PM
Hi, Jhon,

It does not matter where the data comes from. The database querying can be done in any way that you prefer, however, the expected response is Json with an IEnumerable of the model to which the chart is bound to.

public ActionResult Orders_Read()
{       // data base call
    var result = Enumerable.Range(1, 10).Select(i => new OrderViewModel
    {
        OrderID = i,
        Freight = i * 10,
        OrderDate = DateTime.Now.AddDays(i),
        ShipName = "ShipName " + i,
        ShipCity = "ShipCity " + i
    });
 
    return Json(result);
}

@(Html.Kendo().Chart<ChartWithFilter.Models.OrderViewModel>()
    .Name("chart")
    .Series(series =>
    {
        series
            .Line(model => model.Freight, categoryExpression: model => model.OrderDate);
    })
    .CategoryAxis(axis => axis
    .Date()
    .BaseUnit(ChartAxisBaseUnit.Weeks)
    )
    .DataSource(dataSource => dataSource
        .Read(read => read.Action("Orders_Read", "Chart"))
        .Filter(f=>f.Add(x=>x.OrderDate).IsGreaterThanOrEqualTo(new DateTime(2019,1,10)))
    )
)

If you can provide the model, chart definition and data source, I can attempt to replicate this behaviour. Since I do not have it, I am sending you a runnable example for MVC attached here. You should be able to build it, restore the packages and run it. (let me know in case you face any difficulties)

You may find other examples in this repository as well:

https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/chart/

Regards,
Alex Hajigeorgieva
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
Jhon
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Jhon
Top achievements
Rank 1
Share this question
or