Bullet Graphs

The bullet graph is a type of linear bar guage and is based on the Perceptual Edge Bullet Graph Design Specification.

The below example creates a single bullet graph with a two-line title.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
    BulletGraphs(modifier = Modifier.padding(16.dp).height(100.dp)) {
        bullet(FloatLinearAxisModel(0f..300f)) {
            label {
                Column(
                    horizontalAlignment = Alignment.End,
                    modifier = Modifier.padding(end = KoalaPlotTheme.sizes.gap)
                ) {
                    Text("Revenue 2005 YTD", textAlign = TextAlign.End)
                    Text("(US $ in thousands)", textAlign = TextAlign.End, style = MaterialTheme.typography.labelSmall)
                }
            }
            axis { labels { Text("${it.toInt()}") } }
            comparativeMeasure(260f)
            featuredMeasureBar(275f)
            ranges(0f, 200f, 250f, 300f)
        }
    }
/examples/src/jvmMain/kotlin/io/github/koalaplot/example/BulletGraph.kt

Bullet

It is common to use multiple bullet graphs together, and to ensure each is the same width and with labels aligned. That is possible using the BulletGraphs Composable as demonstrated below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    @Composable
    fun TwoLineLabel(line1: String, line2: String) {
        Column(
            horizontalAlignment = Alignment.End,
            modifier = Modifier.padding(end = KoalaPlotTheme.sizes.gap)
        ) {
            Text(line1, textAlign = TextAlign.End)
            Text(line2, textAlign = TextAlign.End, style = MaterialTheme.typography.labelSmall)
        }
    }

    BulletGraphs(modifier = Modifier.padding(16.dp)) {
        bullet(FloatLinearAxisModel(0f..300f)) {
            label { TwoLineLabel("Revenue", "(US $ in thousands)") }
            axis { labels { Text("${it.toInt()}", style = MaterialTheme.typography.labelSmall) } }
            comparativeMeasure(250f)
            featuredMeasureBar(275f)
            ranges(0f, 150f, 225f, 300f)
        }
        bullet(FloatLinearAxisModel(0f..30f)) {
            label { TwoLineLabel("Profit", "%") }
            axis { labels { Text("${it.toInt()}%", style = MaterialTheme.typography.labelSmall) } }
            comparativeMeasure(26f)
            featuredMeasureBar(22.5f)
            ranges(0f, 20f, 25f, 30f)
        }
        bullet(FloatLinearAxisModel(0f..600f)) {
            label { TwoLineLabel("Avg Order Size", "U.S. $") }
            axis { labels { Text("${it.toInt()}", style = MaterialTheme.typography.labelSmall) } }
            comparativeMeasure(550f)
            featuredMeasureBar(325f)
            ranges(0f, 350f, 500f, 600f)
        }
    }
/examples/src/jvmMain/kotlin/io/github/koalaplot/example/BulletGraph2.kt

Bullet


Last modified April 23, 2024: Changes for 0.6.0 (19018a1)