2

请帮我解决这个问题:

方法'Infragistics.Web.Mvc.InfragisticsSuite 的类型参数。DataChart(System.Linq.IQueryable)' 不能从用法中推断出来。尝试明确指定类型参数。

模型

            namespace MvcApplication2.Models
            {
                public class StockMarketDataPoint
                {
                    public double Open { get; set; }
                    public double High { get; set; }
                    public double Low { get; set; }
                    public double Close { get; set; }
                    public double Volume { get; set; }
                    public DateTime Date { get; set; }
                    public string DateString { get { return Date.ToShortDateString(); } }
                }
            }

控制器

                 public class Default1Controller : Controller
                 {
                        public ActionResult Index()
                        {
                                List<StockMarketDataPoint> stockMarketData = new List<StockMarketDataPoint>
                        {
                                new StockMarketDataPoint { Date = DateTime.Parse("2.1.2010"), Open = 1000, High = 1028.75, Low = 985.25, Close = 1020, Volume = 1995 },

                                new StockMarketDataPoint { Date = DateTime.Parse("3.1.2010"), Open = 1020, High = 1032.5, Low = 999.5, Close = 1021, Volume = 1964.5 },

                            new StockMarketDataPoint { Date = DateTime.Parse("4.1.2010"), Open = 1021, High = 1033.5, Low = 996, Close = 1033, Volume = 1974.75 },

                            new StockMarketDataPoint { Date = DateTime.Parse("5.1.2010"), Open = 1033, High = 1062, Low = 1018.75, Close = 1042, Volume = 1978.5 },

                            new StockMarketDataPoint { Date = DateTime.Parse("6.1.2010"), Open = 1042, High = 1058.5, Low = 1019.75, Close = 1029, Volume = 1979 },

                            new StockMarketDataPoint { Date = DateTime.Parse("7.1.2010"), Open = 1029, High = 1050.75, Low = 1006, Close = 1042, Volume = 1990 }
                        };

                        return View(stockMarketData);
                    }
                }

索引.cshtml

            @using Infragistics.Web.Mvc

            @model MvcApplication2.Models.StockMarketDataPoint

            @{
                Layout = null;
            }

            <!DOCTYPE html>

            <html>
            <head>
                <meta name="viewport" content="width=device-width" />
                <title>Index</title>
                <link type="text/css" href="@Url.Content("~/Content/Site.css")" rel="Stylesheet" />
                <link type="text/css" href="@Url.Content("~/Content/jquery.mobile.structure-1.1.0.css")" rel="Stylesheet" />    
                <script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")"></script>
                <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.mobile-1.1.0.min.js")"></script>
                <script type="text/javascript" src="@Url.Content("~/Scripts/modernizr-2.5.3.js")"></script>
                <script type="text/javascript" src="@Url.Content("~/Infragistics/js/infragistics.loader.js")"></script>

            </head>
            <body>

                Here is a chart 

                @(Html.Infragistics().Loader()
                    .ScriptPath(Url.Content("~/Infragistics/js/"))
                    .CssPath(Url.Content("~/Infragistics/css/"))
                    .Render()
                    )

                 @(Html.Infragistics().DataChart(Model)
                .ID("chart")
                .Width("500px")
                .Height("500px")
                .CrosshairVisibility(Visibility.Visible)
                .DataBind()
                .Render()
            )

            </body>
            </html>
4

1 回答 1

4

您将视图中的模型定义为

 @model MvcApplication2.Models.StockMarketDataPoint

在传递列表时?尝试:

@model IQueryable<MvcApplication2.Models.StockMarketDataPoint>

编辑:还要确保将 IQueryable 传递给视图,如

return View(stockMarketData.AsQueryable());

如果必须的话。这将修复模型错误,但仍然无法让您启动并运行图表 - 缺少轴和系列定义。例如测试了这个:

@(Html.Infragistics().DataChart(Model)
    .ID("chart")
    .Width("500px")
    .Height("500px")
    .CrosshairVisibility(Visibility.Visible)
    .Axes((axes) =>
    {
        axes.CategoryX("xAxis")
            .Label((item) => item.Date)
            .LabelVisibility(Visibility.Collapsed);
        axes.NumericY("yAxis");
    })
    .Series(series =>
    {
        series.Financial("stockSeries")
        .CloseMemberPath("Close").OpenMemberPath("Open").HighMemberPath("High").LowMemberPath("Low")
        .XAxis("xAxis").YAxis("yAxis");
    })
    .DataBind()
    .Render()
)

我建议您稍微熟悉一下图表:)相关示例博客

于 2013-02-19T15:42:16.127 回答