πŸ“‘Data types for Linear Plots

Introduction

There are various ways to create data sets or format data for Jet Chart to understand and use it properly.

Mainly, two data types are widely used for linear plots.

  • Coordinate<T>

  • Linear Data Set

Coordinate<T>

Coordinates are the root objects for the linear charts and these represent a (x , y) coordinate in the graphs with a value attached to them.

Any value or variable you give to the linear charts library needs to be wrapped in the Coordinate object. According to the value, the library will calculate the respective (x , y) coordinates in the plot.

Here is an example of how to create a Coordinate<T> object :-

// Coordinate Example wrapping a Float
val coordinate = Coordinate<Float>(10f)

// Coordinate Example wrapping a String
val coordinate2 = Coordinate<String>("Excellent")

You can also transform a Kotlin List<T> into a Coordinate List<T> or create your own list directly, both using in-built functions.

Example of the above :-

Linear Data Sets

This is a data type that is used for linear plots. This contains the dataset title indicating the type of dataset and the actual dataset, markers, which is List<Coordinate<T>>.

Static Data Set

Linear Data Sets, which stay static and don't change or need any re-composition, can be created normally, like any other class object, as well as with the help of a public function.

Here's an example of how to create it by directly assigning values to it :-

Here is another way to create the same using pre-made lists :-

State Data Sets

Data Sets that can be remembered during re-composition can also be made and used like any other mutable State data. Developers can create them for dynamic UIs, where the data sets can change during runtime due to user interactions and re-composition becomes necessary.

Here's an example of how to create it by directly assigning values to it :-

Here is another way to create the same using pre-made lists :-

πŸ“ŠLinear Plots

Last updated

Was this helpful?