views:

44

answers:

1

I'm developing a stocks evolution chart with Microsoft Chart Controls and I need to show the initial and final dates on the AxisX labels but I can't do it.

I google and found many solutions like set the properties:

Chart1.ChartAreas[0].AxisX.Minimum = InitialDate.ToOADate();
Chart1.ChartAreas[0].AxisX.Maximum = FinalDate.ToOADate();
Chart1.ChartAreas[0].AxisX.LabelStyle.IsEndLabelVisible = true;

Nothing made same differnce. I need a help !

On the sample below the initial date was Jul 26, 2007 and the final was Jul 26, 2010, this is what I need to show on the chart labels, the others dates don't make difference and can be showed in any interval.

alt text

A: 

I get a way:

// get the interval in days
double days = (double)((TimeSpan)(FinalDate - InitialDate)).Days;

// the number os labels
double labels = 10.0;

// check if the number of days is bigger than labels
if (days > labels)
{
    // calculate the interval
    double interval = days / labels;
    Chart1.ChartAreas[0].AxisX.Interval = interval;
}
else
{
    // set the interval of 1 day
    Chart1.ChartAreas[0].AxisX.Interval = 1;
}

Here is the result:

chart

charles.art.br