Add Graph to StockChart

I want to dynamically add a moving average to a StockChart.

I’m trying to combine what i found here:

https://www.amcharts.com/docs/v3/tutorials/moving-average-indicators-for-stock-chart/
https://demo10.cuba-platform.com/sampler/#main/6/sample?id=dynamically-creating-graphs-chart

I have set up a stockchart which displays the price on panel 0 and the volume on panel 1. The data comes from a CollectionCntainer pricesDc. It’s displaying fine so far.

Now I would like to add a graph (or more) with moving averages on panel 0.

This is how far i got, without success:

public void addMovingAverage() {
    DataProvider dp = stockChart.getDataSets().get(0).getDataProvider();

    StockGraph sg = new StockGraph();
    sg.setId("ma");
    sg.setLineAlpha(1.0);
    sg.setValueField("mav");

    stockChart.getPanels().get(0).addStockGraphs(sg);

    //add some test data
    dp.addItem(getDataItem(100));
    dp.addItem(getDataItem(200));
    dp.addItem(getDataItem(150));

    stockChart.repaint();
}

private DataItem getDataItem(double value) {
    MapDataItem dataItem = new MapDataItem();
    dataItem.add("mav", value);
    return dataItem;
}

The line:

dp.addItem(getDataItem(100));

throws an:
UnsupportedOperationException: Use CollectionContainer for changing data items of ContainerDataProvider

I think I cannot just add fields to the CollectionContaier because it contains Entities.

EDIT: I just found a “cheap” workaround which works for now: to add a transient field to my entity and set the values in my screen controller. But it would be nice to know how to do it “correctly”.