kandy 0.8.0-RC1 Help

Pie

val dataset = dataFrameOf( "name" to listOf('a', 'b', 'c', 'd', 'b'), "value" to listOf(40, 90, 10, 50, 20) )

Basic Pie Chart

dataset.plot { pie { slice(value) fillColor(name) } }
Basic Pie Chart

Improve appearance

  • configure stroke

  • make the pie bigger

  • add hole to draw donut-like chart

  • use blank theme

  • use better colors

dataset.plot { pie { slice(value) fillColor(name) { scale = categoricalColorBrewer(BrewerPalette.Qualitative.Set1) } size = 20.0 stroke = 1.0 strokeColor = Color.WHITE hole = 0.5 } layout { style(Style.Void) } }
Configured Pie Chart

Explode

val length = dataFrameOf( "name" to listOf( "20-50 km", "50-75 km", "10-20 km", "75-100 km", "3-5 km", "7-10 km", "5-7 km", ">100 km", "2-3 km" ), "count" to listOf(1109, 696, 353, 192, 168, 86, 74, 65, 53), "explode" to listOf(.0, .0, .0, .1, .1, .2, .3, .4, .6) )
length.plot { pie { fillColor(name) { scale = continuous(Color.named("dark_blue"), Color.LIGHT_GREEN) } slice(count) explode(explode) stroke = 1.0 strokeColor = Color.BLACK size = 20.0 } layout.style(Style.Void) }
Explode Pie Chart
val calories = dataFrameOf( "slice" to listOf(35, 25, 25, 15), "label" to listOf("Apples", "Bananas", "Cherries", "Dates"), "explode" to listOf(.1, .0, .0, .0) )
plotGrid( listOf( calories.plot { pie { slice(slice) explode(explode) fillColor(label) { scale = categoricalColorBrewer(BrewerPalette.Qualitative.Set1) } size = 15.0 } layout { style(Style.Void) } }, calories.plot { pie { slice(slice) explode(explode) fillColor(label) { scale = categoricalColorBrewer(BrewerPalette.Qualitative.Set1) } size = 15.0 hole = 0.8 } layout { style(Style.Void) } } ) )
Two Pie Charts
Last modified: 26 March 2024