Modifying Data and Updating Charts

The charts created in Views are data-aware. Data can be changed “on the fly” and all charts that display the data will be automatically updated to reflect the changes. The charts are automatically updated using listeners that are set on the data. The listeners catch data changes and can then be used to perform specific tasks according to the types of modifications that are made to the data.

Types of Modifications

The data displayed in a chart can be modified in different ways depending on whether the change is made at the level of the data set or at the level of the chart data object.

Modifications Made at the Data Set Level

The following types of modifications can be made to a data set:

  • A new data item can be added to the data set.

This can be done by using one of the following methods:

IlvChartDataSet::setPoint

IlvChartDataSet::addPoint

IlvChartDataSet::insertPoint

  • An existing data item in the data set can be replaced by another data item.

This can be done by using the IlvChartDataSet::setPoint method. This method sets the data item stored at a given index in a data set. If a data item already exists at the index, it is replaced by the new one.

  • A data item can be removed from the data set.

This can be done by using the IlvChartDataSet::removePointAndInfo method. This method also removes the point information object (if any) that is associated with the data item.

Note

A method is also available to remove all the data items from a given data set at the same time: IlvChartDataSet::removePointsAndInfo.

Modifications Made at the Chart Data Object Level

The following types of modifications can be made to a chart data object:

  • A new data set can be added to a chart data object.

This can be done by using one of the following methods:

setDataSet

addDataSet

insertDataSet

Note

A method is also available to set several data sets on a given chart data object at the same time: setDataSets.

  • An existing data set in a chart data object can be replaced by another data set.

This can be done by using one of the following methods:

setDataSet sets the data set stored at a given index in a chart data object. If a data set already exists at this index, it is replaced by the new one.

replaceDataSet replaces a given data set by a new one.

  • A data set can be removed from a chart data object.

This can be done by using the removeDataSet method.

Note

A method is also available to remove all the data sets from a given chart data object at the same time: removeDataSets.