java - JFreeChart CombinedXYPlot with Time Series -


i able plot date against price, date on x-axis , price shown in y-axis.

later want plot volume-date graph in same chart, i've used combinedrangexyplot purpose. common data here both graphs date. ideally want graphs displayed 1 below other (horizontal orientation) common x-axis being date , each having own y-axis, 1 being price , other being volume

but issue facing is, when orientation horizontal dates displayed in y-axis graphs appeared tilted @ 90 degree angle. if orientation vertical, x-axis consists of dates , y-axis handles both price , volume. since price movement in 100's , volume movement in millions, not able spot price movements in graph. ideally want x-axis common both graphs containing dates when orientation horizontal, require 2 y-axis values 1 each graph.

    final xyplot priceplot = new xyplot(dataset, new dateaxis("date"), null, new standardxyitemrenderer());     numberaxis numberaxis = (numberaxis)priceplot.getrangeaxis();     numberaxis.setrange(new range(minprice,maxprice));      final xyplot volumeplot = new xyplot(volumedataset, new dateaxis("date"), null, new xybarrenderer(0.20));     numberaxis numberaxisvolume = (numberaxis)volumeplot.getrangeaxis();     numberaxisvolume.setrange(new range(minvolume,maxvolume));      // create parent plot...     final combinedrangexyplot plot = new combinedrangexyplot();      // add subplots...     plot.add(priceplot, 1);     plot.add(volumeplot, 1);     plot.setorientation(plotorientation.horizontal); 

is possible? advice on how can achieved?

i think used wrong plot. subplots in "combinedrangexyplot" share common y axis, subplots in "combineddomainxyplot" share common x axis. requirement needs combineddomainxyplot. following simplified example modified jfreechart demo. hope can help.

/* ===========================================================  * jfreechart : free chart library java(tm) platform  * ===========================================================  *  * (c) copyright 2000-2004, object refinery limited , contributors.  *  * project info:  http://www.jfree.org/jfreechart/index.html  *  * library free software; can redistribute and/or modify under terms  * of gnu lesser general public license published free software foundation;  * either version 2.1 of license, or (at option) later version.  *  * library distributed in hope useful, without warranty;  * without implied warranty of merchantability or fitness particular purpose.  * see gnu lesser general public license more details.  *  * should have received copy of gnu lesser general public license along  * library; if not, write free software foundation, inc., 59 temple place, suite 330,  * boston, ma 02111-1307, usa.  *  * [java trademark or registered trademark of sun microsystems, inc.   * in united states , other countries.]  *  * ------------------------  * combinedxyplotdemo2.java  * ------------------------  * (c) copyright 2002-2004, object refinery limited.  *  * original author:  david gilbert (for object refinery limited).  * contributor(s):   -;  *  * $id $  *  * changes  * -------  * 23-apr-2002 : version 1 (dg);  * 23-may-2002 : renamed multiplotdemo --> combinedxyplotdemo (dg);  * 25-jun-2002 : removed unnecessary imports (dg);  * 10-oct-2002 : fixed errors reported checkstyle (dg);  * 25-feb-2004 : renamed xytooltipgenerator --> xyitemlabelgenerator (dg);  *  */  package testfreechart;  import java.util.date;  import org.jfree.chart.chartpanel; import org.jfree.chart.jfreechart; import org.jfree.chart.axis.axislocation; import org.jfree.chart.axis.dateaxis; import org.jfree.chart.axis.numberaxis; import org.jfree.chart.plot.combineddomainxyplot; import org.jfree.chart.plot.plotorientation; import org.jfree.chart.plot.xyplot; import org.jfree.chart.renderer.xy.standardxyitemrenderer; import org.jfree.chart.renderer.xy.xybarrenderer; import org.jfree.chart.renderer.xy.xyitemrenderer; import org.jfree.data.xy.defaultintervalxydataset; import org.jfree.data.xy.defaultxydataset; import org.jfree.data.xy.xybardataset; import org.jfree.ui.applicationframe; import org.jfree.ui.refineryutilities;  /**  * demonstration application showing how create combined chart.   * bar chart displayed on left, , line chart on right.  *  */ public class combinedxyplotdemo2 extends applicationframe {      /**      * constructs new demonstration application.      *      * @param title  frame title.      */     public combinedxyplotdemo2(final string title) {          super(title);         final jfreechart chart = createcombinedchart();         final chartpanel panel = new chartpanel(chart, true, true, true, false, true);         panel.setpreferredsize(new java.awt.dimension(500, 270));         setcontentpane(panel);      }      /**      * creates combined xyplot chart.      *      * @return combined chart.      */     private jfreechart createcombinedchart() {          // create subplot 1...         final xybardataset  data1 = createdataset1();         final xyitemrenderer renderer1 = new xybarrenderer(1.0);         final xyplot subplot1 = new xyplot(data1, null, new numberaxis("volume"),  renderer1);          // create subplot 2...         final defaultxydataset  data2 = createdataset2();         final xyitemrenderer renderer2 = new standardxyitemrenderer();         final xyplot subplot2 = new xyplot(data2, null, new numberaxis("price"),  renderer2);          // create parent plot...         final combineddomainxyplot plot = new combineddomainxyplot(new dateaxis("date"));          // add subplots...         plot.add(subplot1, 1);         plot.add(subplot2, 1);         plot.setorientation(plotorientation.vertical);          // return new chart containing overlaid plot...         return new jfreechart(             "combined  xy plot", jfreechart.default_title_font, plot, true         );      }      // ****************************************************************************     // * jfreechart developer guide                                               *     // * jfreechart developer guide, written david gilbert, available   *     // * purchase object refinery limited:                                *     // *                                                                          *     // * http://www.object-refinery.com/jfreechart/guide.html                     *     // *                                                                          *     // * sales used provide funding jfreechart project - please    *      // * support can continue developing free software.             *     // ****************************************************************************      /**      * creates sample dataset.      *      * @return series 1.      */     private xybardataset createdataset1() {          double []values={19642.3, 18253.5, 15352.3, 13532.0, 12635.3,                  13998.2,  11943.2,  16943.9,  17843.2,  16495.3,  17943.6, 18500.7,  19595.9};         double [][] data = new double[2][values.length];          int j=3;         for(int i=0; i< values.length; i++)         {             date dt = new date(2002, 3, j);             data[0][i] = dt.gettime();             data[1][i] = values[i];             j++;         }         defaultxydataset dataset = new defaultxydataset();         dataset.addseries("volume", data);          return new xybardataset(dataset, 50.0);     }       /**      * creates sample dataset.      *      * @return series 2.      */     private defaultxydataset createdataset2() {           double []values={42.3, 53.5, 52.3, 32.0, 35.3,                  98.2,  43.2,  43.9,  43.2,  95.3,  43.6, 10.7,  95.9};          double [][] data = new double[2][values.length];          int j=3;         for(int i=0; i< values.length; i++)         {             date dt = new date(2002, 3, j);             data[0][i] = dt.gettime();             data[1][i] = values[i];             j++;         }         defaultxydataset dataset = new defaultxydataset();         dataset.addseries("price", data);         return dataset;      }      /**      * starting point demonstration application.      *      * @param args  ignored.      */     public static void main(final string[] args) {          final combinedxyplotdemo2 demo = new combinedxyplotdemo2("combined xy plot demo");         demo.pack();         refineryutilities.centerframeonscreen(demo);     demo.setvisible(true);  } 

}


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -