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

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

Introduction

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

Prototype

public ValueAxis getDomainAxis() 

Source Link

Document

Returns the domain axis with index 0.

Usage

From source file:net.sf.mzmine.modules.visualization.ida.IDABottomPanel.java

/**
 * Returns a peak list with the top peaks defined by the parameter
 * "threshold"//from   w  ww  . j av a2s  . co  m
 */
PeakList getTopThresholdPeakList(int threshold) {

    PeakList selectedPeakList = (PeakList) peakListSelector.getSelectedItem();
    if (selectedPeakList == null)
        return null;
    SimplePeakList newList = new SimplePeakList(selectedPeakList.getName(), selectedPeakList.getRawDataFiles());

    Vector<PeakListRow> peakRows = new Vector<PeakListRow>();

    Range<Double> mzRange = selectedPeakList.getRowsMZRange();
    Range<Double> rtRange = selectedPeakList.getRowsRTRange();

    PeakThresholdMode selectedPeakOption = (PeakThresholdMode) thresholdCombo.getSelectedItem();
    if (selectedPeakOption == PeakThresholdMode.TOP_PEAKS_AREA) {
        XYPlot xyPlot = masterFrame.getPlot().getXYPlot();
        org.jfree.data.Range yAxis = xyPlot.getRangeAxis().getRange();
        org.jfree.data.Range xAxis = xyPlot.getDomainAxis().getRange();
        rtRange = Range.closed(xAxis.getLowerBound(), xAxis.getUpperBound());
        mzRange = Range.closed(yAxis.getLowerBound(), yAxis.getUpperBound());
    }

    for (PeakListRow peakRow : selectedPeakList.getRows()) {
        if (mzRange.contains(peakRow.getAverageMZ()) && rtRange.contains(peakRow.getAverageRT())) {
            peakRows.add(peakRow);
        }
    }

    Collections.sort(peakRows, new PeakListRowSorter(SortingProperty.Intensity, SortingDirection.Descending));

    if (threshold > peakRows.size())
        threshold = peakRows.size();
    for (int i = 0; i < threshold; i++) {
        newList.addRow(peakRows.elementAt(i));
    }
    return newList;
}

From source file:ac.openmicrolabs.view.gui.OMLLoggerView.java

@Override
public final void setViewLoggingCompleted(final double graphTimeRange) {
    final XYPlot plot = snsChart.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);//from   w  w w.  jav  a 2s  .  c om
    axis.setFixedAutoRange(graphTimeRange);
    axis = plot.getRangeAxis();
    axis.setRange(graphMinY, graphMaxY);

    this.setTitle(OMLAppDetails.name());

    valSideLabel.setText(h.format("label-bold", avgSideLabel.getText()));
    avgSideLabel.setText("");
    for (int i = 0; i < avgLabel.length; i++) {
        valLabel[i].setText(h.format("label-bold", h.get("body").unformat(avgLabel[i].getText())));
        avgLabel[i].setText("");
    }

    reportButton.setSize(doneButton.getSize());
    reportButton.setIcon(new ImageIcon("img/22x22/save.png"));
    reportButton.setLocation(doneButton.getX() - doneButton.getWidth() - PAD10, doneButton.getY());
    reportButton.setBackground(Color.white);

    footerLabel.setSize(reportButton.getLocation().x, PAD30);
    footerLabel.setHorizontalAlignment(JLabel.CENTER);

    btmPanel.remove(progressBar);
    btmPanel.add(reportButton);
    btmPanel.repaint();
    doneButton.setText("Done");
    doneButton.setIcon(new ImageIcon("img/22x22/play.png", OMLAppDetails.name()));
}

From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java

/**
 * calculates the correct height with multiple iterations Domain and Range axes need to share the
 * same unit (e.g. mm)//from   www .j a  v  a 2  s. c  o  m
 * 
 * @param myChart
 * @param dataWidth width of data
 * @param axis for width calculation
 * @return
 */
