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:

  1. The type of the data
  2. How to access the data

The dimension's type

The dimension's choice defines the type of your data.

There are 4 types of dimension:

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/b5778c4e-b7d7-4796-a634-b101121a91e7/Untitled.png

Let'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.

The dimension's accessor (how to access the 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.