1
votes

I'm making a chart that will show attendance over a variable amount of time selected from a dropdown list. I'm trying to change the intervals of the x axis based on the selected value. I used code from MSDN's chart controls tutorial, but the problem is that when I select the dropdown items, I only get one or two intervals.

When I select 1 (1 month), I get one interval starting at 10/14, the minimum date. When I select 3 (3 months), I should get several two-week intervals, but instead I only get 2 month-long intervals.

Can someone help me figure out why I'm getting those results and how I can fix it?

The code below shows what I have so far in the event handler for the dropdown list:

public void AttendanceChange(Object sender, EventArgs e){
        string StatusSelect = this.AttendanceSelect.SelectedValue;
    int Time = Convert.ToInt32(StatusSelect);

    if (Time == 1)
        SetAxisInterval(Chart3.ChartAreas[0].AxisX, 1, DateTimeIntervalType.Weeks);
    else if (Time == 3)
        SetAxisInterval(Chart3.ChartAreas[0].AxisX, 1, DateTimeIntervalType.Weeks);
    else if (Time == 6)
        SetAxisInterval(Chart3.ChartAreas[0].AxisX, 1, DateTimeIntervalType.Months);
    else if (Time == 12)
        SetAxisInterval(Chart3.ChartAreas[0].AxisX, 2, DateTimeIntervalType.Months);
    else if (Time == 24)
        SetAxisInterval(Chart3.ChartAreas[0].AxisX, 3, DateTimeIntervalType.Months);
}

Here is the method to change the intervals:

public void SetAxisInterval(Axis axis, int interval, DateTimeIntervalType intervalType)
{
    axis.Interval = interval;
    axis.IntervalType = intervalType;
}
1
I have edited your title. Please see, "Should questions include “tags” in their titles?", where the consensus is "no, they should not". - John Saunders
Thanks, John! I'll keep that in mind in the future. - ijb109

1 Answers

0
votes

The issue here has to do with the fact that each date being loaded in is counted as a day of the week instead of as a week in itself. I'm looking for an answer to that question in this post: .Net Chart displaying dates as days in a week.