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

Stacked Bar using AJAX - how to project the model?

1 Answer 94 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Nathan J Pledger
Top achievements
Rank 2
Nathan J Pledger asked on 08 Apr 2015, 04:48 PM

 

I have restricted horizontal space on a page, but have multiple values to display in a graph. I thought a single-column, stacked column chart would fit the bill. I'm interested in showing proportion of values.

 I have a simple model:

  •  UserName
  • Items

Using the AJAX mechanism shown here http://demos.telerik.com/aspnet-mvc/bar-charts/remote-data-binding I can get the chart to display using the following code:

@(Html.Kendo().Chart<RequestLoadingSummaryAggregate>()
    .Name("resourceLoadingChart")
    .Title("Resources")
    .Legend(legend=>legend.Visible(false))
    .DataSource(dataSource=>dataSource.Read(read=>read.Action("RequestLoadingSummary","Home")))
    .Series(series =>
    {
        series.Column(model => model.Items).Name("Resource");
    })
    .CategoryAxis(axis=>axis
        .Categories(model=>model.UserName)
        .Labels(labels=>labels.Rotation(-90))
        .MajorGridLines(lines=>lines.Visible(false))
        
    .ValueAxis(axis=>axis.Numeric()
        .Labels(labels=>labels.Format("{0:N0}"))
        .MajorUnit(100)
        .Line(line=>line.Visible(false))
        )
    .Tooltip(tooltip=>tooltip
        .Visible(true)
        .Format("{0:N0}")
        )
        .ChartArea(chartArea=>
        chartArea.Height(400))
      )

But I cannot get it to work as a Stacked Column using the additional defaults:

 

.SeriesDefaults(seriesDefaults =>
    seriesDefaults.Column().Stack(ChartStackType.Normal)
)

How can I project the model from the AJAX result into a form that the chart can understand such that the values occupy a single column with multiple values?

Thanks

 

Nathan

1 Answer, 1 is accepted

Sort by
0
Accepted
Iliana Dyankova
Telerik team
answered on 10 Apr 2015, 02:14 PM
Hi Nathan,

In order to get a stacked chart you need at least two series. If I understand correctly each UserName should be a separate bar? This can be achieved as grouping the dataSource (like in this online demo): 
//....
.DataSource(dataSource => dataSource
   .Read(read => read.Action("RequestLoadingSummary", "Home"))
   .Group(group => group.Add(model => model.UserName))
)
In case I am missing something please elaborate a bit more on the exact scenario you are trying to implement - this way I would be able to advice you further and provide concrete recommendations.

Regards,
Iliana Nikolova
Telerik
 

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

 
Tags
Chart
Asked by
Nathan J Pledger
Top achievements
Rank 2
Answers by
Iliana Dyankova
Telerik team
Share this question
or