Line Chart Not Categorizing Correctly

3 posts, 1 answers
  1. Joshua
    Joshua avatar
    8 posts
    Member since:
    Mar 2015

    Posted 16 Apr 2015 Link to this post

    Picture of the chart: http://i.imgur.com/K88FEJd.png

     

    I cannot get the chart to do categories correctly. If you look at the dates in the following data they are all different except if it is a different department. But in the picture they seem to merge for some reason. Can someone explain this?

    Here is my return JSON data...

    [{"DepartmentName":"Information Technology","TicketDate":"2015-04-01","TicketCt":3},{"DepartmentName":"Information Technology","TicketDate":"2015-04-16","TicketCt":1},{"DepartmentName":"Human Resources","TicketDate":"2015-04-14","TicketCt":1},{"DepartmentName":"Human Resources","TicketDate":"2015-04-15","TicketCt":1}]

     Here is my code:

    @(Html.Kendo().Chart<Guardian.ViewModels.TicketCount>()
                              .Name("LastTwoWeeks_Tickets")
                              .Title("Ticket Count In The Past 30 Days")
                              .Legend(legend => legend
                                  .Position(ChartLegendPosition.Top)
                              )
                              .DataSource(ds => ds.Read(read => read
                                  .Action("_NewTicketCtOverTwoWeeks_Read", "Home"))
                                  .Group(group => group.Add(model => model.DepartmentName))
                                  .Sort(sort => sort.Add(model => model.TicketDate).Ascending())
                              )
                              .Series(series => series.Line(model => model.TicketCt).Name("#= group.value #"))
                              .CategoryAxis(axis => axis
                                  .Categories(model => model.TicketDate)
                              )
                              .ValueAxis(axis => axis.Numeric()
                                  .Labels(labels => labels.Format("{0:N0}"))
                              )
                              .Tooltip(tooltip => tooltip
                                  .Visible(true)
                                  .Shared(true)
                                  .Format("{0:N0}")
                              )
                        )

     

     

  2. Answer
    Iliana Nikolova
    Admin
    Iliana Nikolova avatar
    2592 posts

    Posted 20 Apr 2015 Link to this post

    Hi Joshua,

    The observed issue is due to the following: 
    - By design all categorical charts require a matching set of data points for each series;
            - The categories in a grouped chart are created depending on the first series.

    In order to avoid this problem you should use series.categoryField instead of categoryAxis.field
    //....
    .Series(series => series.Line(model => model.TicketCt, categoryExpression: model => model.TicketDate).Name("#= group.value #"))

    Regards,
    Iliana Nikolova
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Joshua
    Joshua avatar
    8 posts
    Member since:
    Mar 2015

    Posted 20 Apr 2015 Link to this post

    Cool. That works. My chart is showing up correctly now. Thanks for your help.
Back to Top