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:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java

@Override
public void setUseYLabels(final IScope scope, final IExpression expval) {
    // if there is something to do to use custom X axis
    final XYPlot pp = (XYPlot) chart.getPlot();

    ((NumberAxis) pp.getRangeAxis()).setNumberFormatOverride(new NumberFormat() {

        @Override/*from  w ww  .j av a 2 s.  co m*/
        public StringBuffer format(final double number, final StringBuffer toAppendTo,
                final FieldPosition pos) {
            final int ind = chartdataset.YSeriesValues.indexOf(number);
            if (ind >= 0) {
                return new StringBuffer("" + chartdataset.Ycategories.get(ind));
            }
            return new StringBuffer("");

        }

        @Override
        public StringBuffer format(final long number, final StringBuffer toAppendTo, final FieldPosition pos) {
            return new StringBuffer("n" + number);
            // return new StringBuffer(String.format("%s", number));
        }

        @Override
        public Number parse(final String source, final ParsePosition parsePosition) {
            return null;
        }
    });

}

From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.tasks.ChromatogramViewLoaderWorker.java

private void configurePlot(XYPlot plot, RTUnit rtAxisUnit) {
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setNumberFormatOverride(new RTNumberFormatter(rtAxisUnit));
    domainAxis.setLabel("RT[" + rtAxisUnit.name().toLowerCase() + "]");
    plot.setRangeZeroBaselineVisible(true);
    plot.setDomainZeroBaselineVisible(false);
    domainAxis.setAutoRange(true);// w ww. jav  a2  s . c om
    domainAxis.setAutoRangeIncludesZero(false);
    ((NumberAxis) plot.getRangeAxis()).setAutoRange(true);
    ((NumberAxis) plot.getRangeAxis()).setAutoRangeIncludesZero(true);
    Logger.getLogger(getClass().getName()).info("Adding chart");
    plot.setBackgroundPaint(Color.WHITE);
}

From source file:com.mxgraph.examples.swing.chart.TimeSeriesChartDemo1.java

/**
 * Creates a chart./*from w ww  . j  ava  2 s  .co m*/
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
public static JFreeChart createChart(XYDataset dataset, String name) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(name, // title
            "Date", // x-axis label
            "Value", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
        renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator());
        renderer.setBaseItemLabelsVisible(true);
        // 
        renderer.setItemLabelsVisible(true);
        // 
        renderer.setBaseShapesVisible(true);
        // 
        renderer.setBaseShapesFilled(true);

        //  renderer.setLegendItemLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));

    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"/*"yyyy-MM-dd HH:mm:ss"*/));

    chart.getTitle().setFont(new Font("", Font.BOLD, 15));
    chart.getLegend().setItemFont(new Font("", Font.BOLD, 15));
    //
    plot.getRangeAxis().setLabelFont(new Font("", Font.BOLD, 15));
    //
    chart.getLegend().setItemFont(new Font("", Font.ITALIC, 15));
    //
    plot.getDomainAxis().setTickLabelFont(new Font("", 1, 15));
    //
    plot.getDomainAxis().setLabelFont(new Font("", 1, 12));

    return chart;

}

From source file:serverrobot.DynamicGraph.java

public JFreeChart createChart(XYDataset dataset, String pos, double minRange, double maxRange) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(pos, "Time (ms)", "Displacement", dataset, true,
            true, false);//from   www.  j  a va2  s  .  c  o  m
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(new Color(232, 232, 232));
    plot.setDomainGridlinePaint(Color.BLACK);
    plot.setRangeGridlinePaint(Color.BLACK);
    plot.getRenderer().setSeriesPaint(0, Color.BLUE);
    plot.getRenderer().setSeriesPaint(1, Color.RED);

    ValueAxis axis = plot.getDomainAxis();
    //axis.setAutoRange(true);
    axis.setFixedAutoRange(20000.0); // 60 seconds
    axis = plot.getRangeAxis();
    axis.setRange(minRange, maxRange);

    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:experiments.SimpleExample.java

