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

[Solved] Chart issue with passing a ViewModel class with more than 1 collection

2 Answers 88 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Max
Top achievements
Rank 1
Max asked on 23 Oct 2011, 06:22 PM

Hi all

I am passing a class with 1 collection to the Grid and it works fine but with Chart it wont:

namespace ClientUpgrade.ViewModels
{
    public class MasterDetailCombined
    {
        public IEnumerable<FullWindowsStats> FullWindowsStatuses { get; set; }
        public IEnumerable<PartialWindowsStats> PartialWindowsStatuses { get; set; }
    }
}

(VIEW)
@model ClientUpgrade.ViewModels.MasterDetailCombined

@(Html.Telerik().Grid(Model.FullWindowsStatuses)
        .Name("TopGrid")
        .Columns(columns =>
  {...

However the Chart component behaves differently:

(VIEW)
@model ClientUpgrade.ViewModels.MasterDetailCombined

@(Html.Telerik().Chart<ClientUpgrade.ViewModels.MasterDetailCombined>()
    .Name("chartAjax")
    //.Theme(Html.GetCurrentTheme())
    .Title("Client Upgrade Graph")
    .Legend(legend => legend
        .Position(ChartLegendPosition.Bottom)
    )
    .Series(series =>
    {
        series.Bar(s => s.Target).Name("Target Numbers") <== ERROR HERE
...

"Cannot convert lambda expression to type 'System.Collections.IEnumerable' because it is not a delegate type."

I don't understand why I get this error. Also, Chart won't accept just "Model", you have to type the whole namespace
such as ClientUpgrade.ViewModels.MasterDetailCombined

Also, is it necessary to type @model IEnumerable<> all the time? sometimeI jsut type the namespace and it works just fine.

Any help is welcome -- Thank you!

2 Answers, 1 is accepted

Sort by
0
Shawn
Top achievements
Rank 2
answered on 25 May 2012, 04:18 AM
I'm getting the same error, but on the line that defines the axis.Categories.  Please help.
@(Html.Telerik().Chart<myTypeNameHereWithFullNamespace>()
    .Name("chartFinancial")
    .Theme("sunset")
    .Title("Plan vs Actual Benefit")
    .Legend(legend => 
        legend.Position(ChartLegendPosition.Bottom)
    )
    .Series(series =>
    {
        series.Column(s=> s.EstimatedBenefit).Name("Estimated Benefit").Labels(true);
        series.Column(s => s.ActualBenefit).Name("Actual Benefit").Labels(true);
    })
    .CategoryAxis(axis => 
        axis.Categories(s => s.MonthName) --> Error appears here
    )
    .DataBinding(dataBinding => 
        dataBinding.Ajax().Select("GetVWPlanVsActualBenefits""FinReports")
    )
    .HtmlAttributes(new { style = "width: 640; height: 480px;" })
) 
0
Shawn
Top achievements
Rank 2
answered on 26 May 2012, 03:18 AM
Nevermind, I was being a dumb-ass...the property I was referring to in the Category setup line did not exist in my EF Model. (I had forgotten to update the model after I added the field to the database!)
Tags
Chart
Asked by
Max
Top achievements
Rank 1
Answers by
Shawn
Top achievements
Rank 2
Share this question
or