Axes: Elements
- 6 minutes to read
The Titles, Labels, Constant Lines and Strips are an axis’s structural elements and can supplement the axis:
Note that Tickmarks and Grid Lines are visual elements and the axis style configures them. Refer to the Axes guide to learn more about visual element styling.
How to: Manage an axis’ labels
Axis Labels are an axis’s main structural elements. The axis labels show textual representations of axis values at major tick marks and grid lines.
How to: customize axis labels’ text
Labels’ main function is to display an axis value’s textual representation. The axis label converts an axis value to a string using one of the following approaches:
Using Text Pattern
The following code shows how to format label text if the label text does not require conditional formatting and all labels’ texts use the same text format:
AxisLabel axisLabel = new AxisLabel(); axisLabel.setTextFormat("$ #tn"); yAxis.setLabel(axisLabel);
The code above uses the following classes and class members:
Symbol Description AxisBase.setLabel(AxisLabel) Specifies axis label settings. AxisLabel The axis labels options’ storage. AxisLabel.setTextFormat(String) Specifies the axis labels’ text format pattern. Using Axis’ Label Text Formatter
If an axis label’s text requires more detailed customization (for example, conditional prefix), you should use the axis label text formatter to provide labels’ content:
yAxis.setLabelTextFormatter(new LabelFormatter()); // Label formatter's implementation. public class LabelFormatter implements AxisLabelTextFormatter{ private DecimalFormat mDecimalFormat = new DecimalFormat("$ #.1M"); @Override public String format(Object value) { return mDecimalFormat.format((double)value); } }
This approach can use the following symbols:
Symbol Description AxisBase.setLabelTextFormatter(AxisLabelTextFormatter) Specifies the formatter that provides axis labels’ text. AxisLabelTextFormatter The class providing text for the DateTimeAxisX, NumericAxisX, QualitativeAxisX and NumericAxisY labels should implement the interface.
How to: change labels’ position
Axis labels can be positioned inside the drawing area or outside it. The following image demonstrates labels that are inside the area:
AxisLabel axisLabel = new AxisLabel();
axisLabel.setPosition(AxisLabelPosition.INSIDE);
xAxis.setLabel(axisLabel);
The code above uses the following classes and methods:
Symbol | Description |
---|---|
AxisLabel | The axis labels options’ storage. |
AxisBase.setLabel(AxisLabel) | Specifies axis label settings. |
AxisLabel.setPosition(AxisLabelPosition) | Specifies the axis labels position. |
How to: configure labels’ appearance
The style configures the following axis labels’ appearance settings:
The table below demonstrates the symbols that allow you to customize axis labels’ appearance.
Symbol | Description |
---|---|
AxisLabelBase.setStyle(AxisLabelStyle) | Specifies an axis label’s appearance settings. |
AxisLabelStyle | The axis labels appearance options’ storage. |
How to: Customize the axis title
The Axis Title allows you to show additional text that explains the axis’s values:
The following code demonstrates how to specify an axis’s title:
AxisTitle yAxisTitle = new AxisTitle();
yAxisTitle.setText("GDP (nominal)");
yAxisTitle.setAlignment(AxisTitleAlignment.CENTER);
yAxis.setTitle(yAxisTitle);
The code above uses the following classes and members:
Symbol | Description |
---|---|
AxisTitle | The axis title. |
TitleBase.setText(String) | Specifies title’s text. |
AxisTitle.setAlignment(AxisTitleAlignment) | Specifies the title’s alignment. |
AxisBase.setTitle(AxisTitle) | Specifies the axis title. |
You can configure an axis title’s style using the following symbols:
Symbol | Description |
---|---|
TitleStyle | Title appearance settings’ storage. |
TitleBase.setStyle(TitleStyle) | Specifies the title style. |
How to: Add a constant line
Constant lines provide the capability to mark the required axis values:
Note that various axis types have a constant line type. The table below matches axis types with constant line types:
Axis Type | Constant Line Type |
---|---|
QualitativeAxisX | QualitativeConstantLine |
NumericAxisX | NumericConstantLine |
DateTimeAxisX | DateTimeConstantLine |
NumericAxisY | NumericConstantLine |
The following example demonstrates how to configure a constant line:
NumericConstantLine constantLine = new NumericConstantLine(672.66);
ConstantLineTitle constantLineTitle = new ConstantLineTitle();
constantLineTitle.setText("Price minimum");
constantLineTitle.setAlignment(ConstantLineTitleAlignment.FAR);
constantLineTitle.setShowBelowLine(true);
constantLine.setTitle(constantLineTitle);
constantLine.setLegendText("Price minimum");
constantLine.setVisibleInLegend(true);
axisY.addConstantLine(constantLine);
The following classes and members allow you to configure a constant line:
Symbol | Description |
---|---|
NumericAxisX.addConstantLine(NumericConstantLine) | Adds the specified constant line to the axis. |
NumericAxisY.addConstantLine(NumericConstantLine) | Adds the specified constant line to the axis constant lines’ collection. |
NumericConstantLine | The constant line that can be added to NumericAxisX and NumericAxisY axes. |
QualitativeAxisX.addConstantLine(QualitativeConstantLine) | Adds the specified constant line to the axis constant lines’ collection. |
QualitativeConstantLine | The constant line that can be added to a QualitativeAxisX axis. |
DateTimeAxisX.addConstantLine(DateTimeConstantLine) | Adds the specified constant line to the axis. |
DateTimeConstantLine | The constant line that can be added to a DateTimeAxisX axis. |
The style configures the following constant line’s appearance settings:
The table below demonstrates the symbols that allow you to customize axis labels’ appearance:
Symbol | Description |
---|---|
ConstantLineBase.setStyle(ConstantLineStyle) | Specifies a constant line’s style. |
ConstantLineStyle | Constant line appearance settings storage. |
How to: Add a strip
Strips provide the capability to highlight specific axis ranges.
Note that various axis types have a strip type. The table below shows axis types and their corresponding strip types.
Axis Type | Strip Type |
---|---|
NumericAxisX | NumericStrip |
NumericAxisY | NumericStrip |
DateTimeAxisX | DateTimeStrip |
QualitativeAxisX | QualitativeStrip |
The following example demonstrates how to configure a strip:
DateTimeStrip strip = new DateTimeStrip(
new GregorianCalendar(2016, Calendar.AUGUST, 1).getTime(),
new GregorianCalendar(2016, Calendar.AUGUST, 31).getTime()
);
strip.setAxisLabel(new StripAxisLabel());
strip.getAxisLabel().setText("August");
strip.getAxisLabel().setVisible(true);
strip.setLegendText("Strip");
strip.setVisibleInLegend(true);
axisX.addStrip(strip);
The following classes and members allow you to configure a strip:
Symbol | Description |
---|---|
NumericAxisX.addStrip(NumericStrip) | Adds the specified constant line to the axis. |
NumericAxisY.addStrip(NumericStrip) | Adds the specified constant line to the axis constant lines’ collection. |
NumericStrip | The strip that can be added to NumericAxisX and NumericAxisY axes. |
QualitativeAxisX.addStrip(QualitativeStrip) | Adds the specified strip to the axis strips’ collection. |
QualitativeStrip | The strip that can be added to a QualitativeAxisX axis. |
DateTimeAxisX.addStrip(DateTimeStrip) | Adds the specified strip to the axis. |
DateTimeStrip | The strip that can be added to a DateTimeAxisX axis. |
The style configures the following strip’s appearance settings:
The table below demonstrates the symbols that allow you to customize strip’s appearance.
Symbol | Description |
---|---|
StripBase.setStyle(StripStyle) | Specifies the strip’s appearance settings. |
StripStyle | The strip apearance settings’ storage. |