public JFreeChart createChart() {
    XYSeries xyseries = new XYSeries("Fitness Line");
    xyseries.add(0.0D, 0.0D);/*from   ww w  .j a  va 2s.  co  m*/
    for (int i = 1; i <= fitlist.size(); i++) {
        xyseries.add(i, fitlist.get(i - 1));
    }
    XYSeriesCollection xyseriescollection = new XYSeriesCollection(); //?XYSeriesCollectionXYSeries  
    xyseriescollection.addSeries(xyseries);
    //?  
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Line Chart Demo", //      
            "Iteration", // categoryAxisLabel categoryX     
            "FitnessValue", // valueAxisLabelvalueY     
            xyseriescollection, // dataset     
            PlotOrientation.VERTICAL, true, // legend     
            false, // tooltips     
            false); // URLs     

    // CategoryPlot?????     
    XYPlot plot = jfreechart.getXYPlot();
    // ? ?     
    plot.setBackgroundAlpha(0.5f);
    plot.setForegroundAlpha(0.5f);
    //        XYPlot xyplot = jfreechart.getXYPlot();  
    //??  
    ValueAxis xx = plot.getDomainAxis();
    //??  
    xx.setAutoRange(true);
    //        xx.setRange(0.0, 2000);

    ValueAxis yy = plot.getRangeAxis();
    yy.setRange(600.0, 1000);

    return jfreechart;
}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates a XY bar chart./*from ww  w  . j a va 2  s  .com*/
 * 
 * @param title
 * @param categoryAxisLabel
 * @param valueAxisLabel
 * @param dataset
 * @param includeZero
 * @param shadow
 * @return
 */
public JFreeChart createXYBarChart(String title, String categoryAxisLabel, String valueAxisLabel,
        IntervalXYDataset dataset, boolean includeZero, boolean shadow) {
    JFreeChart chart = ChartFactory.createXYBarChart(title, categoryAxisLabel, false, valueAxisLabel, dataset,
            this.orientation, this.drawLegend, false, false);
    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);
    XYPlot plot = chart.getXYPlot();
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.025);
    domainAxis.setUpperMargin(0.025);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(includeZero);
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setShadowVisible(shadow);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesPaint(2, Color.green);
    renderer.setSeriesPaint(3, Color.darkGray);
    renderer.setSeriesPaint(4, Color.yellow);
    return chart;
}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates a line chart.//from   www .  j  av a  2  s  .  c  o  m
 * 
 * @param title
 * @param categoryAxisLabel
 *            (X-Axis label)
 * @param valueAxisLabel
 *            (Y-Axis label)
 * @param dataset
 * @param includeZero
 *            True when zero shall be included to the axis range.
 * @return JfreeChart instance.
 */
public JFreeChart createXYLineChart(String title, String categoryAxisLabel, String valueAxisLabel,
        XYDataset dataset, boolean includeZero, boolean drawShapes) {
    JFreeChart chart = ChartFactory.createXYLineChart(title, categoryAxisLabel, valueAxisLabel, dataset,
            this.orientation, this.drawLegend, false, false);
    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);
    XYPlot plot = chart.getXYPlot();
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.025);
    domainAxis.setUpperMargin(0.025);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(includeZero);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesPaint(2, Color.green);
    renderer.setSeriesPaint(3, Color.darkGray);
    renderer.setSeriesPaint(4, Color.yellow);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseShapesVisible(drawShapes);
    renderer.setBaseShapesFilled(true);
    return chart;
}

From source file:dbseer.gui.panel.DBSeerExplainChartPanel.java

