Views
2 months ago

tornadofx-guide

8. Charts Note you can

8. Charts Note you can also provide an explicit ObservableList prepared in advance. val items = listOf( PieChart.Data("Windows", 77.62), PieChart.Data("OS X", 9.52), PieChart.Data("Other", 3.06), PieChart.Data("Linux", 1.55), PieChart.Data("Chrome OS", 0.55) ).observable() piechart("Desktop/Laptop OS Market Share", items) The block following piechart can be used to modify any of the attributes of the PieChart just like any other control builder we covered. You can also leverage for() loops, Sequences, and other iterative tools within a block to add any number of data items. 122

8. Charts val items = listOf( PieChart.Data("Windows", 77.62), PieChart.Data("OS X", 9.52), PieChart.Data("Other", 3.06), PieChart.Data("Linux", 1.55), PieChart.Data("Chrome OS", 0.55) ).observable() piechart("Desktop/Laptop OS Market Share") { for (item in items) { data.add(item) } } Map-Based Data Sources Sometimes you may want to build a chart using a Map as a datasource. Using the Kotlin to operator, you can construct a Map in a Kotlin-esque way and then pass it to the data function. val items = mapOf( "Windows" to 77.62, "OS X" to 9.52, "Other" to 3.06, "Linux" to 1.55, "Chrome OS" to 0.55 ) piechart("Desktop/Laptop OS Market Share") { } data(items) XY Based Charts Most charts often deal with one or more series of data points on an XY axis. The most common are bar and line charts. Bar Charts You can represent one or more series of data points through a BarChart . This chart makes it easy to compare different data points relative to their distance from the X or Y axis (Figure 8.2). 123

GUIDE
Guide
GUIDE
Guide
GUIDE
GUIDE
Guide
GUIDE
Guide
Guide
Guide
GUIDE
GUIDE