Radial Axes
Radial axes are used specifically for the radar and polar area chart types. These axes overlay the chart area, rather than being positioned on one of the edges.
Radial axes could be only
- linear, is use to chart numerical data. As the name suggests, linear interpolation is used to determine where a value lies in relation the center of the axis.
The radial axis is use to chart numerical data.
Here is an example how to create a radial axis:
// creates a radial axis with default scale id "r" and default kind "r"
RadialAxis axis = new RadialAxis(chart);
// adds axes to chart configuration
chart.getOptions().setAxes(axis);
The axis has configuration properties for ticks, angle lines (line that appear in a radar chart outward from the center), point labels (labels around the edge in a radar chart):
Options
The radial linear axis allows to define a number of properties, used to display the data.
// creates a radial axis
RadialAxis axis = new RadialAxis(chart);
// sets and gets the max value
axis.setMax(100);
double max = axis.getMax();
The following are the attributes that you can set:
Name | Type | Description |
---|---|---|
alignToPixels | boolean | Align pixel values to device pixels. |
animate | boolean | If true , animate scaling the chart from the center. |
backgroundColor | String - IsColor | The background color of scale area. |
beginAtZero | boolean | If true , scale will include 0 if it is not already included. |
display | boolean - Display | If Display.TRUE , the axis is shown. |
max | double | User defined maximum number for the scale, overrides maximum value from data. |
min | double | User defined minimum number for the scale, overrides minimum value from data. |
reverse | boolean | Reverses order of tick labels. |
startAngle | double | 0 |
suggestedMax | double | Adjustment used when calculating the maximum data value. |
suggestedMin | double | Adjustment used when calculating the minimum data value. |
weight | int | The weight used to sort the axis. Higher weights are further away from the chart area. |
Ticks
The radial linear axis provides the following options for configuring tick marks.
// creates a radial axis
RadialAxis axis = new RadialAxis(chart);
// sets and gets the max value
axis.getTicks().setColor(HtmlColor.RED);
IsColor color = axis.gteTicks().getColor();
The following are the attributes that you can set:
Name | Type | Scriptable | Description |
---|---|---|---|
backdropColor | String - IsColor | Yes | Color of label backdrops. |
backdropPadding | Padding | The padding of tick backdrop. See padding documentation for more details. | |
color | String - IsColor | Yes | Color of ticks. |
count | int | [Yes](#scriptable | The number of ticks to generate. If specified, this overrides the automatic generation. |
display | boolean | - | If true , the tick marks are shown. |
font | IsFont | Yes | Font of ticks. See Font. |
maxTicksLimit | int | [Yes](#scriptable | Maximum number of ticks and gridlines to show. |
numberFormat | NumberFormatOptions | Yes | The number format options used by the default label formatter. See INTL number format documentation. |
padding | int | - | The padding between the tick label and the axis. |
precision | int | [Yes](#scriptable | If defined and stepSize is not specified, the step size will be rounded to this many decimal places. |
sampleSize | int | - | The number of ticks to examine when deciding how many labels will fit. Setting a smaller value will be faster, but may be less accurate when there is large variability in label length. |
showLabelBackdrop | boolean | Yes | If true , draw a background behind the tick labels |
stepSize | double | Yes | User defined fixed step size for the scale. |
textStrokeColor | String - IsColor | Yes | The color of the stroke around the text. |
textStrokeWidth | int | Yes | Stroke width around the text. |
z | int | - | z-index of tick layer. Useful when ticks are drawn on chart area. Values less than or equals to 0 are drawn under data sets, greater than 0 on top. |
The further customization of ticks, a callback is provided.
See [padding documentation](../configuration/Commons#padding) for more details.
Scriptable
Scriptable options at ticks level accept a callback which is called for each of the underlying data values. See more details in Configuring charts section.
All scriptable options callbacks will get a ScaleContext instance.
// creates a radial axis
RadialAxis axis = new RadialAxis(chart);
// sets the option by a callback
axis.getTicks().setColor(new ColorCallback<ScaleContext>(){
@Override
public IsColor invoke(ScaleContext context){
// logic
return color;
}
});
The following options can be set by a callback:
Name | Callback | Returned types |
---|---|---|
backdropColor | ColorCallback<ScaleContext> | String - IsColor |
color | ColorCallback<ScaleContext> | String - IsColor |
count | CountCallback | int |
font | FontCallback<ScaleContext> | FontItem |
maxTicksLimit | MaxTicksLimitCallback | int |
numberFormat | NumberFormatCallback | NumberFormatItem |
precision | PrecisionCallback | int |
showLabelBackdrop | ShowLabelBackdropCallback | boolean |
stepSize | StepSizeCallback | double |
textStrokeColor | ColorCallback<ScaleContext> | String - IsColor |
textStrokeWidth | WidthCallback<ScaleContext> | int |
Callback
It is also common to want to change the tick marks to include information about the data type. For example, adding a dollar sign ('$'). To do this, you need to implement a ticks callback in the axis configuration.
To apply a custom callback, you can set a TickCallback instance to the axis options, as following:
axis.getTicks().setCallback(new TickCallback(){
/**
* Changes the tick marks to include information about the data type.
*
* @param axis axis instance where this callback as been defined
* @param value value of tick
* @param index index of tick
* @param values list of all tick values
* @return the tick to apply or if the callback returns null the associated grid line will be hidden.
*/
public String onCallback(Axis axis, double value, int index, List<Double> values){
// add $
return "$" + value;
}
});
See INTL number format documentation if you want to use a number formatter, provided out-of-the-box.
NoSelectedDatasetTicksCallback callback
Charba provides a common implementation for tick callback to set the decimal digits of ticks in case of all data sets are hidden, to avoid the annoying standard format of doubles.
To apply the callback, you can set an instance to the axis options, as following:
// creates a radial axis
RadialAxis axis = new RadialAxis(chart);
// sets the option by a callback
axis.getTicks().setCallback(new NoSelectedDatasetTicksCallback());
The default decimal precision is 2
. A custom precision can be set by the constructor of callback, as following:
// creates a radial axis
RadialAxis axis = new RadialAxis(chart);
// sets the option by a callback
// 3 decimal digits
axis.getTicks().setCallback(new NoSelectedDatasetTicksCallback(3));