DHTMLX Docs & Samples Explorer

Adding and Deleting

With DhtmlxChart you can add and delete chart elements dynamically.

Let's consider it in details.

Adding

Initially data are loaded by load() or parse() method.

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

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

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

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

Deleting

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

     chart.remove(id);

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

     chart.clearAll();

Getting item id

If item id is unknown, you can use the idByIndex() method:

     var id = chart.idByIndex(10);

Moreover, there are first(), last(), next() and previous() methods.

An example that uses mentioned above methods you can see here.