Guest User

Untitled

a guest
Aug 12th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. jqplot and rendering it with asp.net mvc model
  2. public class MyDateModel
  3. {
  4. public string Date { get; set; }
  5. public int Views { get; set; }
  6. }
  7.  
  8. public ActionResult Index()
  9. {
  10. var res = new List<MyDateModel>();
  11.  
  12. res.Add(new MyDateModel { Date=DateTime.Now.AddDays(-9).ToString("yyyy-MM-dd hh:mm"),Views=10});
  13. res.Add(new MyDateModel { Date = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd hh:mm"), Views = 3 });
  14. res.Add(new MyDateModel { Date = DateTime.Now.ToString("yyyy-MM-dd hh:mm"), Views = 3 });
  15.  
  16. return View(res);
  17. }
  18.  
  19. @model IEnumerable<Chartjquery_jqplot.Models.MyDateModel>
  20. @{
  21. Layout = null;
  22. }
  23. <!DOCTYPE html>
  24. <html>
  25. <head>
  26. <title>Index</title>
  27. <link href="../../Content/jquery.jqplot.min.css" rel="stylesheet" type="text/css" />
  28. <script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
  29. <script src="../../Scripts/jquery.jqplot.min.js" type="text/javascript"></script>
  30. <script src="../../Scripts/jqplot.dateAxisRenderer.min.js" type="text/javascript"></script>
  31. <script src="../../Scripts/jqplot.json2.min.js" type="text/javascript"></script>
  32. <script type="text/javascript">
  33. $(document).ready(function () {
  34.  
  35. var [email protected](Json.Encode(Model));
  36. var plot2 = $.jqplot('chart2', jsonurl, {
  37. title: "AJAX JSON Data Renderer",
  38. axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer}}
  39.  
  40. });
  41.  
  42.  
  43.  
  44.  
  45. });
  46. </script>
  47. </head>
  48. <body>
  49. <div>
  50. @Html.Raw(Json.Encode(Model))
  51. <div id="chart2" style="height: 300px; width: 500px;">
  52. </div>
  53. </div>
  54. </body>
  55. </html>
  56.  
  57. public static MvcHtmlString GetStrippedJson(this HtmlHelper helper,string json)
  58. {
  59. json=json.Replace(""Date":", string.Empty);
  60.  
  61. json=json.Replace(""Views":", string.Empty);
  62.  
  63. json=json.Replace('}', ']');
  64.  
  65. json=json.Replace('{', '[');
  66.  
  67. return MvcHtmlString.Create(json);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment