Reputation: 1608
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 http://img826.imageshack.us/img826/6518/evolucaoinvestimento.png
Upvotes: 1
Views: 5300
Reputation: 31
LCharts(iChart).Chart.ChartAreas(0).AxisX.Minimum = MinDate.ToOADate
LCharts(iChart).Chart.ChartAreas(0).AxisX.Maximum = MaxDate.ToOADate
LCharts(iChart).Chart.ChartAreas(0).AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount
'LCharts(iChart).Chart.ChartAreas(0).AxisX.IsMarginVisible = True
LCharts(iChart).Chart.ChartAreas(0).AxisX.LabelStyle.IsEndLabelVisible = True
Upvotes: 3
Reputation: 1608
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 http://img691.imageshack.us/img691/7796/chartimgca42ufcm.png
Upvotes: 2