Adding and Deleting Items

With dhtmlxChart, you can add and delete chart elements dynamically. Let's consider this possibility in details.

Adding Items

Initially, data are loaded by the load() or parse() methods.

But if you want to add additional data objects, you should use the add() method. The method requires a data object with necessary properties:

myChart.add({
    year: 2010,
    sales: 8.9 
});

You may also define an item index in the second parameter:

myChart.add({
    year: 2010,
    sales: 8.9 
},10);

Deleting Items

The remove() method deletes an item by its id:

myChart.remove(id);

To delete all items from a chart, you can use the clearAll() method:

myChart.clearAll();

Getting Item Id

If an item id is unknown, you can use the idByIndex() method to get it:

var id = myChart.idByIndex(10);

Moreover, there are first(), last(), next() and previous() methods for getting IDs of the corresponding items.

Related sample:  Adding

Back to top