@Override
public void mouseReleased(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON3) {
        displayPopupMenu(e.getX(), e.getY());
        return;/*from  w  w w . j  av a 2  s .  co  m*/
    }
    repaint();
    int smallX = Math.min(startX, endX);
    int smallY = Math.min(startY, endY);
    int bigX = Math.max(startX, endX);
    int bigY = Math.max(startY, endY);

    XYPlot plot = this.getChart().getXYPlot();
    Rectangle2D plotArea = this.getScreenDataArea();
    double chartSmallX = plot.getDomainAxis().java2DToValue(smallX, plotArea, plot.getDomainAxisEdge());
    double chartBigX = plot.getDomainAxis().java2DToValue(bigX, plotArea, plot.getDomainAxisEdge());
    double chartSmallY = plot.getRangeAxis().java2DToValue(smallY, plotArea, plot.getRangeAxisEdge());
    double chartBigY = plot.getRangeAxis().java2DToValue(bigY, plotArea, plot.getRangeAxisEdge());

    double minXValue = Math.min(chartSmallX, chartBigX);
    double maxXValue = Math.max(chartSmallX, chartBigX);
    double minYValue = Math.min(chartSmallY, chartBigY);
    double maxYValue = Math.max(chartSmallY, chartBigY);

    //testLog.append("Scanning: (" + smallX + ", " + smallY + "), (" + bigX + ", " + bigY + ")\n");
    //testLog.append("Scanning: X = [" + Math.min(chartSmallX, chartBigX) + ", " + Math.max(chartSmallX, chartBigX) + "]\n");
    //testLog.append("Scanning: Y = [" + Math.min(chartSmallY, chartBigY) + ", " + Math.max(chartSmallY, chartBigY) + "]\n");

    Set<XYItemEntity> foundItem = new HashSet<XYItemEntity>();

    XYDataset dataset = this.getChart().getXYPlot().getDataset();
    EntityCollection collection = this.getChartRenderingInfo().getEntityCollection();

    for (Object obj : collection.getEntities()) {
        if (obj instanceof XYItemEntity) {
            XYItemEntity entity = (XYItemEntity) obj;
            int series = entity.getSeriesIndex();
            int idx = entity.getItem();
            if (dataset.getX(series, idx).doubleValue() >= minXValue
                    && dataset.getX(series, idx).doubleValue() <= maxXValue
                    && dataset.getY(series, idx).doubleValue() >= minYValue
                    && dataset.getY(series, idx).doubleValue() <= maxYValue) {
                foundItem.add(entity);
            }
        }
    }

    //      for (int x = smallX; x <= bigX; ++x)
    //      {
    //         for (int y = smallY; y <= bigY; ++y)
    //         {
    //            ChartEntity entity = this.getEntityForPoint(x, y);
    //            if (entity instanceof XYItemEntity)
    //            {
    //               foundItem.add((XYItemEntity)entity);
    //            }
    //         }
    //      }

    selectedItems = foundItem;

    //      outlierRegion.clear();
    //      for (XYItemEntity entity : foundItem)
    //      {
    //         //testLog.append(entity.toString() + "\n");
    //         //testLog.append("Series = " + entity.getSeriesIndex() + ", ");
    //         //testLog.append("X = " + entity.getDataset().getX(entity.getSeriesIndex(), entity.getItem()) + ", ");
    //         //testLog.append("Y = " + entity.getDataset().getY(entity.getSeriesIndex(), entity.getItem()) + "\n");
    //         outlierRegion.add(entity.getDataset().getX(entity.getSeriesIndex(), entity.getItem()).doubleValue());
    //      }
    //
    //      Collections.sort(outlierRegion);
    //      if (!outlierRegion.isEmpty())
    //      {
    //         testLog.setText("");
    //         testLog.append("Outlier time selected = [");
    //         for (int i = 0; i < outlierRegion.size(); ++i)
    //         {
    //            testLog.append(outlierRegion.get(i).toString());
    //            if (i < outlierRegion.size() - 1)
    //            {
    //               testLog.append(" ");
    //            }
    //         }
    //         testLog.append("]\n");
    //      }
}

From source file:loadmaprenderer.ResultDisplayChart.java

private JFreeChart makeChart(XYDataset dataset, String chartTitle, String dataTitle) {
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, "Year", dataTitle, dataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.BLUE);
    plot.setRangeGridlinePaint(Color.BLUE);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);//from  www  . j a  v a 2 s.co  m
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRange(true);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(true);
    Double range = dataLine.getMaxY() - dataLine.getMinY();
    if (Math.abs(range) < 0.1)
        range = dataLine.getMaxY();
    rangeAxis.setRange(dataLine.getMinY() - range * 0.1, dataLine.getMaxY() + range * 0.1);
    return chart;
}

From source file:ejemplo.Ejemplo.java

private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart Demo 6", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from  w ww. j  a  v a 2  s  .  co  m*/

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}