Classes in depth Chapter 22 of 35

What each chart type's data set adds on top of the shared settings, from line modes and bar corners to candle colors and pie value lines.

Everything in The DataSet class works on all of them. This chapter only lists what is new per class. Three intermediate classes sit in between and are shared by several chart types, so they come first.

Highlight settings shared by several types#

BarLineScatterCandleBubbleDataSet is the base of every set that lives on an x and a y axis, so bar, line, scatter, candle and bubble. It adds one property:

PropertyMeaningDefault
highlightColorcolor of the highlight indicatorlight orange, rgb(255, 187, 115)

BarDataSet overrides that default with black.

LineScatterCandleRadarDataSet adds the crosshair lines drawn through a highlighted entry, for line, scatter, candle and radar sets:

PropertyMeaningDefault
isVerticalHighlightIndicatorEnableddraw the vertical linetrue
isHorizontalHighlightIndicatorEnableddraw the horizontal linetrue
highlightLineWidthwidth of both lines in dp0.5f
dashPathEffectHighlightdash pattern, read onlynull, solid
set.setDrawHighlightIndicators(false)      // both at once
set.enableDashedHighlightLine(8f, 8f, 0f)  // dash length, gap, phase, all in px
set.disableDashedHighlightLine()

isDashedHighlightLineEnabled tells you whether a pattern is set.

Line and radar fill#

LineRadarDataSet is the base of LineDataSet and RadarDataSet: a stroked line with an optional filled area under it.

PropertyMeaningDefault
lineWidthstroke width in dp, clamped to 0 to 101f
isDrawFilledEnabledfill the area between the line and the axisfalse
fillColorcolor of the filled areargb(140, 234, 255)
fillAlphaopacity of the filled area, 0 to 25585
fillDrawabledrawable painted into the area instead of the colornull
set.lineWidth = 3f
set.isDrawFilledEnabled = true
set.fillColor = Color.BLUE
set.fillAlpha = 90

Assigning fillColor clears fillDrawable, so whichever you set last is the one that is drawn. Filling clips the canvas to a path and costs more than drawing the line alone. Where the fill stops is decided by the fill formatter.

The old documentation gives the minimum line width as 0.2. It is 0, which draws the thinnest line the device can.

LineDataSet#

The mode decides how the points are connected.

LineDataSet.ModeDraws
LINEAR (the default)straight segments from point to point
STEPPEDhorizontal steps, the y changes at each entry
CUBIC_BEZIERa smooth curve through the points, bent by cubicIntensity
HORIZONTAL_BEZIERa smooth curve with horizontal control points, so it never overshoots in y
set.mode = LineDataSet.Mode.CUBIC_BEZIER
set.cubicIntensity = 0.18f   // clamped to 0.05 (almost straight) to 1, default 0.2
A cubic line is one path with one color. Only LINEAR and STEPPED draw a segment per entry and use the whole colors list.

Circles at the entries:

PropertyMeaningDefault
isDrawCirclesEnableddraw a circle at every entrytrue
circleRadiusradius in dp, values below 1 are ignored and logged4f
circleColorscircle colors, cycled per entryone rgb(140, 234, 255)
circleColorfirst circle color; assigning replaces the whole list
isDrawCircleHoleEnabledpunch a hole into each circletrue
circleHoleRadiushole radius in dp, values below 0.5 are ignored and logged2f
circleHoleColorhole color, ColorTemplate.COLOR_NONE leaves the hole transparentwhite

setCircleColors(vararg colors: Int) and setCircleColors(colorResIds, context) fill the list, resetCircleColors() empties it.

Dashed lines:

set.enableDashedLine(10f, 5f, 0f)  // dash length, gap, phase, all in px
set.disableDashedLine()

isDashedLineEnabled reports the state and dashPathEffect gives you the effect itself. A dashed line is rendered onto the chart's internal bitmap rather than straight onto the canvas.

Fill and highlight:

PropertyMeaningDefault
fillFormatterdecides the y value the fill reaches down toDefaultFillFormatter()
isDrawHighlightCircleEnableddraw a ring on the highlighted entryfalse
highlightCircleRadiusradius of that ring in dp5f

The ring is drawn in three layers: a halo in highlightColor at 70 alpha, a disc in circleHoleColor, and a stroke in the set's color.

BarDataSet#

val set = BarDataSet(entries, "Orders")
set.barCornerRadius = 7f
set.barBorderWidth = 1f
set.barBorderColor = Color.BLACK
set.highlightAlpha = 0
PropertyMeaningDefault
barCornerRadiuscorner radius in dp, 0 for sharp corners0f
barBorderWidthborder around each bar in dp, 0 for none0f
barBorderColorcolor of that borderblack
barShadowColorcolor of the shadow bar behind each barrgb(215, 215, 215)
highlightAlphaopacity of the overlay on a selected bar, 0 to 255120
stackLabelslegend labels for the stack positionsempty
fillsgradient fills used instead of colors, cycled per barnull

barCornerRadius is new in version 4. The radius is capped at half the bar's width and height, so a short bar keeps a sane shape. On a stacked bar only the top corners of the last stack segment are rounded, which keeps the stack looking like one bar.

Bar shadows are switched on at the chart, with chart.isDrawBarShadowEnabled = true, and then use each set's barShadowColor.

Stacking is decided by the entries: a BarEntry with stackValues is a stacked bar. Three read-only properties describe it, the last of them on BarDataSet rather than on the interface:

