Share via


Axes (Chart Controls)

Each chart area contains axes (Axis objects) for its plot area, and you access each axis through their respective chart area.

Charts are plotted using X and Y axes. The Y axes typically have numerical scales, whereas the X axes typically have categorical scales. Categories can include string, numeric, and date values. By default, the Chart c control uses numerical scales for all axes.

Each axis can have is own title. To set the axis title, use the Axis.Title property.

Plotting Against Axes

The most commonly used charts have a set of primary axes and may have a set of secondary axis. You can enable and disable each individual axis in the ChartArea object, and set a Series object to be plotted against the primary or secondary axes using the Series.XAxisType and Series.YAxisType properties. See the table below to see which property controls which axis.

For most chart types, the X axes are horizontal and the Y axes are vertical, with the following exceptions:

  • In the bar chart type, the X axes are vertical and the Y axes are horizontal.

  • Circular chart types use the primary axes only, with the X axis representing the radius of the circle and the Y axis representing the circumference.

  • Funnel and pyramid chart types use the primary axes only, with the X axis representing the vertical stack (each item on the stack is represented by one data point). The Y axis can represent the area or height of each item, depending on your settings.

The table below shows the typical positions of each axis in the chart area.

Axis Position

Primary X

Bottom

Primary Y

Left

Secondary X

Top

Secondary Y

Right

Customizing Scale, Grid Lines, and Tick Marks

By default, the Chart control automatically sets the scale of the axes in chart areas based on its data series. You can manually set the Minimum, Maximum, Interval, IntervalOffset, IntervalType, and IntervalOffsetType properties for each axis. You can further customize them by defining different settings for an axis's MajorGrid, MinorGrid, MajorTickMark, MinorTickMark, and LabelStyle properties. If you set the same property in the axis and in one of its components (for example, the Minimum property in both AxisY and AxisY.MajorGrid), the component setting takes precedence.

When Axis.Interval is set to Auto, the Axis.IntervalAutoMode property determines how many intervals should be calculated. If your chart is resized or redrawn often at run time, you can set the Axis.IntervalAutoMode property to VariableCount. This way, the chart dynamically calculates axis intervals. This is useful if the chart intervals are displayed differently depending on the data.

You can also use a logarithmic scale by setting the Axis.IsLogarithmic property to true.

Using Crossing Points

The chart area plots data from the crossing point, which represents the value at which the X and Y axes intersect. For example, if 0 is the crossing point of the primary Y axis, a data point value of 5 in a Column chart appears as a column extending above the Y=0 line, and a data point value of -5 appears as a column extending below the Y=0 line.

By default, the chart area automatically determines the crossing point. Customize the crossing point value using the Axis.Crossing property.

Note

The value you specify in Axis.Crossing must be within the upper and lower bounds you specify in the Axis.Minimum and Axis.Maximum properties.

Changing the crossing point to a non-default value can cause axis labels and tick marks to move into the plot area along with the crossing point. To keep the axis labels and tick marks outside the plot area, set the Axis.IsMarksNextToAxis property to False.

Using Scale Breaks

Scale breaks are intentional breaks on the Y axis that are most often used to redistribute data points on a chart. This improves readability when there are large differences between the high and low values of the data being plotted. Set scale breaks in the Axis.ScaleBreakStyle property.

Using Strip Lines

Strip lines in the plot area outline individual data points or emphasize an area of interest in the plot area. To use strip lines, use either the Axis.IsInterlaced property or the Axis.StripLines property.

If you set the Axis.IsInterlaced property to True, the chart draws strip lines on every other grid line interval for the respective axis. If the respective axis does not use grid lines, then the axis's tick marks or labels are used to determine the interlaced strip lines interval. You can set the color of the strip lines using the Axis.InterlacedColor property.

The Axis.StripLines collection property (a StripLinesCollection object) stores StripLine objects. The Chart control draws the strip lines according to the z-order of the StripLine objects in Axis.StripLines. Each StripLine object is drawn repeatedly at a given width, interval, and offset. To draw a non-repeating strip line, set StripLine.Interval to a large number so that only one repeated instance fits on the chart.

The following code demonstrates how to use the Axis.StripLines property to draw a strip line on the primary Y axis between the values of 20 and 60.

chart1.ChartAreas(0).AxisY.StripLines.Add(New StripLine())
chart1.ChartAreas(0).AxisY.StripLines(0).BackColor = Color.FromArgb(80, 252, 180, 65) 
chart1.ChartAreas(0).AxisY.StripLines(0).StripWidth = 40 
chart1.ChartAreas(0).AxisY.StripLines(0).Interval = 1000 
chart1.ChartAreas(0).AxisY.StripLines(0).IntervalOffset = 20 
chart1.ChartAreas[0].AxisY.StripLines.Add(new StripLine()); 
chart1.ChartAreas[0].AxisY.StripLines[0].BackColor = Color.FromArgb(80, 252, 180, 65); 
chart1.ChartAreas[0].AxisY.StripLines[0].StripWidth = 40; 
chart1.ChartAreas[0].AxisY.StripLines[0].Interval = 10000; 
chart1.ChartAreas[0].AxisY.StripLines[0].IntervalOffset = 20;

See Also

Reference

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