public static double calcHeightToWidth(ChartViewer myChart, double chartWidth, double estimatedHeight,
        int iterations) {
    // if(myChart.getChartRenderingInfo()==null ||
    // myChart.getChartRenderingInfo().getChartArea()==null ||
    // myChart.getChartRenderingInfo().getChartArea().getWidth()==0)
    // result
    double height = estimatedHeight;
    double lastH = height;

    makeChartResizable(myChart);

    try {
        for (int i = 0; i < iterations; i++) {
            // paint on ghost panel with estimated height (if copy panel==true)
            myChart.getCanvas().setWidth((int) chartWidth);
            myChart.getCanvas().setHeight((int) estimatedHeight);
            myChart.getCanvas().draw();

            XYPlot plot = (XYPlot) myChart.getChart().getPlot();
            ChartRenderingInfo info = myChart.getRenderingInfo();
            Rectangle2D dataArea = info.getPlotInfo().getDataArea();
            Rectangle2D chartArea = info.getChartArea();

            // calc title space: will be added later to the right plot size
            double titleWidth = chartArea.getWidth() - dataArea.getWidth();
            double titleHeight = chartArea.getHeight() - dataArea.getHeight();

            // calc right plot size with axis dim.
            // real plot width is given by factor;
            double realPW = chartWidth - titleWidth;

            // ranges
            ValueAxis domainAxis = plot.getDomainAxis();
            org.jfree.data.Range x = domainAxis.getRange();
            ValueAxis rangeAxis = plot.getRangeAxis();
            org.jfree.data.Range y = rangeAxis.getRange();

            // real plot height can be calculated by
            double realPH = realPW / x.getLength() * y.getLength();

            // the real height
            height = realPH + titleHeight;

            // for next iteration
            estimatedHeight = height;
            if ((int) lastH == (int) height)
                break;
            else
                lastH = height;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return height;
}

From source file:org.operamasks.faces.render.graph.CompositeChartRenderer.java

private JFreeChart createXYCompositeChart(List<JFreeChart> subcharts, UIChart comp) {
    XYPlot compositePlot = new XYPlot();
    compositePlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    compositePlot.setOrientation(getChartOrientation(comp));

    for (int i = 0; i < subcharts.size(); i++) {
        XYPlot subplot = (XYPlot) subcharts.get(i).getPlot();
        compositePlot.setDataset(i, subplot.getDataset());
        compositePlot.setRenderer(i, subplot.getRenderer());

        if (i == 0) {
            compositePlot.setDomainAxis(0, subplot.getDomainAxis());
            compositePlot.setRangeAxis(0, subplot.getRangeAxis());
        } else {/*from w  ww.j a v a  2 s.  c  om*/
            int yAxisMap = getRangeAxisMap(comp, i);
            ValueAxis yAxis = null;
            if (yAxisMap == -1) {
                yAxisMap = 0; // map to axis zero by default
            } else if (yAxisMap == i) {
                yAxis = subplot.getRangeAxis(); // add subplot axis to composite plot
            }
            compositePlot.setRangeAxis(i, yAxis);
            compositePlot.mapDatasetToRangeAxis(i, yAxisMap);
        }
    }

    return new JFreeChart(null, null, compositePlot, false);
}

From source file:BubbleChartDemo.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    Connection conn = null;//from w w  w  . java2  s  .com
    Statement stmt = null;
    ResultSet rs = null;
    ResultSetMetaData rsm = null;

    OutputStream out = response.getOutputStream();
    try {

        DefaultXYZDataset dataset = new DefaultXYZDataset();
        double[] x = { 2.1, 2.3, 2.3, 2.2, 2.2, 1.8, 1.8, 1.9, 2.3, 3.8 };
        double[] y = { 14.1, 11.1, 10.0, 8.8, 8.7, 8.4, 5.4, 4.1, 4.1, 25 };
        double[] z = { 2.4, 2.7, 2.7, 2.2, 2.2, 2.2, 2.1, 2.2, 1.6, 4 };
        double[][] series = new double[][] { x, y, z };
        dataset.addSeries("Series 1", series);

        JFreeChart chart = ChartFactory.createBubbleChart("Bubble Chart Demo 1", "X", "Y", dataset,
                PlotOrientation.HORIZONTAL, true, true, true);
        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setForegroundAlpha(0.65f);

        XYItemRenderer renderer = plot.getRenderer();
        renderer.setSeriesPaint(0, Color.blue);

        // increase the margins to account for the fact that the auto-range
        // doesn't take into account the bubble size...
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        domainAxis.setLowerMargin(0.15);
        domainAxis.setUpperMargin(0.15);
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setLowerMargin(0.15);
        rangeAxis.setUpperMargin(0.15);

        response.setContentType("image/png");
        int width = 800;
        int height = 600;
        ChartUtilities.writeChartAsPNG(out, chart, width, height);

    } catch (Exception e) {
        throw new ServletException(e);
    }

}

From source file:tmn.dev.project.Player.java

/**
 * Generate a plot of batting average over the span of a season and write
 * the plot to a PNG file.//from w  ww.  j  a  va  2 s . c  om
 * 
 * @return The String representation of the name of the PNG file containing
 *         the plot.
 * @throws IOException
 */
private String createBAPlot() throws IOException {

    // Create a scatter plot for batting average over the season
    // Game number on the x axis, Batting average on the y axis
    JFreeChart chart = ChartFactory.createScatterPlot("Batting Average Throughout the Season", "Game Number",
            "Batting Average", new XYSeriesCollection(baGame), PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = chart.getXYPlot();
    // Set the axis ranges to provide an appropriate zoom
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setRange(baGame.getMinX(), baGame.getMaxX());
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setRange(baGame.getMinY() - .02, baGame.getMaxY() + .02);
    // Set the tick labels on the y axis to the typical BA format
    yAxis.setNumberFormatOverride(new DecimalFormat(".000"));

    // Create the String representation of the /images directory
    String imgDirStr = System.getProperty("user.dir") + System.getProperty("file.separator") + "images";

    // If the directory doesn't already exist, create it
    File imgDir = new File(imgDirStr);
    if (!imgDir.exists() && !imgDir.isDirectory())
        imgDir.mkdir();

    // Create the batting average PNG files
    String fileName = imgDirStr + System.getProperty("file.separator") + this.getId() + ".png";
    File imgFile = new File(fileName);

    // If the file already exists, append a number in parentheses
    int index = 0;
    while (!imgFile.createNewFile()) {
        // Append (<index>).html after the Player ID
        fileName = imgDirStr + System.getProperty("file.separator") + this.getId() + "(" + ++index + ")"
                + ".png";
        // Try to create a file with this name
        imgFile = new File(fileName);
    }

    // Write the plot to the PNG file that was created
    ChartUtilities.saveChartAsPNG(imgFile, chart, 800, 450);

    return imgFile.getName();
}

From source file:com.charts.FiveYearChart.java

public FiveYearChart(YStockQuote currentStock) throws ParseException {

    DateAxis domainAxis = new DateAxis("Date");
    NumberAxis rangeAxis = new NumberAxis("Price");
    CandlestickRenderer renderer = new CandlestickRenderer();
    XYDataset dataset = getDataSet(currentStock);

    XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);

    //Do some setting up, see the API Doc
    renderer.setSeriesPaint(0, Color.BLACK);

    renderer.setDrawVolume(false);/*from w ww .j  a  v a2  s .c  o  m*/
    rangeAxis.setAutoRangeIncludesZero(false);

    domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy"));
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    //Now create the chart and chart panel
    JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false);
    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(900, 400));

    XYPlot plot = (XYPlot) chart.getPlot();
    LegendTitle legend = new LegendTitle(plot);
    chart.addLegend(legend);
    chart.getLegend().setVisible(true);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);
    ValueAxis yAxis = (ValueAxis) plot.getRangeAxis();
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();

    xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y"));
    xAxis.setAutoTickUnitSelection(true);
    xAxis.setAutoRange(true);
    renderer.setAutoWidthFactor(0.5);
    renderer.setUpPaint(Color.green);
    renderer.setDownPaint(new Color(0xc0, 0x00, 0x00));
    renderer.setSeriesPaint(0, Color.black);
    StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
    renderer1.setSeriesPaint(0, Color.BLUE);
    TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0);
    Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue();
    currMA30 = Math.round(currMA30 * 100.0) / 100.0;
    movingAverage30.setKey("MA(30): " + currMA30);
    TimeSeriesCollection collection = new TimeSeriesCollection();
    collection.addSeries(movingAverage30);
    plot.setDataset(1, collection);
    plot.setRenderer(1, renderer1);

    chartPanel.revalidate();
    chartPanel.repaint();
    chartPanel.revalidate();
    chartPanel.repaint();
}

