Example usage for org.jfree.chart.plot XYPlot getRangeAxis

List of usage examples for org.jfree.chart.plot XYPlot getRangeAxis

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getRangeAxis.

Prototype

public ValueAxis getRangeAxis() 

Source Link

Document

Returns the range axis for the plot.

Usage

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PaintScaleFactory.java

public static ValueAxis getPaintScaleAxis(double lower, double upper, String label) {
    // return a simple axis for the scale
    double inc = (upper - lower) / maxDivisions;

    final XYSeries s1 = new XYSeries("Series 1");

    for (int i = 0; i < maxDivisions; i++) {
        s1.add(i, i * inc);//from   w w w  . j a  v a2s .  co m
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(s1);

    JFreeChart chart = ChartFactory.createXYLineChart("Axis Demo", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, false);

    final XYPlot plot = chart.getXYPlot();
    final NumberAxis domainAxis = new NumberAxis("xish");
    final NumberAxis rangeAxis = new NumberAxis(label);
    plot.setDomainAxis(domainAxis);
    plot.setRangeAxis(rangeAxis);
    return plot.getRangeAxis();
}

From source file:org.matsim.contrib.dvrp.util.chart.RouteChartUtils.java

public static JFreeChart chartRoutes(List<? extends Vehicle> vehicles) {
    CoordDataset lData = new CoordDataset();

    for (int i = 0; i < vehicles.size(); i++) {
        Schedule<?> schedule = vehicles.get(i).getSchedule();
        lData.addSeries(Integer.toString(i), LinkSources.createLinkSource(schedule));
    }/*ww  w.  ja  va  2 s  .c  o m*/

    JFreeChart chart = ChartFactory.createXYLineChart("Routes", "X", "Y", lData, PlotOrientation.VERTICAL, true,
            true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setBackgroundPaint(Color.white);

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(false);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesItemLabelsVisible(0, true);

    renderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() {
        public String generateLabel(XYDataset dataset, int series, int item) {
            return ((CoordDataset) dataset).getText(series, item);
        }
    });

    for (int i = 1; i <= vehicles.size(); i++) {
        renderer.setSeriesShapesVisible(i, true);
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesItemLabelsVisible(i, true);
    }

    return chart;
}

From source file:org.matsim.contrib.dvrp.util.chart.RouteCharts.java

public static JFreeChart chartRoutes(Collection<? extends Vehicle> vehicles) {
    CoordDataset lData = new CoordDataset();
    int i = 0;/* w  w w  .j  av a 2  s . c om*/
    for (Vehicle v : vehicles) {
        Schedule schedule = v.getSchedule();
        lData.addSeries(Integer.toString(i++), ScheduleCoordSources.createCoordSource(schedule));
    }

    JFreeChart chart = ChartFactory.createXYLineChart("Routes", "X", "Y", lData, PlotOrientation.VERTICAL, true,
            true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setBackgroundPaint(Color.white);

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(false);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesItemLabelsVisible(0, true);

    renderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() {
        public String generateLabel(XYDataset dataset, int series, int item) {
            return ((CoordDataset) dataset).getText(series, item);
        }
    });

    for (int j = 1; j <= vehicles.size(); j++) {
        renderer.setSeriesShapesVisible(j, true);
        renderer.setSeriesLinesVisible(j, true);
        renderer.setSeriesItemLabelsVisible(j, true);
    }

    return chart;
}

From source file:org.jfree.chart.demo.AnnotationDemo1.java

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart(null, "Age in Months", "Weight (kg)", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    TextTitle texttitle = new TextTitle("Growth Charts: United States", new Font("SansSerif", 1, 14));
    TextTitle texttitle1 = new TextTitle("Weight-for-age percentiles: boys, birth to 36 months",
            new Font("SansSerif", 0, 11));
    jfreechart.addSubtitle(texttitle);/*from w ww  .  ja  v  a2  s  .  c  o  m*/
    jfreechart.addSubtitle(texttitle1);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setUpperMargin(0.12D);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setAutoRangeIncludesZero(false);
    XYTextAnnotation xytextannotation = null;
    Font font = new Font("SansSerif", 0, 9);
    xytextannotation = new XYTextAnnotation("3rd", 36.5D, 11.76D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("5th", 36.5D, 12.039999999999999D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("10th", 36.5D, 12.493D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("25th", 36.5D, 13.313000000000001D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("50th", 36.5D, 14.33D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("75th", 36.5D, 15.478D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("90th", 36.5D, 16.641999999999999D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("95th", 36.5D, 17.408000000000001D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    xytextannotation = new XYTextAnnotation("97th", 36.5D, 17.936D);
    xytextannotation.setFont(font);
    xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xyplot.addAnnotation(xytextannotation);
    return jfreechart;
}

From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart2.java

public static JFreeChart createChart(DataItems nor, DataItems abnor, String title, String protocol1,
        String protocol2) {/*from w w  w  .  j av  a2  s  . c o m*/
    // ?
    XYDataset xydataset1 = TimeSeriesChart1.createNormalDataset(nor, protocol1);
    JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "", "", xydataset1);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();

    XYLineAndShapeRenderer xylineandshaperenderer1 = (XYLineAndShapeRenderer) xyplot.getRenderer();
    // ??1?1

    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 6D, 6D);
    // ???

    // ??
    xylineandshaperenderer1.setSeriesLinesVisible(0, true);
    xylineandshaperenderer1.setBaseShapesVisible(false);
    xylineandshaperenderer1.setSeriesShape(0, double1);
    xylineandshaperenderer1.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer1.setSeriesFillPaint(0, Color.blue);
    xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.blue);
    xylineandshaperenderer1.setSeriesStroke(0, new BasicStroke(0.5F));

    // ?
    XYDataset xydataset2 = TimeSeriesChart1.createNormalDataset(abnor, protocol2);
    /*      XYTextAnnotation localXYTextAnnotation = new XYTextAnnotation("aa",10,
    Double.parseDouble(abnor.getElementAt(10).getData()));
          xyplot.addAnnotation(localXYTextAnnotation);*/
    XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer();
    int datasetcount = xyplot.getDatasetCount();
    xyplot.setDataset(datasetcount, xydataset2);
    xyplot.setRenderer(datasetcount, xylineandshaperenderer2);
    /*      System.out.println("DatasetCount="+xyplot.getDatasetCount());
                  
          for(int c=0;c<xyplot.getDatasetCount();c++){
             System.out.println("DatasetSeriesCount="+xyplot.getDataset(c).getSeriesCount());
             System.out.println("Dataset["+c+"]="+xyplot.getDataset(c).getSeriesKey(0));
          }*/

    /*   // ??? 
       xylineandshaperenderer2.setBaseShapesVisible(false);
       // ??
       xylineandshaperenderer2.setSeriesLinesVisible(0, true);
       xylineandshaperenderer2.setSeriesShape(0, double1);
       // 
       xylineandshaperenderer2.setSeriesPaint(0, Color.green);
       xylineandshaperenderer2.setSeriesFillPaint(0, Color.green);
       xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green);
            
       xylineandshaperenderer2.setUseFillPaint(true);
       xylineandshaperenderer2
    .setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
       xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F));
               
    */
    xylineandshaperenderer2.setSeriesLinesVisible(0, true);
    xylineandshaperenderer2.setBaseShapesVisible(false);
    xylineandshaperenderer2.setSeriesShape(0, double1);
    xylineandshaperenderer2.setSeriesPaint(0, Color.GREEN);
    xylineandshaperenderer2.setSeriesFillPaint(0, Color.GREEN);
    xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green);
    xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F));
    jfreechart.getLegend().setVisible(true);
    return jfreechart;

}

From source file:org.matsim.contrib.dvrp.util.chart.RouteChartUtils.java

public static JFreeChart chartRoutesByStatus(List<? extends Vehicle> vehicles) {
    CoordDataset nData = new CoordDataset();

    for (int i = 0; i < vehicles.size(); i++) {
        Schedule<?> schedule = vehicles.get(i).getSchedule();
        Map<TaskStatus, CoordSource> vsByStatus = createLinkSourceByStatus(schedule);
        nData.addSeries(i + "-PR", vsByStatus.get(TaskStatus.PERFORMED));
        nData.addSeries(i + "-ST", vsByStatus.get(TaskStatus.STARTED));
        nData.addSeries(i + "-PL", vsByStatus.get(TaskStatus.PLANNED));
    }/*from  w  w  w  .  j ava 2  s.  c  o m*/

    JFreeChart chart = ChartFactory.createXYLineChart("Routes", "X", "Y", nData, PlotOrientation.VERTICAL,
            false, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setBackgroundPaint(Color.white);

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(false);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesItemLabelsVisible(0, true);

    renderer.setBaseItemLabelGenerator(new LabelGenerator());

    Paint[] paints = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE;
    Shape[] shapes = DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE;

    for (int i = 0; i < vehicles.size(); i++) {
        int s = 3 * i;

        renderer.setSeriesItemLabelsVisible(s + 1, true);
        renderer.setSeriesItemLabelsVisible(s + 2, true);
        renderer.setSeriesItemLabelsVisible(s + 3, true);

        renderer.setSeriesShapesVisible(s + 1, true);
        renderer.setSeriesShapesVisible(s + 2, true);
        renderer.setSeriesShapesVisible(s + 3, true);

        renderer.setSeriesLinesVisible(s + 1, true);
        renderer.setSeriesLinesVisible(s + 2, true);
        renderer.setSeriesLinesVisible(s + 3, true);

        renderer.setSeriesPaint(s + 1, paints[(i + 1) % paints.length]);
        renderer.setSeriesPaint(s + 2, paints[(i + 1) % paints.length]);
        renderer.setSeriesPaint(s + 3, paints[(i + 1) % paints.length]);

        renderer.setSeriesShape(s + 1, shapes[(i + 1) % shapes.length]);
        renderer.setSeriesShape(s + 2, shapes[(i + 1) % shapes.length]);
        renderer.setSeriesShape(s + 3, shapes[(i + 1) % shapes.length]);

        renderer.setSeriesStroke(s + 2, new BasicStroke(3));
        renderer.setSeriesStroke(s + 3, new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1,
                new float[] { 5f, 5f }, 0));
    }

    return chart;
}

From source file:org.matsim.contrib.dvrp.util.chart.RouteCharts.java

public static JFreeChart chartRoutesByStatus(List<? extends Vehicle> vehicles) {
    CoordDataset nData = new CoordDataset();

    for (int i = 0; i < vehicles.size(); i++) {
        Schedule schedule = vehicles.get(i).getSchedule();
        Map<TaskStatus, CoordSource> vsByStatus = createLinkSourceByStatus(schedule);
        nData.addSeries(i + "-PR", vsByStatus.get(TaskStatus.PERFORMED));
        nData.addSeries(i + "-ST", vsByStatus.get(TaskStatus.STARTED));
        nData.addSeries(i + "-PL", vsByStatus.get(TaskStatus.PLANNED));
    }/*  www. j  av  a  2s .com*/

    JFreeChart chart = ChartFactory.createXYLineChart("Routes", "X", "Y", nData, PlotOrientation.VERTICAL,
            false, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setBackgroundPaint(Color.white);

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(false);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesItemLabelsVisible(0, true);

    renderer.setBaseItemLabelGenerator(new LabelGenerator());

    Paint[] paints = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE;
    Shape[] shapes = DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE;

    for (int i = 0; i < vehicles.size(); i++) {
        int s = 3 * i;

        renderer.setSeriesItemLabelsVisible(s + 1, true);
        renderer.setSeriesItemLabelsVisible(s + 2, true);
        renderer.setSeriesItemLabelsVisible(s + 3, true);

        renderer.setSeriesShapesVisible(s + 1, true);
        renderer.setSeriesShapesVisible(s + 2, true);
        renderer.setSeriesShapesVisible(s + 3, true);

        renderer.setSeriesLinesVisible(s + 1, true);
        renderer.setSeriesLinesVisible(s + 2, true);
        renderer.setSeriesLinesVisible(s + 3, true);

        renderer.setSeriesPaint(s + 1, paints[(i + 1) % paints.length]);
        renderer.setSeriesPaint(s + 2, paints[(i + 1) % paints.length]);
        renderer.setSeriesPaint(s + 3, paints[(i + 1) % paints.length]);

        renderer.setSeriesShape(s + 1, shapes[(i + 1) % shapes.length]);
        renderer.setSeriesShape(s + 2, shapes[(i + 1) % shapes.length]);
        renderer.setSeriesShape(s + 3, shapes[(i + 1) % shapes.length]);

        renderer.setSeriesStroke(s + 2, new BasicStroke(3));
        renderer.setSeriesStroke(s + 3, new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1,
                new float[] { 5f, 5f }, 0));
    }

    return chart;
}

From source file:org.jfree.chart.demo.BubbleChartDemo1.java

private static JFreeChart createChart(XYZDataset xyzdataset) {
    JFreeChart jfreechart = ChartFactory.createBubbleChart("Bubble Chart Demo 1", "X", "Y", xyzdataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setForegroundAlpha(0.65F);/*from w  w w . j a  va 2 s .  c om*/
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.blue);
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setLowerMargin(0.14999999999999999D);
    numberaxis.setUpperMargin(0.14999999999999999D);
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setLowerMargin(0.14999999999999999D);
    numberaxis1.setUpperMargin(0.14999999999999999D);
    return jfreechart;
}

From source file:org.jax.maanova.plot.PlotUtil.java

/**
 * Convert from graph coordinates to Java2D coordinates
 * @param plot//from w w  w  .ja  v  a 2  s.  c o  m
 *          the plot to use
 * @param renderingInfo
 *          the rendering info to use
 * @param graphX
 *          the graph X position to convert
 * @param graphY
 *          the graph Y position to convert
 * @return
 *          the point in Java2D coordinate space
 */
public static Point2D toJava2DCoordinates(XYPlot plot, ChartRenderingInfo renderingInfo, double graphX,
        double graphY) {
    final Rectangle2D dataArea = renderingInfo.getPlotInfo().getDataArea();

    final double java2DX = plot.getDomainAxis().valueToJava2D(graphX, dataArea, plot.getDomainAxisEdge());
    final double java2DY = plot.getRangeAxis().valueToJava2D(graphY, dataArea, plot.getRangeAxisEdge());

    return new Point2D.Double(java2DX, java2DY);
}

From source file:cv.mikusher.freechart.BubbleChart.java

private static JFreeChart createChart(XYZDataset xyzdataset) {
    JFreeChart jfreechart = ChartFactory.createBubbleChart("AGE vs WEIGHT vs WORK", "Weight", "AGE", xyzdataset,
            PlotOrientation.HORIZONTAL, true, true, false);

    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setForegroundAlpha(0.65F);/*w w  w  . jav a2  s .c o  m*/
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.blue);
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setLowerMargin(0.2);
    numberaxis.setUpperMargin(0.5);
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setLowerMargin(0.8);
    numberaxis1.setUpperMargin(0.9);

    return jfreechart;
}