PropertyMeaning
stackSizelargest number of stack values in any entry, 1 for plain bars
isStackedtrue when stackSize is above 1
entryCountStacksnumber of entries counting every stack value separately

For fills, see Setting colors. setGradientColor(startColor, endColor) is the shortcut for one gradient on every bar.

ScatterDataSet#

val set = ScatterDataSet(entries, "DS 2")
set.setScatterShape(ScatterChart.ScatterShape.CIRCLE)
set.scatterShapeSize = 8f
set.scatterShapeHoleRadius = 3f
set.scatterShapeHoleColor = ColorTemplate.COLORFUL_COLORS[3]
PropertyMeaningDefault
scatterShapeSizesize of each shape; the built-in shape renderers read it as pixels15f
shapeRendererthe object that draws the shapeSquareShapeRenderer()
scatterShapeHoleRadiusradius of the hole in dp, 0 for none0f
scatterShapeHoleColorhole color, COLOR_NONE leaves it transparentCOLOR_NONE

setScatterShape(shape) swaps in the built-in renderer for SQUARE, CIRCLE, TRIANGLE, CROSS, X, CHEVRON_UP or CHEVRON_DOWN. Only square, circle and triangle draw a hole.

For a shape of your own, implement IShapeRenderer and assign it to shapeRenderer directly. ScatterDataSet.getRendererForShape(shape) returns a fresh built-in renderer if you want to wrap one.

CandleDataSet#

A candle set colors the body by direction. All four colors start at ColorTemplate.COLOR_NONE, which means the renderer falls back to the entry's color from colors.

PropertyMeaningDefault
increasingColorbody color when close is above openCOLOR_NONE
decreasingColorbody color when close is below openCOLOR_NONE
neutralColorbody color when open equals closeCOLOR_NONE
increasingPaintStylefilled or outlined increasing bodiesPaint.Style.STROKE
decreasingPaintStylefilled or outlined decreasing bodiesPaint.Style.FILL
showCandleBardraw bodies, or only the open and close tickstrue
barSpacespace left free on each side of a body, as a fraction of the x step, clamped to 0 to 0.450.1f
shadowWidthstroke width of the high to low line in dp1.5f
shadowColorcolor of that lineCOLOR_NONE
shadowColorSameAsCandledraw the line in its candle's body colorfalse
set.increasingColor = Color.rgb(122, 242, 84)
set.increasingPaintStyle = Paint.Style.STROKE
set.decreasingColor = Color.RED
set.decreasingPaintStyle = Paint.Style.FILL
set.shadowColor = Color.DKGRAY
set.shadowWidth = 0.7f

The y range of a candle set comes from the entries' low and high, not from their y.

BubbleDataSet#

PropertyMeaningDefault
isNormalizeSizeEnabledscale bubbles relative to maxSize so the largest fills the reference size; off uses the entry size as a direct factortrue
highlightCircleWidthstroke width of the ring around a highlighted bubble in dp1f
maxSizelargest entry size in the set, read onlyrecomputed with the ranges

maxSize is recomputed from scratch whenever the full ranges are, so it shrinks again after an entry is removed or after notifyDataSetChanged(). Adding a single entry can only widen it.

RadarDataSet#

A radar set is a LineRadarDataSet, so it has the line width and the fill settings above. On top it configures the ring on a highlighted entry.

PropertyMeaningDefault
isDrawHighlightCircleEnableddraw the ring at allfalse
highlightCircleFillColorfill of the ring, COLOR_NONE for no fillwhite
highlightCircleStrokeColorstroke of the ring, COLOR_NONE uses the set's first colorCOLOR_NONE
highlightCircleStrokeAlphaopacity of the stroke, 0 to 25576
highlightCircleInnerRadiusinner radius in dp3f
highlightCircleOuterRadiusouter radius in dp4f
highlightCircleStrokeWidthstroke width in dp2f

PieDataSet#

A PieData holds exactly one pie set. Only the y range is tracked, because pie entries have no x.

PropertyMeaningDefault
sliceSpacegap between slices in dp, clamped to 0 to 200f
isAutomaticallyDisableSliceSpacingEnableddrop the gap when the smallest slice would be narrower than itfalse
selectionShifthow far a highlighted slice is pushed out, in dp9f
highlightColorcolor of a highlighted slice, null keeps the slice colornull

Labels and values can sit inside the slice or outside it, each on its own:

set.xValuePosition = PieDataSet.ValuePosition.OUTSIDE_SLICE
set.yValuePosition = PieDataSet.ValuePosition.OUTSIDE_SLICE

xValuePosition places the entry label, yValuePosition the value. Both default to INSIDE_SLICE. Once something sits outside, a connector line is drawn to it:

PropertyMeaningDefault
valueLineColorcolor of the connectorblack
isUseValueColorForLineEnableddraw it in the slice color insteadfalse
valueLineWidthstroke width in dp1f
valueLinePart1OffsetPercentagewhere the line starts, as a percentage of the radius75f
valueLinePart1Lengthlength of the outward part, as a fraction of the radius0.3f
valueLinePart2Lengthlength of the horizontal part, as a fraction of the radius0.4f
isValueLineVariableLengthshorten the line for slices near the horizontal centertrue
copy() on a pie set carries over the inherited styling only. None of the properties in this section are copied.