Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Invient Charts - removeAllPoints doesn't seem to fully work

Arik Kfir
10 years ago Feb 01, 2012 1:39pm

Hi,

First - excellent work! Invient Charts is amazing!

I have a problem though: I have a spline chart which I am updating in a background thread. As long as I'm just adding points to the series, everything works great. However, when I want to remove all existing points from the series (via 'removeAllPoints' method), and add new points, the old points are still visible in the chart.

Here is a how I create the chart:

InvientChart chart = new InvientChart( new InvientChartsConfig() );
chart.getConfig().getTitle().setText( title );
chart.getConfig().getGeneralChartConfig().setSpacing( new Spacing( 30, 30, 30, 30 ) );
chart.getConfig().getGeneralChartConfig().setShadow( true );
chart.setSizeFull();
chart.setHeight( "500px" );
chart.getConfig().getGeneralChartConfig().setShadow( false );

InvientChartsConfig.DateTimeAxis xaxis = new InvientChartsConfig.DateTimeAxis();
xaxis.setShowFirstLabel( false );
chart.getConfig().addXAxes( xaxis );

InvientChartsConfig.NumberYAxis yaxis = new InvientChartsConfig.NumberYAxis();
yaxis.setTitle( new InvientChartsConfig.AxisBase.AxisTitle( "" ) );
chart.getConfig().addYAxes( yaxis );
yaxis.setMin( 0.0 );

DateTimeSeries series = new DateTimeSeries( "Used", InvientCharts.SeriesType.SPLINE, new InvientChartsConfig.SeriesConfig(), true );
chart.addSeries( series );

And that's what I'm doing in the background thread:

synchronized(getApplication()) {
    //
    // if the user selected a different data set in the combo-box, remove data from the previous data-set
    //  
    InvientCharts.DateTimeSeries s = ( InvientCharts.DateTimeSeries ) chart.getSeries( "Used" );
    if( userSelectedDifferentDataSet ) { 
        s.removeAllPoints();
    }

    //
    // add new point from the correct data-set (if user changed selection, previous data has been removed by code-section above)
    //
    s.addPoint( new InvientCharts.DateTimePoint( s, new Date(), newPointValue ), true );
}

Any help is appreciated - thanks!

Last updated on Feb, 1st 2012
Peter B
9 years ago Apr 16, 2012 11:37am