java - Enabling/Disabling drawing of a JFreeChart -
i have chart created shown below, , adding values timeseries (in different location in program). chartpanel contained within jtabbedpane, , not redraw chart unless it's tab being displayed. there way me signal rendering should not occur when new data comes timeseries unless tab 1 being shown? i'm guessing there call signals data has been updated , new rendering needed, want intercept call , nothing if tab not being shown, let call through if tab being shown, , call once manually when user switches tab. isn't major issue 1 chartpanel in background, have few on different tabs , it's starting eat cpu nasty update 4-5 charts constantly.
saccuracy = new timeseries("a"); timeseriescollection dataset = new timeseriescollection(saccuracy); jfreechart c = chartfactory.createtimeserieschart("accuracy", "", "percent", dataset, false, false, false); chartpanel cp = new chartpanel(c);
i've faced same problem whereby jfreechart api clunky , repaints entire chart whenever single datapoint added resulting in large rendering overhead.
the way i've solved implement own underlying model (e.g. xydataset implementation) aware of when chart containing being displayed, , only propagate events when chart visible - if chart not visible model should defer firing of events until later; e.g.
public class myxydataset extends abstractxydataset { private boolean shown; private boolean pendingevent; /** * called when chart containing dataset being displayed * (e.g. hook selection listener listens tab selection events). */ public void setshown(boolean shown) { this.shown = shown; if (this.shown && this.pendingevent) { this.pendingevent = false; firedatasetchanged(); } } public void adddatapoint(double x, double y) { // todo: add underlying collection. if (this.shown) { // chart displayed propagate event immediately. firedatasetchanged(); } else { // chart hidden delay firing of event record need fire one. this.pendingevent = true; } } }
Comments
Post a Comment