kandy 0.6.0 Help

Kandy with Gradle

Using the Kandy library is possible in Kotlin projects on the JVM managed by Gradle.

Getting started with Kandy on Gradle

  1. Install IntelliJ IDEA

  2. From the main menu, select File | New | Project.

  3. In the panel on the left, select New Project.

  4. Choose Kotlin as the programming language and Gradle as the build system.

    New Project in IDEA
  5. Click Create button.

  6. Navigate to your Gradle build file, which could either be build.gradle.kts (for Kotlin DSL) or build.gradle (for Groovy DSL), and add the Kandy library as a dependency:

dependencies { implementation("org.jetbrains.kotlinx:kandy-lets-plot:0.6.0") }
dependencies { implementation 'org.jetbrains.kotlinx:kandy-lets-plot:0.6.0' }

You now have access to the Kandy library in your Kotlin project.

To also use statistical functions with Kandy, add the following to your build script:

repositories { maven("https://packages.jetbrains.team/maven/p/kds/kotlin-ds-maven") } dependencies { implementation("org.jetbrains.kotlinx:kotlin-statistics-jvm:0.2.1") }
repositories { maven "https://packages.jetbrains.team/maven/p/kds/kotlin-ds-maven" } dependencies { implementation "org.jetbrains.kotlinx:kotlin-statistics-jvm:0.1.0" }

Plotting a Simple Example

import org.jetbrains.kotlinx.dataframe.api.dataFrameOf import org.jetbrains.kotlinx.kandy.dsl.plot import org.jetbrains.kotlinx.kandy.letsplot.export.save import org.jetbrains.kotlinx.kandy.letsplot.layers.bars fun main() { // Create a DataFrame with data on average temperatures in various cities val averageTemperature = dataFrameOf( "city" to listOf("New York", "London", "Berlin", "Yerevan", "Tokyo"), "average temperature" to listOf(12.5, 11.0, 9.6, 11.5, 16.0) ) // Construct a plot using the data from the DataFrame averageTemperature.plot { // Add bars to the plot // Each bar represents the average temperature in a city bars { x("city") // Set the cities' data on the X-axis y("average temperature") { // Set the temperatures' data on the Y-axis axis.name = "Average Temperature (°C)" // Assign a name to the Y-axis } } // Set the title of the plot layout.title = "Kandy Getting Started Example" }.save("Started Example.png") // Save plot as PNG image }
Kandy Getting Started Example

This supplementary schema outlines the key elements of Kandy's DSL, providing a quick reference to assist you in building your visualizations.

For more examples, please see the Examples section.

Last modified: 13 May 2024