1

我想制作这样的高图http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/line-labels/我有一个存储过程,计算每个月保留的所有房间类型(一月:双 2,三倍 4 ..)我需要将 I 参数传输到 Roomtypereservations.RoomTypeByDate(i) 中的存储过程;当 i 为 1 时,我得到 1 月的数据,i 为 2 月的数据......

  public ActionResult Gresit()
    {
   DBContext.Current.Open();

  List<Series> allSeries = new List<Series>();
  List<Roomtypereservations> rezervari = new List<Roomtypereservations>();
  for (int i =1; i < 13; i++)
  {
      rezervari = Roomtypereservations.RoomTypeByDate(i);
      var results = new object[4];

      foreach (var a in rezervari)
      {
          results = (new object[] { a.NumRezervari });

          allSeries.Add(new Series
      {
          Name = a.Room_Type,

    //Data = new Data(myData)
          Data = new Data(results.ToArray())

      });
      }
  };


      Highcharts charts = new Highcharts("chart")
          .InitChart(new Chart { DefaultSeriesType = ChartTypes.Spline, })
          .SetTitle(new Title { Text = "Gradul De Ocupare pe luni" })
          .SetXAxis(new XAxis { Categories = Reservation.Categories })
          .SetYAxis(new YAxis
          {
              Title = new YAxisTitle { Text = "Numarul de Camere" },
              Labels = new YAxisLabels { Step = 5, Formatter = "function() { return this.value}" }

          })
          .SetTooltip(new Tooltip
          {
              Crosshairs = new Crosshairs(true),
              Shared = true
          })
          .SetPlotOptions(new PlotOptions
          {
              Spline = new PlotOptionsSpline
              {
                  Marker = new PlotOptionsSeriesMarker
                  {
                      Radius = 4,
                      LineColor = ColorTranslator.FromHtml("#666666"),
                      LineWidth = 1
                  }
              }
          })
          .SetSeries(allSeries.Select(s => new Series { Name = s.Name, Data = s.Data }).ToArray());

      return View(charts);

    }

但我做错了,因为我明白了:我的所有数据都显示为 1 月。我究竟做错了什么? 在此处输入图像描述

4

1 回答 1

4

那是因为您正在循环并为每个数据点创建一个系列。您需要将 allSeries.Add 语句从 foreach 结构中取出。尝试使用以下修改的结构:

for (int i =1; i < 13; i++)
{
  rezervari = Roomtypereservations.RoomTypeByDate(i);
  var results = new List<object>();

  foreach (var a in rezervari)
  {
    results.Add(a.NumRezervari);
  }

  allSeries.Add(new Series
  {
    Name = a.Room_Type,
    Data = new Data(results.ToArray())
  });
}

从外观上看,您正在创建多达 12 个不同的系列。

于 2012-06-04T20:02:05.510 回答