Jquery jqplot并用asp.net mvc模型进行渲染

Jquery jqplot并用asp.net mvc模型进行渲染,jquery,json,asp.net-mvc-3,jqplot,Jquery,Json,Asp.net Mvc 3,Jqplot,在我的asp.net mvc 3.0应用程序中,我将绘制一个图表,其X轴包含日期值,y轴包含每天的视图。对于图表绘制,我使用json结果传递给它。模型如下: public class MyDateModel { public string Date { get; set; } public int Views { get; set; } } 以下是行动: public ActionResult Index() {

在我的asp.net mvc 3.0应用程序中,我将绘制一个图表,其X轴包含日期值,y轴包含每天的视图。对于图表绘制,我使用json结果传递给它。模型如下:

 public class MyDateModel
    {
        public string Date { get; set; }
        public int Views { get; set; }
    }
以下是行动:

public ActionResult Index()
        {
            var res = new List<MyDateModel>();

            res.Add(new MyDateModel { Date=DateTime.Now.AddDays(-9).ToString("yyyy-MM-dd hh:mm"),Views=10});
            res.Add(new MyDateModel { Date = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd hh:mm"), Views = 3 });
            res.Add(new MyDateModel { Date = DateTime.Now.ToString("yyyy-MM-dd hh:mm"), Views = 3 });

            return View(res);
        }
public ActionResult Index()
{
var res=新列表();
res.Add(新的MyDateModel{Date=DateTime.Now.AddDays(-9).ToString(“yyyy-MM-dd-hh:MM”),Views=10});
res.Add(新的MyDateModel{Date=DateTime.Now.AddDays(-3).ToString(“yyyy-MM-dd-hh:MM”),Views=3});
res.Add(新的MyDateModel{Date=DateTime.Now.ToString(“yyyy-MM-dd-hh:MM”),Views=3});
返回视图(res);
}
最后一个观点是:

@model IEnumerable<Chartjquery_jqplot.Models.MyDateModel>
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>Index</title>
    <link href="../../Content/jquery.jqplot.min.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.jqplot.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jqplot.dateAxisRenderer.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jqplot.json2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {

            var jsonurl=@Html.Raw(Json.Encode(Model));
            var plot2 = $.jqplot('chart2', jsonurl, {
                title: "AJAX JSON Data Renderer",
                axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer}}

            });




        });
    </script>
</head>
<body>
    <div>
        @Html.Raw(Json.Encode(Model))
        <div id="chart2" style="height: 300px; width: 500px;">
        </div>
    </div>
</body>
</html>
@model IEnumerable
@{
布局=空;
}
指数
$(文档).ready(函数(){
var jsonurl=@Html.Raw(Json.Encode(Model));
变量plot2=$.jqplot('chart2',jsonurl{
标题:“AJAX JSON数据呈现程序”,
轴:{xaxis:{渲染器:$.jqplot.DateAxisRenderer}
});
});
@Html.Raw(Json.Encode(模型))
但它并没有在页面上画任何东西

你能帮我吗

此外,json结果是:


[{“日期”:“2012-07-06 12:10”,“视图”:10},{“日期”:“2012-07-12:10”,“视图”:3},{“日期”:“2012-07-15 12:10”,“视图”:3}]

我找到了一种将正确的json数据传递给图表的方法。这是我写的html hepler:

public static MvcHtmlString GetStrippedJson(this HtmlHelper helper,string json)
        {
            json=json.Replace("\"Date\":", string.Empty);

            json=json.Replace("\"Views\":", string.Empty);

            json=json.Replace('}', ']');

            json=json.Replace('{', '[');

            return MvcHtmlString.Create(json);
        }

但是我不知道如何根据每天的滴答声设置滴答声区间,不确定这是否有帮助,但是我传递数据的代码如下@Model.data是一个列表

$(document).ready(function () {
        var data = @Html.Raw(Json.Encode(@Model.data));
        //debugger;
        //alert(data);
        $.jqplot('chartdiv', data);