Area Chart
An area chart of rows that are given once: for each of the values read from them a line, with the room between it and nought filled.
import com.pantrixui.components.chart.area.PantrixAreaChart
- Fill.
fillsays what the room under the line is filled with:Gradientis the series' colour fading from the line towards zero,Solidan even tint of the colour. - Zero. An area chart's value axis starts at zero: an area's height is read as an amount, and an area cut off above zero shows less than there is. The axis can say otherwise with
startFromZero = false. Where values go below zero the area fills downwards from the zero line. - Areas over one another. Each area is drawn over the one before it, and all from zero: a later series covers an earlier one where it is larger. The fading fill shows the one underneath; give the larger series first.
- Stacked areas. With
stackedeach area stands on the one before it, and the topmost line is the total: the parts of a whole are shown so. The tooltip writes each series' own value, and then the total. Withstacking = ChartStacking.Percenteach place's total counts as a hundred percent and the areas show the shares. - Line.
curve,missing, and a series'dashandmarkerare as in the line chart. - Automation. The chart is tagged as the
PantrixChartit is:Chart_<tagKey>.
Examples
A single amount
A single amount over the months: the line goes through smoothly and the room under it is filled, its colour fading towards zero. The value axis starts at zero by itself; its values are written short (format).
A chart of one series has no legend: what the line is belongs to the words around the chart.
val strings = PantrixTheme.strings
PantrixAreaChart(
data = STORAGE,
x = { it.month },
values = listOf(ChartValue("used", "Space used") { it.used }),
curve = ChartCurve.Smooth,
yAxis = ChartAxis(format = { "${strings.decimal(it)} GB" }),
description = "Storage space used by month",
tagKey = "plain"
)
private data class Storage(
val month: String,
val used: Int,
val backups: Int
)
private val STORAGE = listOf(
Storage("Jan", used = 120, backups = 40),
Storage("Feb", used = 138, backups = 46),
Storage("Mar", used = 151, backups = 52),
Storage("Apr", used = 149, backups = 61),
Storage("May", used = 176, backups = 64),
Storage("Jun", used = 203, backups = 72),
Storage("Jul", used = 221, backups = 85),
Storage("Aug", used = 214, backups = 91),
Storage("Sep", used = 252, backups = 96),
Storage("Oct", used = 281, backups = 110),
Storage("Nov", used = 305, backups = 124),
Storage("Dec", used = 342, backups = 131)
)
Two amounts, two fills
Two amounts, the larger given first. With Gradient each area fades from its line towards zero, and the area underneath shows through the one above; with Solid the fill is an even tint. Turn the switch and compare the two.
var solid by remember { mutableStateOf(false) }
PantrixSwitchButton(
checked = solid,
onCheckedChange = { solid = it },
label = "Solid fill",
tagKey = "area_solid"
)
PantrixAreaChart(
data = STORAGE,
x = { it.month },
values = listOf(
ChartValue("used", "Space used") { it.used },
ChartValue("backups", "Backups") { it.backups }
),
curve = ChartCurve.Smooth,
fill = if (solid) ChartFill.Solid else ChartFill.Gradient,
description = "Space used and backups by month",
tagKey = "fills"
)
private data class Storage(
val month: String,
val used: Int,
val backups: Int
)
private val STORAGE = listOf(
Storage("Jan", used = 120, backups = 40),
Storage("Feb", used = 138, backups = 46),
Storage("Mar", used = 151, backups = 52),
Storage("Apr", used = 149, backups = 61),
Storage("May", used = 176, backups = 64),
Storage("Jun", used = 203, backups = 72),
Storage("Jul", used = 221, backups = 85),
Storage("Aug", used = 214, backups = 91),
Storage("Sep", used = 252, backups = 96),
Storage("Oct", used = 281, backups = 110),
Storage("Nov", used = 305, backups = 124),
Storage("Dec", used = 342, backups = 131)
)
Values that go below zero
Values on both sides of zero: a month's profit or loss. An area always fills towards zero: downwards in profit, upwards in loss. A line is drawn at zero, and the fading fill is strongest at the farthest point on either side of zero.
val strings = PantrixTheme.strings
PantrixAreaChart(
data = PROFIT,
x = { it.first },
values = listOf(ChartValue("profit", "Profit") { it.second }),
yAxis = ChartAxis(format = { strings.compact(it) }),
description = "Profit and loss by month",
tagKey = "below_zero"
)
private val PROFIT = listOf(
"Jan" to 84_000,
"Feb" to 52_000,
"Mar" to 21_000,
"Apr" to -18_000,
"May" to -46_000,
"Jun" to -31_000,
"Jul" to 9_000,
"Aug" to 38_000,
"Sep" to 67_000,
"Oct" to 95_000,
"Nov" to 112_000,
"Dec" to 140_000
)
A stepped area
A value that holds until it changes: a warehouse's stock. StepAfter carries each value level until the next, and the fill fills the room under the steps.
PantrixAreaChart(
data = STOCK,
x = { it.first },
values = listOf(ChartValue("stock", "Stock") { it.second }),
curve = ChartCurve.StepAfter,
fill = ChartFill.Solid,
description = "Stock in the warehouse by week",
tagKey = "stepped"
)
private val STOCK = listOf(
"Week 1" to 480,
"Week 2" to 480,
"Week 3" to 310,
"Week 4" to 310,
"Week 5" to 640,
"Week 6" to 520,
"Week 7" to 520,
"Week 8" to 270
)
Stacked areas
The parts of a whole: visits from three sources, stacked (stacked). Each area starts at the line of the one under it, and the topmost line is all the visits. The fill is a flat tint: so it reads where each area of the stack ends. The tooltip writes the month's total after the sources.
Turn the switch: each month counts as a hundred percent (stacking = ChartStacking.Percent). The areas are now the sources' shares and the axis writes percentages; the tooltip adds each value's share beside it.
Press a name in the legend: the source goes, and the ones over it come down into its place.
var shares by remember { mutableStateOf(false) }
PantrixSwitchButton(
checked = shares,
onCheckedChange = { shares = it },
label = "As shares",
tagKey = "area_shares"
)
PantrixAreaChart(
data = SOURCES,
x = { it.month },
values = listOf(
ChartValue("search", "Search") { it.search },
ChartValue("direct", "Direct") { it.direct },
ChartValue("social", "Social") { it.social }
),
fill = ChartFill.Solid,
stacked = true,
stacking = if (shares) ChartStacking.Percent else ChartStacking.Normal,
description = "Visits from three sources by month, stacked",
tagKey = "stacked"
)
private data class Sources(
val month: String,
val search: Int,
val direct: Int,
val social: Int
)
private val SOURCES = listOf(
Sources("Jan", search = 420, direct = 240, social = 130),
Sources("Feb", search = 480, direct = 260, social = 120),
Sources("Mar", search = 455, direct = 300, social = 165),
Sources("Apr", search = 530, direct = 280, social = 190),
Sources("May", search = 510, direct = 330, social = 240),
Sources("Jun", search = 560, direct = 310, social = 285)
)
API
data
An area chart of rows that are given once: for each of the values read from them a line, with the room between it and nought filled.
| Parameter | Type | Default | What it is |
|---|---|---|---|
data | List<T> | the rows, in the order the lines go through them. | |
x | (T) -> Any | where a row stands along the chart: a name, a day, anything that is equal to itself. | |
values | List<ChartValue<T>> | the series: what each reads from a row, and how it is called and drawn. | |
modifier | Modifier | Modifier | the chart's modifier. A height here is the chart's, the legend's with it. |
curve | ChartCurve | ChartCurve.Linear | how each line goes from a point to the next. |
fill | ChartFill | ChartFill.Gradient | what the room under each line is filled with: its colour fading down to nought, or a tint of it. |
missing | ChartMissing | ChartMissing.Gap | what a line does at a row that has no value. |
stacked | Boolean | false | whether each area stands on the one before it, in the order of values, and not on nought. |
stacking | ChartStacking | ChartStacking.Normal | how the stacked areas stand on one another: as their values, or as their shares of the stack. Areas that are not stacked have no stack for it to go by. |
labels | ChartDataLabels? | null | the values written over the points of every line, where they have room. null writes none. |
xAxis | ChartAxis? | ChartAxis() | the axis of the places, under the chart. null draws nothing of it. |
yAxis | ChartAxis? | ChartAxis() | the axis of the values, beside the chart. null draws nothing of it. |
secondYAxis | ChartAxis? | ChartAxis() | the second axis of the values, at the chart's other side: drawn where a value is read by it (ChartValue.axis), and not otherwise. null draws nothing of it. |
marks | List<ChartMark> | emptyList() | the lines and the bands drawn in the plot besides the series: a target, a limit, a stretch of places. |
legend | ChartLegend? | ChartLegend() | where the names of the series stand. null shows none. |
tooltip | ChartTooltip? | ChartTooltip() | what is shown for the place that is pointed at. null shows none. |
zoom | ChartZoom? | null | what lets the reader look closer at a part of the places and move along the rest. null, which it is unless the chart is given one, shows all the places and no more. |
decimation | ChartDecimation? | ChartDecimation() | how a line with more points in view than the plot has room for is drawn through fewer of them. null draws every point, as many as there are. |
export | ChartExport? | null | what lets the reader take the chart out of the app as a file: a picture, or a drawing that is sharp at any size. null, which it is unless the chart is given one, and the chart has no such button. |
empty | (@Composable () -> Unit)? | null | what the chart shows in its plot while it has no value to draw, in the place of the theme's words for it ("No data"), which a screen reader is then not told either. null writes the words. A file the chart is exported as says them. |
state | ChartState | rememberChartState() | what the reader has hidden and what they point at: the chart's own where none is given. |
description | String? | null | what the chart shows, in a few words, for a screen reader. |
onSelect | ((ChartPoint) -> Unit)? | null | called with the value that is pressed. |
style | ChartStyle? | null | this chart's own geometry. |
colors | ChartColors? | null | this chart's own colours, where they are not the theme's. |
tagKey | String? | null | the chart's automation key. The chart is tagged as the PantrixChart it is, Chart_<tagKey>, and its parts and events are that chart's. |
ChartStyle
A chart's geometry: how tall it is where nothing says, how thick its lines and how large its marks are, and the room between its parts; and whether its fills have textures besides their colours.
| Parameter | Type | Default | What it is |
|---|---|---|---|
height | Dp | Dp.Unspecified | How tall a chart's plot is, with its axes, where the chart's modifier gives it no height. A legend above or under the plot adds its own. |
lineWidth | Dp | Dp.Unspecified | The width of a series' line. |
markerSize | Dp | Dp.Unspecified | The width and height of the mark on a point. |
selectedMarkerSize | Dp | Dp.Unspecified | The same of the mark on the point that is pointed at. |
gridWidth | Dp | Dp.Unspecified | The width of the grid's lines, of the lines along the axes and of the line that marks the place pointed at. Zero draws none. |
labelGap | Dp | Dp.Unspecified | Between the plot and what is written beside it and under it, and between that and an axis' title. |
tickSpacing | Dp | Dp.Unspecified | The least room between two values marked along the axis of values: what decides how many are marked where the axis does not say. |
legendGap | Dp | Dp.Unspecified | Between the legend and the chart it stands beside. |
legendItemGap | Dp | Dp.Unspecified | Between one entry of the legend and the next. |
swatchSize | Dp | Dp.Unspecified | How wide the sample of a series is in the legend and in the tooltip: a short run of its line, or a patch of its fill. |
swatchGap | Dp | Dp.Unspecified | Between that sample and the name after it. |
tooltipShape | ShapeSpec | ShapeSpec.Unspecified | The tooltip's corners: a step of the brand's shape scale, or a fixed shape. |
tooltipHorizontalPadding | Dp | Dp.Unspecified | Between the tooltip's sides and what it holds. |
tooltipVerticalPadding | Dp | Dp.Unspecified | Between its top and bottom and what it holds, and between its heading and rows. |
tooltipGap | Dp | Dp.Unspecified | Between the place pointed at and the tooltip beside it. |
tooltipElevation | Dp | Dp.Unspecified | The tooltip's shadow. |
barGap | Dp | Dp.Unspecified | Between two bars that stand side by side at a place. Bars too thin for it stand closer. |
barMaxWidth | Dp | Dp.Unspecified | The widest a bar is, however much room its place has: a chart of three places is not three slabs. |
barRadius | Dp | Dp.Unspecified | How round the corners of a bar's end are, the end away from nought. |
sliceGap | Dp | Dp.Unspecified | Between two slices of a pie that lie side by side, the same from the pie's middle to its rim. |
selectedSliceOffset | Dp | Dp.Unspecified | How far the slice of a pie that is pointed at stands out past the pie's rim. The pie keeps this much room about itself, so that the slice has where to stand. |
gaugeWidth | Dp | Dp.Unspecified | How thick the arc of a gauge is. An arc is no thicker than half its radius. |
meterHeight | Dp | Dp.Unspecified | How tall the bar of a meter group is. |
trackerHeight | Dp | Dp.Unspecified | How tall the blocks of a status tracker are. |
bubbleMinSize | Dp | Dp.Unspecified | How far across the smallest bubble of a scatter chart is: a point whose size is nothing, or too little to be seen as an area, is still a point. |
bubbleMaxSize | Dp | Dp.Unspecified | How far across its largest bubble is: the one whose size is the most of the chart's. |
navigatorHeight | Dp | Dp.Unspecified | How tall the strip under a chart's plot is, on which the part of the chart that is in view is marked and moved, in a chart whose zoom has one: how wide, beside a plot whose places go down its side. |
barBandShare | Float | Float.NaN | How much of a place's band its bars take, more than nought and one at the most: the rest is the room between one place's bars and the next's. Bars are no wider than barMaxWidth all the same. |
markLineWidth | Dp | Dp.Unspecified | The width of a mark's line: a target, a limit, a day. Zero draws none, and the mark's words are written all the same. |
markBandAlpha | Float | Float.NaN | How much of its colour a mark's band is drawn in, from nought to one: a band lies behind the series, and is a tint. |
patterns | Boolean? | null | Whether the fills of a chart's series, slices and tiles are drawn with textures besides their colours, and its lines broken in turn (ChartPattern): what tells them apart for a reader who cannot tell the colours apart. Left out, as the system is set: on where it is set to tell things apart without colour, iOS's "Differentiate Without Color" and Android's colour correction, and off otherwise. |
nodeWidth | Dp | Dp.Unspecified | How wide a node of a sankey is. |
nodeGap | Dp | Dp.Unspecified | Between two nodes of a column of a sankey. |
ChartColors
What a chart is painted with, for a chart that does not take the theme's colours: a colour that is set is used, and one that is left out stays the theme's.
| Parameter | Type | Default | What it is |
|---|---|---|---|
series | List<Color> | emptyList() | The colours the series are drawn in, in the order they are handed out, for the series that name none of their own. Empty, they are the theme's chart colours. |
grid | Color | Color.Unspecified | The lines drawn across the chart at the marks of an axis. The theme's divider. |
axis | Color | Color.Unspecified | The line along an axis. The theme's border. |
label | Color | Color.Unspecified | What is written beside the axes: the values, the places and the axes' titles, and the names in the legend. The theme's textSecondary. |
crosshair | Color | Color.Unspecified | The line that marks the place pointed at. The theme's borderHover: stronger than the grid it crosses, and quieter than the series it stands behind. |
tooltipContainer | Color | Color.Unspecified | The tooltip's fill. The theme's surface. |
tooltipBorder | Color | Color.Unspecified | The tooltip's edge. The theme's border. |
tooltipText | Color | Color.Unspecified | The tooltip's heading and its values. The theme's textPrimary. |
tooltipLabel | Color | Color.Unspecified | The names of the series in the tooltip. The theme's textSecondary. |
rising | Color | Color.Unspecified | What a value that goes up is drawn in: a step of a waterfall that adds. The theme's success. |
falling | Color | Color.Unspecified | What a value that goes down is drawn in: a step of a waterfall that takes away. The theme's danger. |