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

Line Chart Not Categorizing Correctly

2 Answers 39 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 2
Joshua asked on 16 Apr 2015, 02:08 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Iliana Dyankova
Telerik team
answered on 20 Apr 2015, 07:47 AM
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.

 
0
Joshua
Top achievements
Rank 2
answered on 20 Apr 2015, 11:18 AM
Cool. That works. My chart is showing up correctly now. Thanks for your help.
Tags
Chart
Asked by
Joshua
Top achievements
Rank 2
Answers by
Iliana Dyankova
Telerik team
Joshua
Top achievements
Rank 2
Share this question
or