Skip to content
javahacks.dev
Vaadin

Vaadin Charts and Dashboards for Data Heavy Java Views

Build charts and a dashboard in Vaadin Flow with the Chart component and Configuration API, update data from the server, and plan for the commercial licence.

5 min read
Summarize in AI
Flat illustration of a browser page built from server-side components, with the Vaadin, OpenJDK, CSS, Spring and Thymeleaf logos.

Server-side Java views often need a chart: revenue by month, requests by status. Vaadin offers a chart component whose configuration is plain Java. This is for Vaadin 25, and the framework basics are in the Vaadin guide.

A first chart

java
Chart chart = new Chart(ChartType.COLUMN);
Configuration conf = chart.getConfiguration();
conf.setTitle("Orders per month");

XAxis x = new XAxis();
x.setCategories("Jan", "Feb", "Mar", "Apr");
conf.addxAxis(x);

YAxis y = new YAxis();
y.setTitle("Orders");
conf.addyAxis(y);

conf.addSeries(new ListSeries("2026", 120, 135, 98, 160));

ChartType selects the form: COLUMN, LINE, PIE, AREA and others. Each series is a named list of values aligned with the categories. Because the component renders in the browser from the configuration, no image is generated on the server.

Update the data

java
ListSeries series = (ListSeries) chart.getConfiguration().getSeries().get(0);

series.updatePoint(3, 175);          // change one value
series.addData(142);                 // append
chart.drawChart();                   // redraw after structural changes

Point-level methods send a small update. Changes to titles, axes or the series list need drawChart(). In a view that refreshes on a timer or from a background thread, use ui.access(...) with push, as described in push and server updates.

A dashboard layout

java
class Card extends VerticalLayout {
    Card(String title, Component content) {
        add(new H3(title), content);
        addClassName("card");
        setPadding(true);
    }
}

FlexLayout dashboard = new FlexLayout(
        new Card("Orders", ordersChart),
        new Card("Revenue", revenueChart),
        new Card("Status", statusPie));
dashboard.setFlexWrap(FlexLayout.FlexWrap.WRAP);
dashboard.setWidthFull();

Give the cards a minimum width and a gap in the theme CSS so they wrap on small screens. Vaadin also ships a Dashboard component with draggable, resizable widgets in its commercial set. Both approaches are layouts of components, and the routing around them is in routing and layouts.

Feed the chart from a service

java
Map<YearMonth, Long> counts = orderService.countByMonth(2026);
ListSeries s = new ListSeries("2026");
counts.values().forEach(s::addData);

Aggregate in the database, not in the view: a query that returns twelve rows is cheap, and loading every order to count them is not. For tabular detail next to the chart, use a lazily loaded grid, see Grid lazy loading.

The licence

Charts, Dashboard and several other components are commercial Vaadin components. Using them in development shows a trial notice, and production use requires a subscription and a licence key in the build. Decide this before the interface depends on them. The core Flow components, including Grid, are open source.

Free alternatives

  • A table or Grid with sparkline-like text for small summaries.
  • A JavaScript library such as Chart.js wrapped in a @JsModule and a custom element, as in custom components with web components.
  • Server-rendered SVG inserted with Html for simple static graphics.

How much data a chart can show

A browser draws a chart from every point it receives, so the number of points is the main performance control. A line with 500 points looks smooth and renders instantly. A line with 200,000 points renders slowly, hides detail behind overdrawn pixels and sends a large payload to every session. Reduce the data on the server before it leaves: aggregate by hour or day, downsample with an algorithm that keeps peaks, or load a coarse series first and fetch detail when the user zooms. A good rule is that nobody can read more than a few hundred points across a screen, so sending more serves the library and not the reader.

Charts that update often need a plan too. Pushing a new point every second to a hundred open sessions means a hundred updates per second from the server. Batch updates to what a person can perceive, usually once every few seconds, and push only the changed point instead of redrawing the series.

Accessibility and honesty in charts

A chart is an image of numbers, and screen reader users get nothing from an image. Give each chart a text alternative with the key finding in a sentence, and offer the underlying data as a table next to it or behind a toggle. Do not rely on colour alone to tell series apart: add markers, dash styles or direct labels. Start bar charts at zero, since a truncated axis makes a small change look dramatic. These choices cost an hour per dashboard and decide whether the dashboard can be trusted and used by everyone.

Testing views that contain charts

Test the part that is yours: the service that produces the series and the view logic that maps it to the chart's configuration. A unit test can assert that a month of orders produces thirty-one points in the right order, with no browser involved. For the chart itself, a couple of browser tests that open the dashboard and check that the chart container exists and that a known label is rendered catch wiring mistakes. Do not try to assert on pixels.

Licensing and what to check before you commit

The chart components are part of a commercial offering, so check the current licence terms and the cost per developer before you build a dashboard around them, and check what happens to a deployed application if a subscription lapses. If the terms do not fit, the free alternatives below, including a JavaScript library wrapped in a small custom component, are a legitimate choice, and the data flow from your service stays the same either way.

Responsive layout for a dashboard

A dashboard is read on a laptop, a wall display and sometimes a phone, so build it with flexible widths and not fixed pixels. Put widgets in a layout that wraps, give each a minimum width, and let them reflow. Charts need an explicit height or they collapse to nothing, which is the first problem most people see. Keep the number of widgets small. A dashboard with fifteen charts is read as noise, and one with five answers a question. Start by writing the three questions the viewer should be able to answer in ten seconds, and design the widgets to match.

Refresh strategy

Decide how fresh the data must be, and then do the cheapest thing that meets it. Many dashboards are fine with a refresh when the user opens the page and a button for more. If you need live data, push updates from the server on a timer, but share the query between viewers: compute the numbers once per interval and broadcast them, instead of running the same SQL for every open session. A hundred viewers each running a query every five seconds is a self-inflicted load test on your database.

Where this does not apply

A chart with tens of thousands of points is slow in any browser, so downsample on the server. Accessibility needs a text alternative, such as the same numbers in a grid. The reference is the Vaadin Charts documentation, and Highcharts documents the underlying options.

Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.