Unexpected behavior when data (or filter) is updated (how to remove graphs from a chart.)

Hello,
I have a problem when I build a chart using ListDataProvider as a data provider.
When I update the ListDataProvider instance
I can’t remove graphs from charts.

I have attached an example.[testDynamicChart.zip|attachment]

(upload://gE4AQ0kczQbgPnms3ksLSuyxgFX.zip) (321.1 KB)

Hello,

it seems that there is no link to download your attached project. Please, try to reattach it.

1 Like

testDynamicChart.zip (321.1 KB)

link to download project test:
https://www.cuba-platform.com/discuss/uploads/short-url/gE4AQ0kczQbgPnms3ksLSuyxgFX.zip

1 Like

Hi!

You can remove Graphs like this:

List<Graph> graphs = testChart.getGraphs();
if (CollectionUtils.isNotEmpty(graphs)) {
    graphs.clear();
}

I think you can add it to the beginning of filterData() method.

Hi, thanks for the help.
But on the screen the graph still with the lines of the previous print query.

Could you clarify in more details, because with code above it works like this:
dynamicgrapgs

full method code
public void filterData() {
    List<Graph> graphs = testChart.getGraphs();
    if (CollectionUtils.isNotEmpty(graphs)) {
        graphs.clear();
    }

    ListDataProvider dataProvider = new ListDataProvider();
    testChart.setDataProvider(dataProvider);

    for (int i = 0; i < 5; i++) {
        String date = "05/0" + (i + 1) + "/2019";
        BigDecimal sales = generateRandomBigDecimalFromRange(
                new BigDecimal(20.90).setScale(2, BigDecimal.ROUND_HALF_UP),
                new BigDecimal(35.90).setScale(2, BigDecimal.ROUND_HALF_UP)
        );
        BigDecimal spending = generateRandomBigDecimalFromRange(
                new BigDecimal(-1.21).setScale(2, BigDecimal.ROUND_HALF_UP),
                new BigDecimal(21.28).setScale(2, BigDecimal.ROUND_HALF_UP)
        );
        BigDecimal profit = sales.subtract(spending);
        dataProvider.addItem(MapDataItem.of("date", date,
                "sales", sales,
                "spending", spending,
                "profit", profit));
    }

    String currProdCode = null;
    Graph sales = new Graph()
            .setId("sales")
            .setStackable(true)
            .setType(GraphType.LINE)
            .setBullet(BulletType.ROUND)
            .setBalloonText("sales [[sales]]")
            .setLineThickness(3)
            .setTitle("sales")
            .setValueField("sales");
    Graph spending = new Graph()
            .setId("spending")
            .setStackable(true)
            .setType(GraphType.LINE)
            .setBullet(BulletType.ROUND)
            .setBalloonText("spending [[spending]]")
            .setLineThickness(3)
            .setTitle("spending")
            .setValueField("spending");
    Graph profit = new Graph()
            .setId("profit")
            .setStackable(true)
            .setType(GraphType.LINE)
            .setBullet(BulletType.ROUND)
            .setBalloonText("profit [[profit]]")
            .setLineThickness(3)
            .setTitle("profit")
            .setValueField("profit");
    testChart.addGraphs(sales, spending, profit);
    testChart.repaint();
}