views:

815

answers:

1

Hi,

I'm using the Microsoft Chart Controls for .NET 3.5, and struggles with getting the chart control to support window/control resizing.

I have graphs where the X value is dates, and want the chart to display the maximum available of intervals/labels on the chart axis when I resize the window.

The closes I've come is to call this from the PrePaint event:

double interval = chart.Series[0].Points.Count / ((double)chart.Width / 90);
foreach (var area in chart.ChartAreas.Where(ca => ca.Visible))
{
    area.AxisX.Interval = interval;
}

This makes the intervals and labels fit perfectly along the X axis, but the dates are not shown correctly. This first label seems to be right (some date in 2008), but the rest of the labels along the axis are displayed as some date in 1900 instead.

Anyone know the preferred way of doing this?

A: 

for dates in ms charts u have to explicitly specify the minimum dates to start with. otherwise it takes 29th december 1899 as origin. u can set minimum and max dates on chart like

chart.ChartAreas[0].AxisY.Minimum = (new DateTime(2010, 5, 1)).ToOADate();
                chart.ChartAreas[0].AxisY.Maximum = (new DateTime(2011, 4, 1)).ToOADate();

this post has some valuable information on ms charts HTH
regards

Muhammad Adeel Zahid