All artifacts are available at Maven Central.
| Lets-Plot Kotlin API |
lets-plot-kotlin-jvm lets-plot-kotlin-js lets-plot-kotlin-geotools |
|
Published by this project. |
| Lets-Plot (JVM) |
lets-plot-swing lets-plot-batik (obsolete) |
|
Published by the Lets-Plot project. |
The following is how you configure a Gradle project with Kotlin DSL.
plugins {
kotlin("jvm")
}
dependencies {
// Lets-Plot Kotlin API
implementation("org.jetbrains.lets-plot:lets-plot-kotlin-jvm:4.13.0")
// Lets-Plot (JVM)
implementation("org.jetbrains.lets-plot:lets-plot-swing:4.9.0")
}plugins {
kotlin("multiplatform")
}
kotlin {
...
sourceSets {
named("jsMain") {
dependencies {
// Lets-Plot Kotlin API
implementation("org.jetbrains.lets-plot:lets-plot-kotlin-js:4.13.0")
}
}
}
}See Lets-Plot Kotlin Mini Apps (Demos) GitHub repository:
- JVM/Swing app examples
- Kotlin/JS app example
- JVM plot export examples:
Runnable examples that show how to export plot to an SVG, HTML or PNG image using
PlotSvgExport,PlotHtmlExportorPlotImageExportutilities.
- Create a figure object using the Lets-Plot Kotlin API:
val figure = letsPlot(data) + geomDensity(
color = "dark-green",
fill = "green",
alpha = .3,
size = 2.0) { x = "x" }- Convert the figure object to a map of plot specification parameters:
val rawSpec = figure.toSpec()
val processedSpec = MonolithicCommon.processRawSpecs(rawSpec, frontendOnly = false)- Create a plot Swing panel: SwingPlotPanel:
val panel: JPanel = SwingPlotPanel(
processedSpec = processedSpec,
preserveAspectRatio = preserveAspectRatio,
preferredSizeFromPlot = false,
repaintDelay = 10,
) { messages ->
for (message in messages) {
println("[Example App] $message")
}
}- Create a figure object using the Lets-Plot Kotlin API:
val figure = letsPlot(data) + geomDensity(
color = "dark-green",
fill = "green",
alpha = .3,
size = 2.0) { x = "x" }- Convert the figure object to a map of plot specification parameters:
val rawSpec = figure.toSpec()-
Generate HTML code:
a) A code which you can embed in your HTML document, providing the Lets-Plot JS library is already loaded statically via a
<script>tag in the document's<head>section.val html: String = PlotHtmlHelper.getStaticDisplayHtmlForRawSpec(rawSpec)
b) An
iframecode which includes everything needed to render the plot.val html: String = PlotHtmlExport.buildHtmlFromRawSpecs( plotSpec = rawSpec, scriptUrl = PlotHtmlHelper.scriptUrl(version="4.9.0"), iFrame = true )
-
Embed the generated HTML code in your document:
This is the tricky part because you have to make sure that the JavaScript included in the generated HTML code is not just added to DOM but also is executed by the browser.
For example, see: JsFrontendUtil.createPlotDiv(figure).
Note: In case you are using Android WebView to display the plot:
- enable JavaScript:
webView.settings.javaScriptEnabled = true- grant the internet access permission (AndroidManifest.xml):
<uses-permission android:name="android.permission.INTERNET" />
Code and documentation released under the MIT license. Copyright © 2019-2026, JetBrains s.r.o.