A Java and TeaVM demo book
Draw the web.
One chapter at a time.
Eight focused pages explore SVG, HTML Canvas, reusable charts, animation, and LMCode host functions. Every chapter is a separate page: the page is the selection.
SVG drawing
Create namespaced SVG shapes, groups, text, arcs, and Bézier paths from Java. The result remains ordinary inspectable DOM.
Canvas drawing
Use the same drawing primitives on an HTML Canvas, or drop down to TeaVM's CanvasRenderingContext2D for gradients and other native operations.
Bar charts
A band scale maps categories to evenly spaced bars. A linear scale, nice ticks, grid lines, and a zero baseline complete this small chart primitive.
Line charts
Multiple named series share Cartesian scales and axes. Each series becomes a path with point markers and a generated legend.
Scatter plots
Fifty-six samples in two series demonstrate that chart layout is independent of the output backend. Circles are immediate Canvas operations here.
Pie charts
Non-negative slices are normalized into arc wedges with percentage labels, separators, and a legend. Path2D translates center-parameterized arcs for SVG.
Animation and events
TeaVM schedules requestAnimationFrame callbacks. Pointer movement updates Java fields, and the pause button demonstrates ordinary browser event handling.
LMCode charts
LMCode supplies chart data through typed host functions. Java owns the Bar records and replaces the chart only after the handler completes successfully.