Vaadin 17 includes a major Vaadin Charts upgrade

Johannes Häyry
Johannes Häyry
On Sep 14, 2020 4:58:02 PM
In Product

Frame 5

We released a major upgrade for Vaadin Charts as part of Vaadin 17. Read on to learn about the Java API for styling, new chart types, and how to upgrade.

Java API to style charts returns

The Java API to style charts is back in Vaadin 17! In Vaadin 8, it was possible to style charts using only Java, but this feature was dropped in Vaadin 10. The API is back and it’s as comprehensive as before: it covers colors, grid-line widths, border widths, dash styles, font sizes, and more. Using CSS files to style charts is now optional, and the new (old) API is the default.

For example, if you want to set the plot band colors with the Java API, you can simply provide the value in the constructor or call a setter.

YAxis yAxis = conf.getyAxis();
yAxis.addPlotBand(new PlotBand(0, 150, new SolidColor("#666666")));

Alternatively, you can use CSS for styling. Include the default theme module and import your custom CSS module for Charts.

@CssImport(value = "./styles/my-chart-styles.css", themeFor = "vaadin-chart", include = "vaadin-chart-default-theme")
public class MyView extends VerticalLayout {
  // ...

Create your Chart in styled mode.

Chart chart = new Chart(ChartType.BULLET);
Configuration conf = chart.getConfiguration();

To change the plot band’s color, simply add your custom CSS class name.

PlotBand band0 = new PlotBand();

Then change the color in your CSS file.

/* <project-root>/frontend/styles/my-chart-styles.css */ {
	fill: #666666;

New chart types and other improvements

The new Charts version introduces four new chart types: Bullet, Organization, X Range, and Timeline.


Example of a bullet graph


Example of an organization chart

X Range

Example of an x-range graph


Example of a timeline graph

We reintroduced a couple of features from the Vaadin 8 version of Charts. You can set the Lang object for localization and other global chart options.

Here’s how to add localisations for month names:

// Months in Finnish
String[] fiMonths = new String[] {"Tammikuu", "Helmikuu", "Maaliskuu",
    "Huhtikuu", "Toukokuu", "Kesäkuu", "Heinäkuu", "Elokuu",
    "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu"};
Lang fi = new Lang();
ChartOptions options  = ChartOptions.get();

The DrillDown event callback is also available. It allows you to create lazy-loading data for drill-down graphs.

private void createMyChart() {
  final Chart chart = new Chart(ChartType.COLUMN);
  conf = chart.getConfiguration();

	// PlotOptions omitted
  DataSeries series = new DataSeries();
  DataSeriesItem item = new DataSeriesItem("LUAE", 42);
  chart.setDrilldownCallback(event -> getPointDrilldown(event.getItem()));

private Series getPointDrilldown(DataSeriesItem item) {
  // Create and return a new DataSeries based on item.getId()

How to upgrade

The new Charts version is part of Vaadin 17. If you are using Vaadin 16, simply upgrade the version number of the Vaadin platform dependency.

As a Vaadin 14 user, you should still be able to use the LTS version of the platform and only upgrade the Charts version to the latest one, but we haven’t tested that yet extensively. If you have already tried the new version with Vaadin 14, let me know in the comments.  Be aware that the LTS support does not yet cover new Charts. Alternatively, you can wait for the backport of Charts to an upcoming Vaadin 14 minor version. We currently estimate that it will be available in version 14.5.0.

Chart types documentation
Johannes Häyry
Johannes Häyry
I'm a developer disguised as a product marketer. I usually write about new Vaadin releases or the upcoming cool features on the roadmap.
Other posts by Johannes Häyry