From source file:com.stableapps.anglewraparounddemo.AngleWrapDemoMain.java

/**
 * Creates a sample chart.//from   ww w  . java2 s .  co m
 *
 * @return a sample chart.
 */
private JFreeChart createChart() {
    final XYDataset direction = createAngleDataset(600);
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time", "Date", "Direction", direction, true,
            true, false);

    final XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);

    // configure the range axis to provide a fix set of TickUnits depending on size of chart
    NumberAxis rangeAxis = new NumberAxis() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public NumberTickUnit getTickUnit() {
            NumberTickUnit tickUnit = super.getTickUnit();
            if (tickUnit.getSize() < 15) {
                return tickUnit;
            } else if (tickUnit.getSize() < 45) {
                return new NumberTickUnit(45);
            } else if (tickUnit.getSize() < 90) {
                return new NumberTickUnit(90);
            } else if (tickUnit.getSize() < 180) {
                return new NumberTickUnit(180);
            } else {
                return new NumberTickUnit(360);
            }
        }

    };
    rangeAxis.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(rangeAxis);

    final OverflowCondition overflowCondition = new OverflowCondition() {
        @Override
        public boolean isOverflow(double y0, double x0, double y1, double x1) {
            return Math.abs(y1 - y0) > 180;
        }
    };
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) {
        /**
         *
         */
        private static final long serialVersionUID = 1L;
        double min = 0;
        double max = 360;
        LinearInterpolator interpolator = new LinearInterpolator();

        @Override
        protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset,
                int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis,
                Rectangle2D dataArea) {
            if (item == 0) {
                return;
            }

            // get the data point...
            double x1 = dataset.getXValue(series, item);
            double y1 = dataset.getYValue(series, item);
            if (Double.isNaN(y1) || Double.isNaN(x1)) {
                return;
            }

            double x0 = dataset.getXValue(series, item - 1);
            double y0 = dataset.getYValue(series, item - 1);
            if (Double.isNaN(y0) || Double.isNaN(x0)) {
                return;
            }

            if (overflowCondition.isOverflow(y0, x0, y1, x1)) {
                boolean overflowAtMax = y1 < y0;
                if (overflowAtMax) {
                    LinearFunction lf = interpolator.interpolate(new double[] { y0, y1 + (max - min) },
                            new double[] { x0, x1 });
                    double xmid = lf.value(max);
                    drawPrimaryLine(state, g2, plot, x0, y0, xmid, max, pass, series, item, domainAxis,
                            rangeAxis, dataArea);
                    drawPrimaryLine(state, g2, plot, xmid, min, x1, y1, pass, series, item, domainAxis,
                            rangeAxis, dataArea);
                } else {
                    LinearFunction lf = interpolator.interpolate(new double[] { y1 - (max - min), y0 },
                            new double[] { x1, x0 });
                    double xmid = lf.value(min);
                    drawPrimaryLine(state, g2, plot, x0, y0, xmid, min, pass, series, item, domainAxis,
                            rangeAxis, dataArea);
                    drawPrimaryLine(state, g2, plot, xmid, max, x1, y1, pass, series, item, domainAxis,
                            rangeAxis, dataArea);
                }
            } else {
                drawPrimaryLine(state, g2, plot, x0, y0, x1, y1, pass, series, item, domainAxis, rangeAxis,
                        dataArea);
            }

        }

        private void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, double x0,
                double y0, double x1, double y1, int pass, int series, int item, ValueAxis domainAxis,
                ValueAxis rangeAxis, Rectangle2D dataArea) {
            RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
            RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
            double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
            double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);
            double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
            double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
            // only draw if we have good values
            if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                    || Double.isNaN(transY1)) {
                return;
            }
            PlotOrientation orientation = plot.getOrientation();
            boolean visible;
            if (orientation == PlotOrientation.HORIZONTAL) {
                state.workingLine.setLine(transY0, transX0, transY1, transX1);
            } else if (orientation == PlotOrientation.VERTICAL) {
                state.workingLine.setLine(transX0, transY0, transX1, transY1);
            }
            visible = LineUtilities.clipLine(state.workingLine, dataArea);
            if (visible) {
                drawFirstPassShape(g2, pass, series, item, state.workingLine);
            }
        }

        @Override
        protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot,
                XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis,
                Rectangle2D dataArea) {

            // get the data point...
            State s = (State) state;
            try {
                double x1 = dataset.getXValue(series, item);
                double y1 = dataset.getYValue(series, item);
                if (Double.isNaN(x1) && Double.isNaN(y1)) {
                    s.setLastPointGood(false);
                    return;
                }

                if (!s.isLastPointGood()) {
                    ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1);
                    s.seriesPath.moveTo(xy.getLeft(), xy.getRight());
                    s.setLastPointGood(true);
                    return;
                }

                double x0 = dataset.getXValue(series, item - 1);
                double y0 = dataset.getYValue(series, item - 1);
                if (overflowCondition.isOverflow(y0, x0, y1, x1)) {
                    boolean overflowAtMax = y1 < y0;
                    if (overflowAtMax) {
                        LinearFunction lf = interpolator.interpolate(new double[] { y0, y1 + (max - min) },
                                new double[] { x0, x1 });
                        double xmid = lf.value(max);
                        ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid,
                                max);
                        s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                        xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid, min);
                        s.seriesPath.moveTo(xy.getLeft(), xy.getRight());
                        xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1);
                        s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                    } else {
                        LinearFunction lf = interpolator.interpolate(new double[] { y1 - (max - min), y0 },
                                new double[] { x1, x0 });
                        double xmid = lf.value(min);
                        ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid,
                                min);
                        s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                        xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid, max);
                        s.seriesPath.moveTo(xy.getLeft(), xy.getRight());
                        xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1);
                        s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                    }
                } else {
                    ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1);
                    s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                }

                s.setLastPointGood(true);
            } finally {
                // if this is the last item, draw the path ...
                if (item == s.getLastItemIndex()) {
                    // draw path
                    drawFirstPassShape(g2, pass, series, item, s.seriesPath);
                }

            }
        }

        private ImmutablePair<Float, Float> translate(XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis,
                Rectangle2D dataArea, double x, double y) {
            RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
            RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
            double transX1 = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
            double transY1 = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
            // update path to reflect latest point
            float xtrans = (float) transX1;
            float ytrans = (float) transY1;
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL) {
                xtrans = (float) transY1;
                ytrans = (float) transX1;
            }
            return new ImmutablePair<>(xtrans, ytrans);
        }
    };
    renderer.setDrawSeriesLineAsPath(true);
    plot.setRenderer(0, renderer);

    return chart;
}

From source file:org.squale.squaleweb.util.graph.HistoMaker.java

/**
 * This method create the JFreechart chart
 * /*from  w  w  w  .  j a v  a2  s  .  c o  m*/
 * @param maxAxisToday Does the max for the date axis should be set to today ?
 * @return A JFreeChart chart
 */
public JFreeChart getChart(boolean maxAxisToday) {
    JFreeChart retChart = super.getChart();
    if (null == retChart) {
        retChart = ChartFactory.createTimeSeriesChart(mTitle, mXLabel, mYLabel, mDataSet, mShowLegend, false,
                false);
        XYPlot plot = retChart.getXYPlot();
        XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
        xylineandshaperenderer.setBaseShapesVisible(true);
        plot.setRenderer(xylineandshaperenderer);
        SimpleDateFormat sdf = new SimpleDateFormat(mDateFormat);
        DateAxis axis = (DateAxis) plot.getDomainAxis();
        if (maxAxisToday) {
            axis.setMaximumDate(new Date());
        }
        axis.setDateFormatOverride(sdf);
        ValueAxis yAxis = plot.getRangeAxis();
        yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        yAxis.setAutoRangeMinimumSize(2.0);
        super.setChart(retChart);
    }
    return retChart;
}

From source file:com.charts.MaxChart.java

