.net Highcharts无法在mvc中正确显示条形图

时间:2016-05-27 07:13:17

标签: asp.net asp.net-mvc charts highcharts

我正在尝试使用带有highchart的条形图显示报告。您可以在mycontroller中看到我有:

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>

但结果是:

enter image description here

1 个答案:

答案 0 :(得分:1)

要在视图中访问“chartTraffcBarDatetime”变量,您需要使用大括号@ {}而不是paranentheses @()......

试试这个:

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