0

我有这个错误:http: //i.imgur.com/C4xKucH.png

我知道我的消息模型是可查询的。我打算使用不同的模型,但我不太清楚它为什么/如何使用我的“消息”模型。我打算使用我的模型“GraphModel”。这就是我的视图的样子:

@model ChatProj.Models.GraphModel
@using Infragistics.Web.Mvc
@using System.Linq
@{  
    ViewBag.Title = "RealTime chart";  
} 
<style>  
    #chart1  
    {  
        position: relative;  
        float: left;  
    }  
    #legend1  
    {  
        position: relative;  
        float: left;  
        margin-left: 15px;  
    }  
</style>
<script type="text/javascript">
    $.ig.loader({
        scriptPath: "js/",
        cssPath: "css/",
        resources: "igDataChart.Category"
    });

    $.ig.loader(function () {
        var queued = 0, data = [], updateData, currCPU = 10.0, currMem = 1024, connection;

        $("#chart1").igDataChart("option", "dataSource", data);
        $("#chart1").igDataChart("option", "series", [{
            name: "series1", dataSource: data
        }, {
            name: "series2", dataSource: data
        }]);
        $("#chart1").igDataChart("option", "axes", [{
            name: "xAxis", dataSource: data
        }]);

        var updateData = function (newItem) {
            data.push(newItem);
            $("#chart1").igDataChart("notifyInsertItem", currCPU, data.length - 1, newItem);
            queued++;
            if (queued > 2000) {
                oldItem = data[0];
                data.shift();
                $("#chart1").igDataChart("notifyRemoveItem", currCPU, 0, oldItem);
                queued--;
            }
        }

        var generateRandomItem = function () {
            var newItem = {}, currDate = new Date(),
            hours = currDate.getHours(), minutes = currDate.getMinutes(),
            seconds = currDate.getSeconds();

            if (Math.random() > .5) {
                currCPU += Math.random() * 2.0;
            } else {
                currCPU -= Math.random() * 2.0;
            }

            if (Math.random() > .5) {
                currMem += Math.random() * 5.0;
            } else {
                currMem -= Math.random() * 5.0;
            }

            if (currMem <= 0) {
                currMem = 0;
                currMem += Math.random() * 5.0;
            }

            if (currMem > 4096) {
                currMem = 4096;
                currMem -= Math.random() * 5.0;
            }

            if (currCPU <= 0) {
                currCPU = 0;
                currCPU += Math.random() * 2.0;
            }

            if (currCPU > 100) {
                currCPU = 100;
                currCPU -= Math.random() * 2.0;
            }

            if (hours > 12) {
                hours = hours - 12;
            }
            if (hours < 10) {
                hours = "0" + hours;
            }
            if (minutes < 10) {
                minutes = "0" + minutes;
            }
            if (seconds < 10) {
                seconds = "0" + seconds;
            }

            newItem.DateString = hours + ":" + minutes + ":" + seconds;
            newItem.CPUUsage = currCPU;
            newItem.MemUsage = currMem;

            return newItem;
        }

                window.setInterval(function () {
                    var newItem = generateRandomItem();

                    updateData(newItem);
                }, 33);


        /*connection = $.connection('/MessageDataStream');

        connection.received(function (dataItem) {
            var newItem = dataItem;

            updateData(newItem);
        });

        connection.start();*/
    });
    </script>
@(  
 Html.Infragistics().DataChart(Model.AsQueryable())  
               .ID("chart1")  
               .Width("500px")  
               .Height("500px")  
               .VerticalZoomable(true)  
               .HorizontalZoomable(true)  
               .WindowResponse(WindowResponse.Immediate)  
               .Legend((l) =>  
               {  
                   l.ID("legend1").Width("150px");  
               })  
               .Axes((axes) =>  
               {  
                   axes.CategoryX("xAxis").Label((item) => item.DateString)  
                       .LabelExtent(50);  
                   axes.NumericY("yAxis")  
                       .MinimumValue(0)  
                       .MaximumValue(100)  
                       .LabelExtent(30);  
                   axes.NumericY("yAxis2")  
                       .MinimumValue(0)  
                       .MaximumValue(4096)  
                       .LabelExtent(40)  
                       .MajorStroke("transparent")  
                       .LabelLocation(AxisLabelsLocation.OutsideRight);  
               })  
               .Series((series) =>  
               {  
                   series  
                   .Line("series1")  
                   .Title("CPU usage")  
                   .XAxis("xAxis").YAxis("yAxis")  
                   .ValueMemberPath((item) => item.CPUUsage)  
                   .Thickness(2);  

                   series
                   .Line("series2")
                   .Title("Available Memory")
                   .XAxis("xAxis").YAxis("yAxis2")
                   .ValueMemberPath((item) => item.MemUsage)
                   .Thickness(2);
               }).DataBind().Render()


 )

这是我的控制器的样子:

public ActionResult Chart()
        {
            return View(new GraphModel());  
        }

我想知道为什么它试图使用我的“消息”而不是我想要的“GraphModel”模型?

编辑:“GraphModel”看起来像这样:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ChatProj.Models
{
    public class GraphModel
        : List<GraphData>
    {

    }

    public class GraphData
    {
        //public double messagesPM { get; set; }
        //public string DateString { get; set; }

        public string DateString { get; set; }
        public double CPUUsage { get; set; }
        public double MemUsage { get; set; }

    }
}

“消息”模型如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ChatProj.Models
{
    public class Message
    {
        public int MessageID { get; set; }
        public string Name { get; set; }
        public string MessageString { get; set; }
        public DateTime MessageDate { get; set; }

    }
}
4

0 回答 0