- jqplot and rendering it with asp.net mvc model
- 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);
- }
- @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>
- 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);
- }