There are two ways how you can pass data to a chart: through the DataProvider
interface or using the datasource mechanism.
-
The
DataProvider
interface has a standard implementation:ListDataProvider
class. It contains a list ofDataItem
instances, each one containing a set of key-value pairs. An instance ofDataProvider
is passed to thesetDataProvider()
method of chart configuration. This approach to providing chart data is the most universal, but it requires you to create instances ofDataProvider
andDataItem
in a screen controller. -
A
CollectionDatasource
type datasource can be assigned to aChart
component by invoking thesetDatasource()
method. This approach requires an entity that will represent chart data. It may be convenient when such entity already exists in the application data model and also when chart data should be displayed as a table.
Section 1.4, “Example of Working with Charts” illustrates both approaches to providing chart data.
Entity properties or the values contained in an instance of DataProvider
which are used for display purposes are defined in the chart attributes. The set of chart attributes may differ for different
chart types. For example, for the chart:pieChart
component, you should define the valueField
and titleField
attributes. The following types are allowed for attribute values: Integer
, Long
, Double
, String
, Boolean
, Date
.
Dynamic addition of data to an existing chart is not supported; you should redraw the entire chart to display new data. This
can be done using the repaint()
method.