I'm using the MS Chart control in .Net 4 to display 4 data series, the X axis is set to datetime type.
with the interval set to days the graph includes weekend even though no weekend dates are included in the data.
All the series except one have the same date points, the exception is a projection line that starts on the last date and continues for a number of working days (excludes weekends).
How can remove the display of weekends (or dates that have no value) from the chart for all series?
this is a winforms .Net 4.0 Application.
foreach (var series in chart2.Series)
{
series.ChartType = SeriesChartType.Line;
series.BorderWidth = 5;
series.XValueType = ChartValueType.Date;
// I Tried this to remove weekends but it results in the graph showing a big red X
series.IsXValueIndexed = true;
}
Edit with Code to reproduce my issue below:
DateTime dt = DateTime.Now;
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days;
Series test1 = new Series("Test1");
test1.XValueType = ChartValueType.Date;
for (int i = 1; i < 7; i++)
{
//skip the weekend
if (dt.DayOfWeek.ToString() == "Saturday") dt = dt.AddDays(1);
if (dt.DayOfWeek.ToString() == "Sunday") dt = dt.AddDays(1);
test1.Points.AddXY(dt.Date, i);
dt = dt.AddDays(1);
i++;
}
chart1.Series.Add(test1);
Series test2 = new Series("Test2");
test1.XValueType = ChartValueType.Date;
for (int i = 1; i < 7; i++)
{
//skip the weekend
if (dt.DayOfWeek.ToString() == "Saturday") dt = dt.AddDays(1);
if (dt.DayOfWeek.ToString() == "Sunday") dt = dt.AddDays(1);
test2.Points.AddXY(dt.Date, i);
dt = dt.AddDays(1);
i++;
}
chart1.Series.Add(test2);
foreach (var series in chart1.Series)
{
series.ChartType = SeriesChartType.Line;
series.BorderWidth = 5;
series.IsXValueIndexed=true;
}
chart1.ChartAreas[0].AxisX.LabelStyle.Angle = 45;
chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 1;