2016-11-10 133 views
0

我要生成酒吧,如在linkenter image description here范围栏

不过,我得到这个错误:

enter image description here

这里是我使用的代码:

 // AxisY 
     chart1.ChartAreas.Add(CA); 
     chart1.ChartAreas[1].AxisY.MajorGrid.Enabled = false; 
     chart1.ChartAreas[1].AxisY.Interval = 1; 

     // AxisX 
     chart1.ChartAreas[1].AxisX.ScrollBar.Enabled = true; 
     chart1.ChartAreas[1].AxisX.ScaleView.Zoomable = true; 
     chart1.ChartAreas[1].AxisX.MajorGrid.Enabled = false; 
     chart1.ChartAreas[1].AxisX.LabelStyle.Format = "yyyy-MM-dd hh:mm:ss"; 

     chart1.ChartAreas[1].AxisX.Interval = 0; 
     chart1.ChartAreas[1].AxisX.IntervalType = DateTimeIntervalType.Years; 

     minDate = new DateTime(2016, 01, 01, 00, 00, 00, 000); 
     maxDate = new DateTime(2016, 12, 01, 00, 00, 00, 000); // or DateTime.Now; 

     chart1.ChartAreas[1].Axes[0].Enabled = AxisEnabled.False; 
     chart1.ChartAreas[1].Axes[1].Enabled = AxisEnabled.False; 

     chart1.ChartAreas[1].BackColor = Color.Transparent; 
     chart1.ChartAreas[1].Position.Height = 100; 
     chart1.ChartAreas[1].Position.Width = 100; 
     chart1.ChartAreas[1].InnerPlotPosition.Height = 90; 
     chart1.ChartAreas[1].InnerPlotPosition.Width = 80; 
     chart1.ChartAreas[1].InnerPlotPosition.X = 10; 

     var series2 = new Series 
     { 
      Name = "S2", 
      Color = Color.Black, 
      ChartType = SeriesChartType.RangeBar, 
      YValueType = ChartValueType.Auto, 
      XValueType = ChartValueType.Auto 
     }; 

     var values2 = new DateTime[3]; 
     values2[0] = minDate.AddMonths(2); 
     values2[1] = minDate.AddMonths(4); 
     values2[2] = minDate.AddMonths(6); 

     series2.Points.AddXY(1, values2[1], values2[2]); 

     series2["PointWidth"] = ".25"; 

     chart1.Series.Add(series2); 

底部轴是日期时间。左边的轴是固定的,并且有文字作为标签。我需要显示数据的差距。

+0

这是不相关的问题。 – TaW

回答

1

是的,这看起来很奇怪乍一看,错误信息并没有指出你在正确的方向。

原因是,您尝试为系列添加点,然后在之前将系列添加到图表。

RangeBar不能与除条形图表之外的任何其他图表类型组合。

因此(?)图表无法检查点是否实际上以有效的方式添加,而不是说所以它声称您的系列只接受一个y值。

解决方案:只要添加任何DataPoints前添加series2Chart,一切都很好..

+0

如果您对答案感到满意,请考虑考虑[接受](http://stackoverflow.com/help/accepted-answer)它..! - 我发现你从来没有这样做过:在答案的选票下面,点击左上角的(不可见)复选标记,然后单击它!它变成绿色,并获得我们两个小的声誉.. – TaW

+0

当然,它会发生:D –