2016-05-27 28 views
1

正確顯示柱狀圖我試圖用條形圖與highchart.as,你可以在這裏看到我myController的必須證明報告:.NET Highcharts不能在MVC

var q = 
      _iTrafficRepository.Get() 
       .AsEnumerable().GroupBy(i => i.SubmitDateTime.Date) 
       .Select(g => new {date= g.Key, count = g.Count()}).ToArray(); 
     Highcharts chartTraffcBarDatetime = new Highcharts("chart1") 

    .SetSeries(new Series 
    { 
     Type = ChartTypes.Bar, 
     Name = "Browser share", 
     Data = new Data(q) 
    }); 

     ViewBag.ChartTraffic = chartTraffc; 
     ViewBag.chartTraffcBarDatetime = chartTraffcBarDatetime; 

     return View(); 

q算了算的submitdatetime,這樣做的結果是: enter image description here

在視圖我使用此代碼:

DotNet.Highcharts.Highcharts chartTraffcBarDatetime = ViewBag.chartTraffcBarDatetime; 
       <div style="direction: ltr">@(chartTraffcBarDatetime)</div> 

但RES ULT:

enter image description here

回答

1

訪問 'chartTraffcBarDatetime' 變量視圖,您需要使用大括號@ {}不paranentheses @()...

試試這個:

DotNet.Highcharts.Highcharts chartTraffcBarDatetime = ViewBag.chartTraffcBarDatetime; 
      <div style="direction: ltr">@{chartTraffcBarDatetime}</div> 
+0

它不起作用。引發錯誤:編譯器錯誤消息:CS1528:預期;或=(無法在聲明中指定構造函數參數) –

+0

您是否使用Razor視圖引擎?也許如果您向我們展示了視圖中的所有標記,那麼我們可以獲得更多的視角... – JTech

+0

是的,我使用剃鬚刀視圖引擎 –