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 http://img826.imageshack.us/img826/6518/evolucaoinvestimento.png

Charles Cavalcante
  • 1,572
  • 2
  • 14
  • 27

2 Answers2

3
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
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Yeh
  • 31
  • 1
2

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

Charles Cavalcante
  • 1,572
  • 2
  • 14
  • 27