SciChart Android 2D Charts API > Styling and Theming > PenStyle, BrushStyle and FontStyle
PenStyle, BrushStyle and FontStyle

In SciChart, almost all styling methods expect an instance of either PenStyle or BrushStyle to be passed in. Those that deals with text styling, expect an instance of a FontStyle. All these classes are designed to hold a relevant information related to drawing.

SciChart also provides the helper ColorUtil class, which can be used to pick up colors quickly from the list of preset ones.

PenStyle

The are 4 available PenStyle implementations which allows to specify how lines should be drawn:

Also all PenStyle implementations allows to specify the following parameters for a pen:

  • Is pen anti-aliased or not
  • Thickness
  • StrokeDashArray - used to create dashed pens. Creates a DashPathEffect internally. Please refer to the Android documentation to find out how to specify dashed intervals by an array of floats.    

To create a new PenStyle instance, call an appropriate type constructor, for example:

Copy Code
SolidPenStyle solidPenStyle = new SolidPenStyle (0xFF279B27, true, 2, new float[]{20, 20});

Or if you use our builder helpers you can use PenStyleBuilder for more convenience:

Copy Code
SolidPenStyle solidPenStyle = sciChartBuilder.newPen().withColor(ColorUtil.argb(0xFF, 0x40, 0x83, 0xB7)).withAntiAliasing(true).withThickness(3).build();

Another benefit of using PenStyleBuilder  is that it allows to specify units for the pen thickness. There are the following units available out of the box:

Brush Style

As to the BrushStyle class, it has three implementations available out of the box:

Copy Code
BrushStyle brushStyle = new SolidBrushStyle(0x22279B27);

FontStyle

In SciChart, almost all styling methods expect an instance of either PenStyle or BrushStyle to be passed in. Those that deals with text styling, expect an instance of a FontStyle. The FontStyle type is designed to hold a relevant information related to text, such as:

  • Font style - a Typeface object
  • Text size
  • Text color

The FontStyle type instances can be created in this way:

Copy Code
Typeface typeface = Typeface.createFromAsset(getAssets(), "font/font.ttf");
FontStyle fontStyle = new FontStyle(typeface, 14, ColorUtil.Blue);

Or if you use our builder helpers you can use FonStyleBuilder helper for more convenience:

Copy Code
FontStyle labelStyle = sciChartBuilder.newFont().withTextSize(8).withTextColor(ColorUtil.White).build();

Another benefit of using FonStyleBuilder is that it allows to specify units for the font size. Please refer to the information about PenStyle above to find a list of all the available units.

See Also