java - Add horizontal scroll to JFreeChart -


this question has answer here:

as title says: how can add horizontal scrollbar candlestick chart created jfreechart? want user able scroll horizontally through chart when zoomed in. right zooming in works can't move left or right. tried putting chartpanel jscrollpane that's chartpanel, not chart itself. custom chartpanel constructor:

public mychartpanel(jfreechart chart) {     super(chart);     linedrawingcontrollers =new eventlistenerlist();     this.setmousezoomable(false);     this.addmouselistener(mousehandler);     this.addmousemotionlistener(mousehandler);     this.setpopupmenu(null);     this.linepopupmenu=new jpopupmenu();     linepopupmenulistener=new linepopupmenulistener(); } 

my custom jpanel create chart , chartpanel , put chartpanel inside jscrollpane:

public mycandlestickchart() {     ohlcseries = new ohlcseries("test data");     ohlcseriescollection = new ohlcseriescollection();     ohlcseriescollection.addseries(ohlcseries);     ohlcseries=ohlcseriescollection.getseries(0);      chart= chartfactory.createcandlestickchart("default chart", "time", "value", ohlcseriescollection, true);     chart.getxyplot().setorientation(plotorientation.vertical);     chartpanel=new mychartpanel(chart);     chartpanel.setdisplaytooltips(false);     jscrollpane=new jscrollpane(chartpanel);     jscrollpane.sethorizontalscrollbarpolicy(jscrollpane.horizontal_scrollbar_always);     add(jscrollpane);     add(tooltippanel); } 

then add mycandlestickchart jpanel main application frame:

mycandlestickchart=new mycandlestickchart(); applicationframe.add(mycandlestickchart, borderlayout.center); 

you can move left , right if call setdomainpannable(true) on xyplot. looks chart.getxyplot().setdomainpannable(true) in case. there method setrangepannable(boolean pannable) panning in range direction respectively. when used long time ago, resulted in being able move chart dragging middle mouse button. don't know behavior in case nowadays :) method place start if have no other ideas. may if inside source code there, can create own custom scrollbar same functionality.

upd.: alternatively, can increase/decrease size of chartpanel on mouse wheel or whatever without using zooming functionality of jfreechart. jscrollpane job. fine , easier if want scale globally. if want nice zooming of user selected area, customizing of jfreechart's "panning".

upd2.: might wrong middle mouse button. ctrl + mouse dragging in link provided @trashgod


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -