Updating a Histogram?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
arwelbath
Posts: 24
Joined: Fri Aug 10, 2007 12:37 pm

Updating a Histogram?

Post by arwelbath » Mon Feb 02, 2009 1:13 pm

Hi,
I am plotting a simple Histogram, and what I would like to do is to update the graph as new data is obtained. The updates are never frequent, and so there's no need for any flashy, super-fast dynamic stuff.

At the moment I'm creating a dataset....

Code: Select all

    public IntervalXYDataset makeIntervalXYDataset() {
        HistogramDataset dataset = new HistogramDataset();
        return dataset;
    }
..adding a seried to it (dataset.addSeries(......) ), then using this to make a graph...

Code: Select all

    public ChartPanel MakeErrorsHistogramChart(IntervalXYDataset dataset) {
    
         JFreeChart chart = ChartFactory.createHistogram(
             "",
             null,
             null,
             dataset,
             PlotOrientation.VERTICAL,
             true,
             false,
             false
         );         
         chart.getXYPlot().setForegroundAlpha(0.75f);
         final ChartPanel panel = new ChartPanel(chart);
         return panel;
    };
Now, to update the graph, I'd be happy with just clearing the initial series, and adding another one, but there isn't any kind of 'removeSeries' method for HistogramDataset.

So, does anyone know of a way to update a Histogram, other than to make a completely new graph?
Cheers,
Arwel

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Mon Feb 02, 2009 9:56 pm

There is another implementation that will support the updating you want, I think. Try SimpleHistogramDataset instead of HistogramDataset.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

arwelbath
Posts: 24
Joined: Fri Aug 10, 2007 12:37 pm

Post by arwelbath » Tue Feb 03, 2009 3:38 pm

Thanks David. I'll give it a go...

Locked