Skip to main content
Version: 5.2

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:

NameTypeScriptableDescription
alignToPixelsbooleanYesAlign pixel values to device pixels.
animateboolean-If true, animate scaling the chart from the center.
backgroundColorString - IsColorYesThe background color of scale area.
beginAtZerobooleanYesIf true, scale will include 0 if it is not already included.
displayboolean - DisplayYesIf Display.TRUE, the axis is shown.
maxdoubleYesUser defined maximum number for the scale, overrides maximum value from data.
mindoubleYesUser defined minimum number for the scale, overrides minimum value from data.
reversebooleanYesReverses order of tick labels.
startAngledoubleYesStarting angle to draw arcs for the first item in a data set. In degrees, 0 is at top.
suggestedMaxdoubleYesAdjustment used when calculating the maximum data value.
suggestedMindoubleYesAdjustment used when calculating the minimum data value.
weightdoubleYesThe weight used to sort the axis. Higher weights are further away from the chart area.

Scriptable

Scriptable options at scale 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 category axis 
RadialAxis axis = new RadialAxis(chart);
// sets the option by a callback
axis.setBackgroundColor(new ColorCallback<ScaleContext>(){

@Override
public IsColor invoke(ScaleContext context){
// logic
return color;
}
});

The following options can be set by a callback:

NameCallbackReturned types
alignToPixelsAlignToPixelsCallbackboolean
backgroundColorColorCallback<ScaleContext>String - IsColor
beginAtZeroBeginAtZeroCallbackboolean
displayDisplayCallbackboolean - Display
maxMinMaxCallback<Double>double
minMinMaxCallback<Double>double
reverseReverseCallbackboolean
startAngleStartAngleCallbackdouble
suggestedMaxMinMaxCallback<Double>double
suggestedMinMinMaxCallback<Double>double
weightScaleWeightCallbackdouble

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:

NameTypeScriptableDescription
backdropColorString - IsColorYesColor of label backdrops.
backdropPaddingPaddingThe padding of tick backdrop.
See padding documentation for more details.
colorString - IsColorYesColor of ticks.
countint[Yes](#ticks-scriptable-optionsThe number of ticks to generate. If specified, this overrides the automatic generation.
displayboolean-If true, the tick marks are shown.
fontIsFontYesFont of ticks.
See Font.
maxTicksLimitint[Yes](#ticks-scriptable-optionsMaximum number of ticks and gridlines to show.
numberFormatNumberFormatOptionsYesThe number format options used by the default label formatter.
See INTL number format documentation.
paddingint-The padding between the tick label and the axis.
precisionint[Yes](#ticks-scriptable-optionsIf defined and stepSize is not specified, the step size will be rounded to this many decimal places.
sampleSizeint-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.
showLabelBackdropbooleanYesIf true, draw a background behind the tick labels
stepSizedoubleYesUser defined fixed step size for the scale.
textStrokeColorString - IsColorYesThe color of the stroke around the text.
textStrokeWidthintYesStroke width around the text.
zint-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.

Ticks scriptable options

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:

NameCallbackReturned types
backdropColorColorCallback<ScaleContext>String - IsColor
colorColorCallback<ScaleContext>String - IsColor
countCountCallbackint
fontFontCallback<ScaleContext>FontItem
maxTicksLimitMaxTicksLimitCallbackint
numberFormatNumberFormatCallbackNumberFormatItem
precisionPrecisionCallbackint
showLabelBackdropShowLabelBackdropCallbackboolean
stepSizeStepSizeCallbackdouble
textStrokeColorColorCallback<ScaleContext>String - IsColor
textStrokeWidthWidthCallback<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));