In this second tutorial, you'll see some of the basic features of Charts-kt, and build a bar chart based on your data model.
This tutorial will help you understand how to:
- Parse and map a CSV file to a Kotlin data class
- Use your own model and data in your charts
- Describe your values through "dimensions"
- Create a bar chart
- Understand the "Datum" concept
What do you need?
- 15 minutes
- A working JavaFX environment (see part 1)
- Intellij Community or Ultimate (tested with IntelliJ 2020.3.*)
Parsing a CSV file
This CSV file contains statistical weather data for each month of 2016 and 2017, for 5 different cities. Save it in the resources
repository of your project:
Weather - Stats.csv
Parsing this file is very easy using the multiplatform Dsv module of data2viz.
- create a Kotlin data class
Weather
to hold the information,
- load the file which is located in
"./src/main/resources/"
,
- parse each row and, if needed, drop the header (the first line of the file),
- finally, map each row of the file in a
Weather
instance.