views:

410

answers:

0

I'm using the Microsoft Chart Controls and databinds it like this:

chart1.Series["Default"].Points.DataBindXY(events.Dates, events.Values);
//where
//  events.Dates is IList<DateTime>
//  events.Values is Double

I'm having some issues getting the chart/chartarea to display a reasonable amount of intervals though. It works fine on Auto as long as I don't explicitly set the min/max values for the X-axis, but the number of intervals seems to be the same as number of Dates when setting min/max as:

chart1.ChartAreas["Default"].AxisX.Minimum = events.Dates.FirstOrDefault().ToOADate();
chart1.ChartAreas["Default"].AxisX.Maximum = events.Dates.LastOrDefault().ToOADate();

I need to set the min/max values since it seems like they are not automatically set correctly as the are reported way wrong during PostPaint and that makes it impossible to find the right position along the X-axis by using:

float posX = (float) chart1.ChartAreas["Default"].AxisX.ValueToPixelPosition(dataPoint.XValue);

Any ideas on how to correctly set the amount of intervals along the X-axis (or even, how to correctly get the pixelposition without setting max/min values) are very appreciated.

EDIT: Seems I got this wrong. My X-axis is XValueIndexed and thus the X values are indexes instead of the actual values and I have to tune the PostPaint event to cope with this instead of the actual values.