Data2viz
.play
Explore
Sketches
Create
Sketch
Documentation
Let's start
Core mechanisms
Colors and gradients
Scales
Chromatic Scales
Forces
Random numbers
Fork
View
Editor
Details
Sign up
Log in
Basic styling
import io.data2viz.charts.* import io.data2viz.charts.dimension.* import io.data2viz.charts.chart.* import io.data2viz.charts.chart.mark.* import io.data2viz.charts.viz.* import io.data2viz.charts.layout.* import io.data2viz.charts.core.* import io.data2viz.geom.* import io.data2viz.color.* import io.data2viz.math.* import kotlin.random.Random val width = 700.0 val height = 400.0 val randomPoints = (1 .. 1000).map{ Point(Random.nextDouble(), Random.nextDouble()) } fun main() { // Creating and sizing the VizContainer val vc = newVizContainer().apply { size = Size(width, height) } // Chart DSL, our domain object is a "Point" vc.chart(randomPoints) { // Disable interaction config { events { highlightMode = HighlightMode.None } } // Create 2 continuous numeric dimensions val xPosition = quantitative( { domain.x } ) val yPosition = quantitative( { domain.y } ) // Plot values plot(xPosition, yPosition) { config { events { highlightMode = HighlightMode.Single } } // The size of a dot is a continuous dimension size = quantitative( { (domain.x + domain.y) * 80.0 }) // Create a discrete dimension for the color style val colorDiscrete = discrete( { val angle = ((domain.x + domain.y) * PI).rad Colors.hsl(angle, 80.pct, 50.pct) as Color? } ) // The color of a dot is a discrete dimension that returns a Color strokeColor = colorDiscrete strokeColorHighlight = colorDiscrete } } }
Sketch created by
pierre
2362
0
0
Charts.kt
Styling
Description
Very basic color and size styling.
comments
Submit
Lovers
comments