I am using a rangebar mschart to plot some data. Y axis represents the time ( total of 24 hours). The chart is plotting data correctly, but the y axis is not starting from 0 hours.
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. This starts Y axis from 0 but then plotting is not visible.
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); 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
Converting TextBox value to datetime did the trick.
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.