简体   繁体   English

MS图表Y轴从0小时开始不凝视[RangeBar]

[英]MS Chart Y Axis not staring from 0 Hours [RangeBar]

I am using a rangebar mschart to plot some data. 我正在使用Rangebar Mschart绘制一些数据。 Y axis represents the time ( total of 24 hours). Y轴表示时间(总计24小时)。 The chart is plotting data correctly, but the y axis is not starting from 0 hours. 图表正确绘制了数据,但是y轴不是从0小时开始。

在此处输入图片说明

Code

 var IETable = (dt as System.ComponentModel.IListSource).GetList();
 chChart.DataBindCrossTable(IETable, "Number", "", "Start,Finish", "");

                  foreach (Series sr in chChart.Series)
                  {

                      sr.ChartType = SeriesChartType.RangeBar;
                      sr.YValueType = ChartValueType.Time;

                  }


                  chChart.ChartAreas[0].AxisY.LabelStyle.Format = "h : tt";
                  chChart.ChartAreas[0].AxisY.Interval = 2;
                  chChart.ChartAreas[0].AxisY.IntervalType = DateTimeIntervalType.Hours;
                  chChart.ChartAreas[0].AxisY.IntervalOffset = 0;
                  chChart.ChartAreas[0].AxisY.IsMarksNextToAxis = true;
                  chChart.ChartAreas[0].AxisY.IsStartedFromZero = true;


I also tried AxisY.Minimum=0 and AxisY.Maximum=1. 我还尝试了AxisY.Minimum = 0和AxisY.Maximum = 1。 This starts Y axis from 0 but then plotting is not visible. Y轴从0开始,但是看不到绘图。

DateTime minDate = new DateTime(0, 0, 0, 0, 0, 0);
DateTime maxDate = minDate.AddHours(24);
chChart.ChartAreas[0].AxisY.Minimum = minDate.ToOADate();
chChart.ChartAreas[0].AxisY.Maximum = maxDate.ToOADate();

Try this. 尝试这个。 You might need to change the new DateTime(0, 0, 0, 0, 0, 0); 您可能需要更改新的DateTime(0,0,0,0,0,0); to fit the year and month etc when you will add stuff. 以适合年份和月份等,当您添加内容时。 Possible solution is to get minDate with DateTime.Now and substraction the hours, minutes and seconds 可能的解决方案是使用DateTime.Now获取minDate并减去小时,分钟和秒

Converting TextBox value to datetime did the trick. 将TextBox值转换为datetime可以达到目的。

DateTime minDate =Convert.ToDateTime(tbDate.Text);
DateTime maxDate = minDate.AddDays(1);
chChart.ChartAreas[0].AxisY.Minimum = minDate.ToOADate();
chChart.ChartAreas[0].AxisY.Maximum = maxDate.ToOADate();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM