如何使用 MVC4 显示 JqPlot 图表日期

How to Display JqPlot chart Date using MVC4

我将 var 值传递给 Jquery 以显示需求、供应和日期值。我无法在图表中显示日期值。

控制器:

public ActionResult ChartDataJSON()
        {

            ICriteria criteria = NHibernateHttpModule.CurrentSession.CreateCriteria(typeof(JqPlotsSample));

            var chartData = criteria.List<JqPlotsSample>();
            DateTime dt;
            foreach(var item in chartData)
            {


               dt  =DateTime.ParseExact(item.Date,"yyyy-MM-dd h:mmtt",CultureInfo.InvariantCulture);
               item.Date = dt.ToString();


            }

            return Json(chartData, JsonRequestBehavior.AllowGet);

    }

查看:

    <script type="text/javascript">
        $(document).ready(function () {
            // The url for our json data
            var url = '@Url.Action("ChartDataJSON", "SampleJqplot")';

            var ret = null;
            $.ajax({
                // have to use synchronous here, else the function
                // will return before the data is fetched
                async: false,
                url: url,
                type:'GET',
                dataType: "json",
                success: function (data) {
                    ret = data;
                }
            });
            var date = [];
            var demands = [];
            var supplys = [];


            for (i = 0; i < ret.length; i++) {



                demands.push([ret[i].Date, ret[i].Demand]);

                supplys.push([ret[i].Date, ret[i].Supply]);

            }
            alert(ret[1].Date+"Date Alert")

            var plot1 = $.jqplot('chart1', [demands, supplys], {

                title: "Demand Supply",
                axes: {
                    xaxis: {
                        renderer: $.jqplot.DateAxisRenderer,
                        tickOptions: {
                            formatString: '%d/%m/%Y'
                        },

                        label: 'Date'
                    },
                    yaxis: {
                        label: 'Demand'
                    },
                    y2axis: {
                        label: 'Supply'
                    }
                },
                series: [
                    { yaxis: 'yaxis', label: 'demands' },
                    { yaxis: 'y2axis', label: 'supplys' }
                ],
                highlighter: {
                    show: true,
                    sizeAdjust: 1
                },
                cursor: {
                    show: false
                }
            });

        });

        </script>

<body>

    <div id="chart1" style="height: 400px; width: 600px;"></div>
</body>

数据库:

图表:

只有需求和供应值未到日期。

大家好,当我添加 jqplot.dateAxisRenderer.js 文件时,我得到了日期值。

<script src="@Url.Content("~/Scripts/jqplot/jqplot.dateAxisRenderer.min.js")" type="text/javascript"></script>