19.3. Basic Use
The Chart is a regular Vaadin component, which you can add to a layout.You can give the chart type in the constructor or set it later in the chart model. A chart has a height of 400 pixels and takes full width by default, which settings you may often need to customize.
Chart chart = new Chart(ChartType.COLUMN); chart.setWidth("400px"); // 100% by default chart.setHeight("300px"); // 400px by default
The chart types are described in Section 19.4, “Chart Types”.
Configuration
After creating a chart, you need to configure it further. At the least, you need to specify the data series to be displayed in the configuration.
Most methods available in the Chart object handle its basic Vaadin component properties. All the chart-specific properties are in a separate Configuration object, which you can access with the getConfiguration() method.
Configuration conf = chart.getConfiguration(); conf.setTitle("Reindeer Kills by Predators"); conf.setSubTitle("Kills Grouped by Counties");
The configuration properties are described in more detail in Section 19.5, “Chart Configuration”.
Plot Options
Many chart settings can be configured in the plot options of the chart or data series. Some of the options are chart type specific, as described later for each chart type, while many are shared.
For example, for line charts, you could disable the point markers as follows:
// Disable markers from lines
PlotOptionsLine plotOptions = new PlotOptionsLine(); plotOptions.setMarker(new Marker(false)); conf.setPlotOptions(plotOptions);
You can set the plot options for the entire chart or for each data series separately, allowing also mixed-type charts, as described in Section 19.3.2, “Mixed Type Charts”.
The shared plot options are described in Section 19.5.1, “Plot Options”.
Chart Data
The data displayed in a chart is stored in the chart configuration as a list of Series objects. A new data series is added in a chart with the addSeries() method.
ListSeries series = new ListSeries("Diameter"); series.setData(4900, 12100, 12800,
6800, 143000, 125000, 51100, 49500);
conf.addSeries(series);
The data can be specified with a number of different series types DataSeries, ListSeries, AreaListSeries, and RangeSeries. The data configuration is described in more detail in Section 19.6, “Chart Data”.