Kenodo ui mvc chart - Datasource grouping not working

265 views Asked by At

I have a kendo graph of running total of ounces applied. When I do not apply the “Group” setting, it is rendering the entire year to date, as intended. However, when I apply a group setting, for example by people’s names, it is only rendering 2 months’ worth of data.

I have a list of the following class

public class BreakoutData
{
    public string BreakoutField { get; set; }
    public decimal TotalAcres { get; set; }
    public decimal RunningAcresTotal { get; set; }
    public decimal TotalOunces { get; set; }
    [DisplayName("")]
    public decimal RunningOuncesTotal { get; set; }
    public DateTime TransactionDay { get; set; }
    public Color Color { get; set; }
}

That will return a list of running totals from the begging to the year todate. Here is what it looks like with group applied.

Code:

    @(
        Html.Kendo().Chart<BreakoutData>()
            .Name("BreakoutChart")
            .Title("Breakout")
            .Series(series =>
            {
                series.Line(model => model.RunningOuncesTotal,  model => model.Color.ToString(), model => model.TransactionDay.ToString()).Name("") ;
            })
            .CategoryAxis(axis => axis
                .Categories(m => m.TransactionDay)
                .Date()
                .BaseUnit(ChartAxisBaseUnit.Days)
                .Labels(labels =>
                {
                    labels.Format("MM/dd/yyyy");
                    labels.Rotation(-45);
                })
            )
            .DataSource(d => d.Read(read => read.Action("LoadBreakOutChart", "Breakout").Data("getAdditionalData"))
                .Group(m => m.Add(g => g.BreakoutField))
            )
            .Tooltip(
                tooltip => tooltip.Visible(true)
                    .Template("#=kendo.toString(category, 'ddd, MMM dd,yyyy')#" +
                              "<br> #=series.name # : <strong>#=value #</strong>")
            )
            .Legend(legend => legend.Position(ChartLegendPosition.Bottom))
            .Events(e => e.DataBound("HideLoading"))
            .HtmlAttributes(new { style = "height:500px;min-width:900px;" })
            .Pdf(p =>
            {
                p.FileName("text.pdf");
                p.Author("FarmChem");
            })       
    )
1

There are 1 answers

0
Farm3256 On

If you have an issue with the chart not rendering correctly if your missing datapoint try adding .CategoryField('fieldname') and remove the .Categories(m => m.TransactionDay).

I was able to solve my issue with these changes.