public MaxChart(YStockQuote currentStock) throws ParseException {

    DateAxis domainAxis = new DateAxis("Date");
    NumberAxis rangeAxis = new NumberAxis("Price");
    CandlestickRenderer renderer = new CandlestickRenderer();
    XYDataset dataset = getDataSet(currentStock);

    XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);

    //Do some setting up, see the API Doc
    renderer.setSeriesPaint(0, Color.BLACK);

    renderer.setDrawVolume(false);//from   w  ww  . java2  s  .c o m
    rangeAxis.setAutoRangeIncludesZero(false);

    domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy"));
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    //Now create the chart and chart panel
    JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false);
    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(900, 400));

    XYPlot plot = (XYPlot) chart.getPlot();
    LegendTitle legend = new LegendTitle(plot);
    chart.addLegend(legend);
    chart.getLegend().setVisible(true);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);

    ValueAxis yAxis = (ValueAxis) plot.getRangeAxis();
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();

    xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y"));
    xAxis.setAutoTickUnitSelection(true);
    xAxis.setAutoRange(true);
    renderer.setAutoWidthFactor(0.5);
    renderer.setUpPaint(Color.green);
    renderer.setDownPaint(new Color(0xc0, 0x00, 0x00));
    renderer.setSeriesPaint(0, Color.black);
    StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
    renderer1.setSeriesPaint(0, Color.BLUE);
    TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0);
    Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue();
    currMA30 = Math.round(currMA30 * 100.0) / 100.0;
    movingAverage30.setKey("MA(30): " + currMA30);
    TimeSeriesCollection collection = new TimeSeriesCollection();
    collection.addSeries(movingAverage30);
    plot.setDataset(1, collection);
    plot.setRenderer(1, renderer1);

    chartPanel.revalidate();
    chartPanel.repaint();
    chartPanel.revalidate();
    chartPanel.repaint();
}