2016-04-04 15 views
0

Talep değerini, Gönderim ve Tarih değerini görüntülemek için var değerini Jquery'ye aktarıyorum. Tarih değerini grafikte gösteremiyorum.JqPlot grafiğinin gösterilmesi MVC4 kullanılarak tarihlendirme

Denetleyici:

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); 

    } 

Görünüm:

<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> 

Veritabanı: enter image description here

Grafik:

enter image description here

Yalnızca Talep ve Arz değeri geçerli değil.

cevap

0

Hey guys jqplot.dateAxisRenderer.js dosyasını eklediğimde tarih değerini aldım.

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

enter image description here