ChartsAreas > Collection > ChartArea1 > Axes > Collection

This is how you get to the properties for the axis of a basic chart.

Labels – The Markers Along Each Axis

Intervals shown with decimal places of incorrect value added. The interval setting is a double and if your source value is say a single it will not necessarily convert exactly to a double – use Convert::ToDouble(MySingle.ToString()) to solve this

	chartArea1->AxisY->Minimum = MyChartMinH;
	chartArea1->AxisY->Maximum = MyChartMaxH;
	chartArea1->AxisY->Interval = Convert::ToDouble(MyChartHInterval.ToString());
	chartArea1->AxisY->LabelStyle->Interval = Convert::ToDouble(MyChartHInterval.ToString());
Setting display format

	chartArea1->AxisX->LabelStyle->Format = "hh:mm";	//Set to display in time format

Axis Type

Set the Interval Type

DateTime X Axis

The X values of data points can be bound to a data source that has DateTime values.

	chartArea1->AxisX->LabelStyle->Format = "HH:mm";
	chartArea1->AxisX->Minimum = ChartFromDateAndTime.ToOADate();
	chartArea1->AxisX->Maximum = ChartToDateAndTime.ToOADate();
	chartArea1->AxisX->IntervalType = DataVisualization::Charting::DateTimeIntervalType::Minutes;
	chartArea1->AxisX->Interval = MyChartTimeIntervalHours * 60) + MyChartTimeIntervalMinutes;
	chartArea1->AxisX->LabelStyle->Interval = MyChartTimeIntervalHours * 60) + MyChartTimeIntervalMinutes;

Using Fixed Axis Scale And Divisions

	chartArea1->AxisY->Minimum = 200;
	chartArea1->AxisY->Maximum = 10;
	chartArea1->AxisY->Interval = 1;						//Frequency of each line
	chartArea1->AxisY->LabelStyle->Interval = 10;			//Prequency of each label

Grid Lines

See MajorGrid and MinorGrid.

	chartArea1->AxisY->MajorGrid->Enabled = true;
	chartArea1->AxisY->MinorGrid->Enabled = true;
Setting Grid Lines Color

This can sometimes get lost at run time. Just re apply in code:

	chartArea1->AxisY->MajorGrid->LineColor = System::Drawing::Color::DarkGray;
	chartArea1->AxisY->MinorGrid->LineColor = System::Drawing::Color::LightGray;
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.


Your email address will not be published.