I am taking a existing chart that was done previously in Dundas chart control and migrating it to the Telerik chart control. So far I can easily replicate the data area display, but I am having trouble with the labels and gridlines on the x-axis. Basically I need to take a start and end date and always display the grid with 8 total gridlines (9 if you include the Y axis) based on hours. So for example in the attached files I have one with a start date of 2/23/2011 and end date of 3/1/2011. I need that range basically as best as possible divided by 8. This needs to happen even if dealing with just a single day as seen in the attached file for just 2/23/2011. With my old Dundas code I did this by taking the total hour difference between the dates, loop adding an hour to the value until it was divisble by 8 evenly and then setting the X axis to that as the intervale and telling the grid its X axis was an intervaltype of hours. Here is the code.
Now I realize that the Telerik chart works differently so I have tried many things to replicate the same process in its workings. I set the Label step to 8. I set ranges, etc. No matter what I do I cannot get it to display 8 grid lines. I just get labels for the start and end dates. I tried code like below to no avail. I am think I am missing something in my understanding on how the labels and grid lines work. Side note. I need the labels to be on the grid lines. Thanks in advance.
//Take the start and end dates and set them for the start and end X axis this.Chart1.ChartAreas[0].AxisX.Minimum = initialDate.ToOADate(); this.Chart1.ChartAreas[0].AxisX.Maximum = completeDate.ToOADate(); //Get the total hours between start and end double totalSeriesHours = completeDate.Subtract(initialDate).TotalHours; //We will be showing 8 grid lines on the X axis so keep adding an hour until we can divide evenly by 8 if (totalSeriesHours > 0) { // How many hours per label? while ((totalSeriesHours % 8.0) != 0) { totalSeriesHours++; } totalSeriesHours /= 8; } //Set the X axis lines, labels and tick marks. this.Chart1.ChartAreas[0].AxisX.MajorGrid.IntervalType = DateTimeIntervalType.Hours; this.Chart1.ChartAreas[0].AxisX.MajorGrid.Interval = totalSeriesHours; this.Chart1.ChartAreas[0].AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Hours; this.Chart1.ChartAreas[0].AxisX.LabelStyle.Interval = totalSeriesHours; this.Chart1.ChartAreas[0].AxisX.MajorTickMark.Interval = totalSeriesHours; this.Chart1.ChartAreas[0].AxisX.MajorTickMark.IntervalType = DateTimeIntervalType.Hours;Now I realize that the Telerik chart works differently so I have tried many things to replicate the same process in its workings. I set the Label step to 8. I set ranges, etc. No matter what I do I cannot get it to display 8 grid lines. I just get labels for the start and end dates. I tried code like below to no avail. I am think I am missing something in my understanding on how the labels and grid lines work. Side note. I need the labels to be on the grid lines. Thanks in advance.
double minDateValue = initialDate.ToOADate(); double maxDateValue = completeDate.ToOADate(); double totalSeriesHours = maxDateValue - minDateValue; //We will be showing 8 grid lines on the X axis so keep adding an hour until we can divide evenly by 8 if (totalSeriesHours > 0) { // How many hours per label? while ((totalSeriesHours % 8.0) != 0) { totalSeriesHours++; } totalSeriesHours /= 8; } //Take the start and end dates and set them for the start and end X axis this.Chart1.PlotArea.XAxis.IsZeroBased = false; this.Chart1.PlotArea.XAxis.AutoScale = false; this.Chart1.PlotArea.XAxis.AddRange(minDateValue, maxDateValue, totalSeriesHours);