[Charts] replacing chart idle time

Hi alll,

On replacing a chart with another one, there is a significant delay (up to 4 seconds), even if .setImmediate(true); is called.

How to overcome that?

Please find below complete case.

Ahmed

@SuppressWarnings("serial")
@Theme("vaadin2")
public class Vaadin2UI extends UI implements ChartClickListener {

    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = Vaadin2UI.class, widgetset = "com.example.vaadin2.widgetset.Vaadin2Widgetset")
    public static class Servlet extends VaadinServlet {
    }

    protected boolean barChart;
    protected Chart chart;

    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setImmediate(true);
        layout.setMargin(true);
        setContent(layout);
        
        initChart();
        chart.drawChart();
    }

    private void initChart() {
        VerticalLayout layout = (VerticalLayout) getContent();
        if (chart != null) {
            chart.removeChartClickListener(this);
            layout.removeComponent(chart);
        }
        chart = new Chart(barChart ? ChartType.BAR : ChartType.PIE);
        chart.setImmediate(true);
        chart.setSizeFull();
        chart.addChartClickListener(this);
        if (barChart) {
            setBarOptions();
        }
        else {
            setPieOptions();
        }
        layout.addComponent(chart);
    }

    private void setPieOptions() {
        Configuration conf = chart.getConfiguration();
        conf.disableCredits();
        conf.setTitle("");

        PlotOptionsPie plotOptions = new PlotOptionsPie();
        plotOptions.setAnimation(false);
        plotOptions.setEnableMouseTracking(false);
        conf.setPlotOptions(plotOptions);
        DataSeries series = new DataSeries();
        series.add(new DataSeriesItem("x1", 10));
        series.add(new DataSeriesItem("x2", 20));
        series.add(new DataSeriesItem("x3", 30));
        chart.getConfiguration().setSeries(series);
    }

    private void setBarOptions() {
        Configuration conf = chart.getConfiguration();
        conf.disableCredits();
        conf.setTitle("");
        Legend legend = new Legend();
        legend.setEnabled(false);
        conf.setLegend(legend);

        PlotOptionsBar plotOptions = new PlotOptionsBar();
        plotOptions.setAnimation(false);
        chart.getConfiguration().setPlotOptions(plotOptions);;

        DataSeries series = new DataSeries();
        series.add(new DataSeriesItem("x1", 10));
        series.add(new DataSeriesItem("x2", 20));
        series.add(new DataSeriesItem("x3", 30));
        chart.getConfiguration().setSeries(series);
    }

    /**
     * @see com.vaadin.addon.charts.ChartClickListener#onClick(com.vaadin.addon.charts.ChartClickEvent)
     */
    @Override
    public void onClick(ChartClickEvent event) {
        barChart = !barChart;
        initChart();
        chart.drawChart();
    }
}