oddity w/ bufferedimage chart and firedatasetchanged()

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Andrew Foss
Posts: 36
Joined: Thu Apr 12, 2007 6:54 am

oddity w/ bufferedimage chart and firedatasetchanged()

Post by Andrew Foss » Wed Nov 07, 2007 4:26 am

I'm doing a progressive draw of the chart and it's a pretty complex chart, it's slow but it works.

The dataset has a scaler factor which scales the getY result and does a firedatasetchanged().

I set a chartprogresslistener for the DRAWING_FINISHED event and set the next scaler, until the dataset is returning full normal values.

When I create the chart w/ bufferedimage true, then the chartprogresslistener no longer get's DRAWING_FINISHED events, as a result of the firedatasetchanged().

any chance this is a bug or am I missing something w/ the drawing and buffered image?

thanks,
andrew

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 » Wed Nov 07, 2007 11:51 am

Sounds like a bug - any hints to reproduce? A self-contained demo would be a great help.
David Gilbert
JFreeChart Project Leader

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

Andrew Foss
Posts: 36
Joined: Thu Apr 12, 2007 6:54 am

Post by Andrew Foss » Wed Nov 07, 2007 12:31 pm

Definitely confirmed that iterative fireDatasetChanged is only resulting in one draw of the chart when the chartpanel is useBuffer true

if useBuffer false, fireDatasetChanged triggers all 10 iterative redraws just fine.

I'm stumped.

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 » Wed Nov 07, 2007 12:39 pm

In the paintComponent() method in the ChartPanel class, find this block of code:

Code: Select all

            // do we need to redraw the buffer?
            if (this.refreshBuffer) {

                Rectangle2D bufferArea = new Rectangle2D.Double(
                        0, 0, this.chartBufferWidth, this.chartBufferHeight);

                Graphics2D bufferG2 = (Graphics2D) 
                        this.chartBuffer.getGraphics();
                if (clearBuffer) {
                    bufferG2.clearRect(0, 0, this.chartBufferWidth, 
                            this.chartBufferHeight);
                }
                if (scale) {
                    AffineTransform saved = bufferG2.getTransform();
                    AffineTransform st = AffineTransform.getScaleInstance(
                            this.scaleX, this.scaleY);
                    bufferG2.transform(st);
                    this.chart.draw(bufferG2, chartArea, this.anchor, 
                            this.info);
                    bufferG2.setTransform(saved);
                }
                else {
                    this.chart.draw(bufferG2, bufferArea, this.anchor, 
                            this.info);
                }

                this.refreshBuffer = false;

            }
Try moving the 'this.refreshBuffer = false' up to the start of the block. I suspect your code is is triggering a ChartChangeEvent (which sets refreshBuffer to true) at the previous line (this.chart.draw(...)), and then we're resetting the flag which prevents any further chart refresh.
David Gilbert
JFreeChart Project Leader

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

Andrew Foss
Posts: 36
Joined: Thu Apr 12, 2007 6:54 am

Post by Andrew Foss » Wed Nov 07, 2007 2:27 pm

Dave,

that did it, thank you very much!

I built a test chart to show it, but can't figure out how to attach, just as well, I think this is the right track, I poured over this area trying to understand, but it escaped me.

[/img]

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 » Wed Nov 07, 2007 2:50 pm

I committed the fix to Subversion for inclusion in the 1.0.7 release.
David Gilbert
JFreeChart Project Leader

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

Locked