Suggested way to add Data to Charts

Hello,
I’m having some difficulties in understanding what’s more future proof for adding data to Charts.
The documentation (Connecting Data - CUBA Platform. Displaying Charts And Maps) lists three different approaches:
1 - DataProvider, but ListDataProvider is deprecated
2 - CollectionDatasource
3 - Simpified Data Binding API, which looks like the new way, but MapDataItem is already (or still?) deprecated. Also, I can add data with this method, but how can I remove it from the chart?

Is using a Datasource the suggested way to handle this? Are ValueCollectionDatasource flexible enough to handle directly custom data produced by Services and Controllers?

Hi,

All approaches described in the documentation can be used for data binding. Classes from the com.haulmont.charts.gui.amcharts.model.data package are deprecated, but there are new ones for the same purpose in the com.haulmont.charts.gui.data package (as mentioned in the java doc).

There are some samples in our Sampler app, that clarify charts usage:

  1. ListDataProvider with [url=https://demo.cuba-platform.com/sampler/open?screen=entity-data-item]EntityDataItem[/url], [url=https://demo.cuba-platform.com/sampler/open?screen=map-data-item]MapDataItem[/url], [url=https://demo.cuba-platform.com/sampler/open?screen=simple-data-item]SimpleDataItem[/url]
  2. [url=https://demo.cuba-platform.com/sampler/open?screen=update-column-chart]Incremental update[/url] (adding and removing data). The datasource is used as an axample, but both Datasource and ListDataProvider have methods for adding, updating and removing data with triggering chart update.
  3. [url=https://demo.cuba-platform.com/sampler/open?screen=chart-valueds]ValueDatasource[/url]

Regards,
Gleb

1 Like