Dimensions are a core concept of Charts-kt, every chart needs dimensions to explain which properties will be displayed, and how they'll be displayed.
In order to do this, a dimension describes:
The dimension's choice defines the type of your data.
There are 4 types of dimension:
Quantitative
, for continuous numeric valuesTemporal
, for continuous temporal valuesDiscrete
, for discrete values or "categories"Constant
, for values that cannot changeLet's consider this Kotlin data class TemperatureRecord
:
//run highlight-only
data class TemperatureRecord(
val temperature: Double,
val location: Town,
val time: Instant
)
If you want to translate this class' values into dimensions, you could write this:
//run highlight-only
chart(temperatureRecords) {
val temperatureDimension = quantitative( { domain.temperature } )
val timeDimension = temporal ( { domain.time } )
val locationDimension = discrete ( { domain.location } )
}
Choosing the right dimension type (quantitative, temporal, discrete) is crucial to describe how to handle your data.
As you've seen above, a dimension is instantiated through a function that defines its type, and a parameter which is a lambda that is called the accessor.