# 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 :-*

```kotlin
// 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 :-*

```kotlin
// Transforming a List<T> to List<Coordinate<T>>
val yLabel = mutableListOf("Excellent", "Good", "Average", "Bad", "Worst")
val yLabelList1: List<Coordinate<String>> = yLabel.toCoordinateSet()

// Creating our own List<Coordinate<T>>
val yLabelList2: List<Coordinate<Float>> = Coordinate.coordinateSetBuilder(
        1f, 2f, 3f, 4f, 5f, 6f
)

// Creating our own List<Coordinate<T>>
val yLabelList3: List<Coordinate<Float>> = Coordinate.coordinateSetBuilder(
        listOf(1f , 2f , 3f , 4f , 5f)
)
```

## 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 :-*&#x20;

```kotlin
// Creating Linear Data directly from class constructor()
val linearDataSet1: List<LinearDataSet> = listOf(
    LinearDataSet(
        title = "Amazon",
        markers = listOf(100f, 200f, 303f, 408f, 52f).toCoordinateSet()
    )
)

// Creating Linear Data using the in - built function
val linearDataSet2: List<LinearDataSet> = listOf(
    LinearDataSet.createDataSet(
        title = "Amazon",
        markers = listOf(100f, 200f, 303f, 408f, 52f)
    ),
    LinearDataSet.createDataSet(
        title = "Google",
        markers = listOf(10f, 290f, 492f, 201f, 502f)
    ) // It converts the markers List<T> to List<Coordinate<T>> internally
)
```

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

<pre class="language-kotlin"><code class="lang-kotlin"><strong>// Each List represents a data set
</strong>val list1 = listOf(6f, 5f, 4f, 6f, 7.5f, 7f, 6f)
val list2 = listOf(3f, 6f, 8f, 2f, 3.5f, 3f, 4f)

// You can directly set the lists like this
val linearDataSet1: List&#x3C;LinearDataSet> = listOf(
<strong>    LinearDataSet.createDataSet(title = "Amazon", markers = list1),
</strong>    LinearDataSet(title = "Google", markers = list2.toCoordinateSet())
)
</code></pre>

### 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 :-*&#x20;

```kotlin
// We can create multiple Linear Data Set inside the listOf()
val linearDataSet1: List<LinearDataSet> by remember {
    mutableStateOf(
        listOf(
            LinearDataSet.createDataSet(
                title = "Amazon",
                markers = listOf(1f, 2f, 3f, 4f, 5f)
            ), // Using built - in functions 
            LinearDataSet(
                title = "Google",
                markers = listOf(1f, 2f, 3f, 4f, 5f).toCoordinateSet()
            ) // Using constructor call
        )
    )
}
```

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

```kotlin
// Declare the lists from which you would want to create a Linear Data Set 
val list1 = listOf(6f, 5f, 4f, 6f, 7.5f, 7f, 6f)
val list2 = listOf(3f, 6f, 8f, 2f, 3.5f, 3f, 4f)

// You can directly set the lists like this
val linearDataSet: List<LinearDataSet> by remember {
    mutableStateOf(
        listOf(
            LinearDataSet.createDataSet(
                title = "Amazon",
                 markers = list1
             ), // Using built - in functions 
            LinearDataSet(
                 title = "Google",
                 markers = list2.toCoordinateSet()
             ) // Using constructor call
        )
    )
}
```

{% hint style="warning" %}
Warning:- If you are unable to create Linear Data Sets properly, we advise you to read through this page again before proceeding forward to create plots.

After finishing, you can follow the link given below and head to the linear plot section.
{% endhint %}

{% content-ref url="/pages/K13AD5SKgAC6rfcOGylM" %}
[Linear Plots](/jetchart/plot-tool-kit/linear-plots.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev-anirban.gitbook.io/jetchart/plot-tool-kit/data-types-for-linear-plots.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
