Freigeben über


Chart Areas (Chart Controls)

The Chart.ChartAreas collection property contains all chart areas (ChartArea objects) in the Chart control. Chart areas can be positioned next to each other or overlap each other. This gives you the freedom to create custom charts.

Each chart area contains a plot area, where the Chart control plots the data series. When you change the appearance properties of the chart area, it changes the appearance of the plot area.

Gridlines in the plot area are configured in the respective axis, as well as scale, and strip lines. Each chart area also contains four axes:

  • A primary X axis (the ChartArea.AxisX property)

  • A primary Y axis (the ChartArea.AxisY property)

  • A secondary X axis (the ChartArea.AxisX2 property)

  • A secondary Y axis (the ChartArea.AxisY2 property)

All axes can be accessed through the ChartArea.Axes property (an Axis array). For more information on axes, see Axes.

The plot area is found inside the chart area, and is where the Chart control plots the data series. It is also where axes, grid lines, and strip lines are drawn. Axis labels are always outside of the plot area, but most other elements are found within the plot area.

Adding Chart Areas at Run Time

To add a chart area to the Chart control at run time, use the Add method in the Chart.ChartAreas object. The following code demonstrates this.

Chart1.ChartAreas.Add("NewChartArea")
Chart1.ChartAreas.Add("NewChartArea");

You can also plot multiple charts with multiple series in a ChartArea object. See Series for more information.

Positioning Chart Areas

By default, the Chart object automatically positions a chart area to accommodate the number of chart areas to be plotted, the chart picture title position, and the legend's position. To set the position of a chart area manually, use the ChartArea.Position property.

  • Auto
    If set to true, the Chart control automatically places the chart area within the chart picture.
  • X
    The relative X coordinate of the chart area in the chart picture. For more information, see Coordinate System.
  • Y
    The relative Y coordinate of the chart area in the chart picture. For more information, see Coordinate System.
  • Height
    The height of the chart area as a percentage of the chart picture's height.
  • Width
    The width of the chart area as a percentage of the chart picture's width.

By default, the Chart object automatically positions the chart areas to avoid overlapping. You can overlap them manually by setting their ChartArea.Position property accordingly. When charts overlap, the Chart object displays the first chart area in the Chart.ChartAreas collection at the top, then the next element below it, and so on.

Additionally, use the AlignWithChartArea, AlignOrientation, and AlignStyle properties in the ChartArea object to align or synchronize two or more chart areas horizontally, vertically, or both.

Enabling 3D

To use 3D chart types, you must enable 3D in the chart area. To do this, use the ChartArea.Area3DStyle property.

The following code enables 3D for the default chart area and rotates the chart area by 45 degrees both horizontally and vertically.

Chart1.ChartAreas("Default").Area3DStyle.Enable3D = True
Chart1.ChartAreas("Default").Area3DStyle.Inclination = 45
Chart1.ChartAreas("Default").Area3DStyle.Rotation = 45
Chart1.ChartAreas["Default"].Area3DStyle.Enable3D = true;
Chart1.ChartAreas["Default"].Area3DStyle.Inclination = 45;
Chart1.ChartAreas["Default"].Area3DStyle.Rotation = 45;

See Also

Reference

Chart Elements
System.Windows.Forms.DataVisualization.Charting
System.Web.UI.DataVisualization.Charting