Example usage for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero

List of usage examples for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero.

Prototype

public void setAutoRangeIncludesZero(boolean flag) 

Source Link

Document

Sets the flag that indicates whether or not the axis range, if automatically calculated, is forced to include zero.

Usage

From source file:org.trade.ui.chart.CandlestickChart.java

/**
 * Method createChart./*from  w ww  . j a  va  2s.com*/
 * 
 * @param strategyData
 *            StrategyData
 * @param title
 *            String
 * @return JFreeChart
 */
private JFreeChart createChart(StrategyData strategyData, String title, Tradingday tradingday) {

    DateAxis dateAxis = new DateAxis("Date");
    dateAxis.setVerticalTickLabels(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm"));
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    NumberAxis priceAxis = new NumberAxis("Price");
    priceAxis.setAutoRange(true);
    priceAxis.setAutoRangeIncludesZero(false);
    XYPlot pricePlot = new XYPlot(strategyData.getCandleDataset(), dateAxis, priceAxis,
            strategyData.getCandleDataset().getRenderer());
    pricePlot.setOrientation(PlotOrientation.VERTICAL);
    pricePlot.setDomainPannable(true);
    pricePlot.setRangePannable(true);
    pricePlot.setDomainCrosshairVisible(true);
    pricePlot.setDomainCrosshairLockedOnData(true);
    pricePlot.setRangeCrosshairVisible(true);
    pricePlot.setRangeCrosshairLockedOnData(true);
    pricePlot.setRangeGridlinePaint(new Color(204, 204, 204));
    pricePlot.setDomainGridlinePaint(new Color(204, 204, 204));
    pricePlot.setBackgroundPaint(Color.white);

    /*
     * Calculate the number of 15min segments in this trading day. i.e.
     * 6.5hrs/15min = 26 and there are a total of 96 = one day
     */

    int segments15min = (int) (tradingday.getClose().getTime() - tradingday.getOpen().getTime())
            / (1000 * 60 * 15);

    SegmentedTimeline segmentedTimeline = new SegmentedTimeline(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE,
            segments15min, (96 - segments15min));

    Date startDate = tradingday.getOpen();
    Date endDate = tradingday.getClose();

    if (!strategyData.getCandleDataset().getSeries(0).isEmpty()) {
        startDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0).getDataItem(0)).getPeriod()
                .getStart();
        startDate = TradingCalendar.getSpecificTime(tradingday.getOpen(), startDate);
        endDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0)
                .getDataItem(strategyData.getCandleDataset().getSeries(0).getItemCount() - 1)).getPeriod()
                        .getStart();
        endDate = TradingCalendar.getSpecificTime(tradingday.getClose(), endDate);
    }

    segmentedTimeline.setStartTime(startDate.getTime());
    segmentedTimeline.addExceptions(getNonTradingPeriods(startDate, endDate, tradingday.getOpen(),
            tradingday.getClose(), segmentedTimeline));
    dateAxis.setTimeline(segmentedTimeline);

    // Build Combined Plot
    CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(dateAxis);
    mainPlot.add(pricePlot, 4);

    int axixIndex = 0;
    int datasetIndex = 0;

    /*
     * Change the List of indicators so that the candle dataset is the first
     * one in the list. The main chart must be plotted first.
     */
    List<IndicatorDataset> indicators = new ArrayList<IndicatorDataset>(0);
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (!IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (int i = 0; i < indicators.size(); i++) {
        IndicatorDataset indicator = indicators.get(i);
        if (indicator.getDisplaySeries(0)) {

            if (indicator.getSubChart(0)) {
                String axisName = "Price";
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    axisName = ((CandleSeries) indicator.getSeries(0)).getSymbol();
                } else {
                    org.trade.dictionary.valuetype.IndicatorSeries code = org.trade.dictionary.valuetype.IndicatorSeries
                            .newInstance(indicator.getType(0));
                    axisName = code.getDisplayName();
                }
                NumberAxis subPlotAxis = new NumberAxis(axisName);
                subPlotAxis.setAutoRange(true);
                subPlotAxis.setAutoRangeIncludesZero(false);

                XYPlot subPlot = new XYPlot((XYDataset) indicator, dateAxis, subPlotAxis,
                        indicator.getRenderer());

                subPlot.setOrientation(PlotOrientation.VERTICAL);
                subPlot.setDomainPannable(true);
                subPlot.setRangePannable(true);
                subPlot.setDomainCrosshairVisible(true);
                subPlot.setDomainCrosshairLockedOnData(true);
                subPlot.setRangeCrosshairVisible(true);
                subPlot.setRangeCrosshairLockedOnData(true);
                subPlot.setRangeGridlinePaint(new Color(204, 204, 204));
                subPlot.setDomainGridlinePaint(new Color(204, 204, 204));
                subPlot.setBackgroundPaint(Color.white);
                XYItemRenderer renderer = subPlot.getRendererForDataset((XYDataset) indicator);
                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
                mainPlot.add(subPlot, 1);

            } else {
                datasetIndex++;
                pricePlot.setDataset(datasetIndex, (XYDataset) indicator);
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    // add secondary axis
                    axixIndex++;

                    final NumberAxis axis2 = new NumberAxis(
                            ((CandleSeries) indicator.getSeries(0)).getSymbol());
                    axis2.setAutoRange(true);
                    axis2.setAutoRangeIncludesZero(false);
                    pricePlot.setRangeAxis(datasetIndex, axis2);
                    pricePlot.setRangeAxisLocation(i + 1, AxisLocation.BOTTOM_OR_RIGHT);
                    pricePlot.mapDatasetToRangeAxis(datasetIndex, axixIndex);
                    pricePlot.setRenderer(datasetIndex, new StandardXYItemRenderer());
                } else {
                    pricePlot.setRenderer(datasetIndex, indicator.getRenderer());
                }
                XYItemRenderer renderer = pricePlot.getRendererForDataset((XYDataset) indicator);

                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
            }
        }
    }
    JFreeChart jfreechart = new JFreeChart(title, null, mainPlot, true);
    jfreechart.setAntiAlias(false);
    return jfreechart;
}

From source file:org.gwaspi.gui.reports.SampleQAHetzygPlotZoom.java

private JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createScatterPlot("Heterozygosity vs. Missing Ratio",
            "Heterozygosity Ratio", "Missing Ratio", dataset, PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    // CHART BACKGROUD COLOR
    chart.setBackgroundPaint(Color.getHSBColor(0.1f, 0.1f, 1.0f)); // Hue, saturation, brightness
    plot.setBackgroundPaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9

    // GRIDLINES// w  w w . j  ava  2  s  .  co  m
    plot.setDomainGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7
    plot.setDomainMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9
    plot.setRangeGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7
    plot.setRangeMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker()); // Hue, saturation, brightness 8

    plot.setDomainMinorGridlinesVisible(true);
    plot.setRangeMinorGridlinesVisible(true);

    // DOTS RENDERER
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, PLOT_MANHATTAN_DOTS);
    //      renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY);
    //      renderer.setUseOutlinePaint(true);
    // Set dot shape of the currently appended Series
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1, -1, 2, 2));

    renderer.setSeriesVisibleInLegend(0, false);

    // AXIS
    double maxHetzy = 0.005;
    for (int i = 0; i < dataset.getItemCount(0); i++) {
        if (maxHetzy < dataset.getXValue(0, i)) {
            maxHetzy = dataset.getXValue(0, i);
        }
    }
    NumberAxis hetzyAxis = (NumberAxis) plot.getDomainAxis();
    hetzyAxis.setAutoRangeIncludesZero(true);
    hetzyAxis.setAxisLineVisible(true);
    hetzyAxis.setTickLabelsVisible(true);
    hetzyAxis.setTickMarksVisible(true);
    hetzyAxis.setRange(0, maxHetzy * 1.1);

    double maxMissrat = 0.005;
    for (int i = 0; i < dataset.getItemCount(0); i++) {
        if (maxMissrat < dataset.getYValue(0, i)) {
            maxMissrat = dataset.getYValue(0, i);
        }
    }
    NumberAxis missratAxis = (NumberAxis) plot.getRangeAxis();
    missratAxis.setAutoRangeIncludesZero(true);
    missratAxis.setAxisLineVisible(true);
    missratAxis.setTickLabelsVisible(true);
    missratAxis.setTickMarksVisible(true);
    missratAxis.setRange(0, maxMissrat * 1.1);

    // Add significance Threshold to subplot
    final Marker missingThresholdLine = new ValueMarker(missingThreshold);
    missingThresholdLine.setPaint(Color.blue);

    final Marker hetzyThresholdLine = new ValueMarker(hetzyThreshold);
    hetzyThresholdLine.setPaint(Color.blue);

    // Add legend to hetzyThreshold
    hetzyThresholdLine.setLabel("hetzyg. threshold = " + hetzyThreshold);
    missingThresholdLine.setLabel("missing. threshold = " + missingThreshold);
    hetzyThresholdLine.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    hetzyThresholdLine.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    missingThresholdLine.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
    missingThresholdLine.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    plot.addRangeMarker(missingThresholdLine); // THIS FOR MISSING RATIO
    plot.addDomainMarker(hetzyThresholdLine); // THIS FOR HETZY RATIO

    // Marker label if below hetzyThreshold
    XYItemRenderer lblRenderer = plot.getRenderer();

    // THRESHOLD AND SELECTED LABEL GENERATOR
    MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(hetzyThreshold, missingThreshold);
    lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator);
    lblRenderer.setSeriesItemLabelFont(0, new Font("SansSerif", Font.PLAIN, 10));
    lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.BOTTOM_LEFT, TextAnchor.BOTTOM_LEFT, 2 * Math.PI));

    // TOOLTIP GENERATOR
    MyXYToolTipGenerator tooltipGenerator = new MyXYToolTipGenerator();

    lblRenderer.setBaseToolTipGenerator(tooltipGenerator);

    lblRenderer.setSeriesItemLabelsVisible(0, true);

    return chart;
}

From source file:org.paxle.tools.charts.impl.gui.ChartServlet.java

private JFreeChart createIndexChart() {
    // init Time-Series
    TimeSeries indexSizeSeries = new TimeSeries("Index Size", Minute.class);
    indexSizeSeries.setMaximumItemAge(24 * 60);
    this.seriesMap.put(TSERIES_INDEX_SIZE, indexSizeSeries);

    // init chart
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, "Time", "#Docs",
            new TimeSeriesCollection(indexSizeSeries), true, false, false);

    XYPlot plot = chart.getXYPlot();/*from w  ww . jav  a2 s  . c om*/

    final TimeSeriesCollection linksDataset = new TimeSeriesCollection();

    TimeSeries totalLinksSeries = new TimeSeries("Total URI", Minute.class);
    totalLinksSeries.setMaximumItemAge(24 * 60);
    linksDataset.addSeries(totalLinksSeries);
    this.seriesMap.put(TSERIES_CMD_SIZE_TOTAL, totalLinksSeries);

    TimeSeries enqueuedLinksSeries = new TimeSeries("Enqueued URI", Minute.class);
    enqueuedLinksSeries.setMaximumItemAge(24 * 60);
    linksDataset.addSeries(enqueuedLinksSeries);
    this.seriesMap.put(TSERIES_CMD_SIZE_ENQUEUD, enqueuedLinksSeries);

    NumberAxis axis2 = new NumberAxis("#Links");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setNumberFormatOverride(new DecimalFormat("#,##0"));
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, linksDataset);
    plot.setRenderer(1, new StandardXYItemRenderer());
    plot.mapDatasetToRangeAxis(1, 1);

    NumberAxis axis1 = (NumberAxis) plot.getRangeAxis(0);
    axis1.setNumberFormatOverride(new DecimalFormat("#,##0"));

    // change axis date format
    ((DateAxis) plot.getDomainAxis()).setDateFormatOverride(new SimpleDateFormat("HH:mm"));
    chart.setBackgroundPaint(Color.WHITE);
    return chart;
}

From source file:be.nbb.demetra.dfm.output.simulation.RMSEGraphView.java

private JFreeChart createChart() {
    JFreeChart result = ChartFactory.createXYBarChart("", "", false, "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);
    result.getTitle().setFont(TsCharts.CHART_TITLE_FONT);

    XYPlot plot = result.getXYPlot();// w  ww.  j a v  a 2s  . c  om

    plot.setDataset(DFM_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(DFM_INDEX, dfmRenderer);
    plot.mapDatasetToDomainAxis(DFM_INDEX, 0);
    plot.mapDatasetToRangeAxis(DFM_INDEX, 0);

    plot.setDataset(ARIMA_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(ARIMA_INDEX, arimaRenderer);
    plot.mapDatasetToDomainAxis(ARIMA_INDEX, 0);
    plot.mapDatasetToRangeAxis(ARIMA_INDEX, 0);

    plot.setDataset(STDEV_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(STDEV_INDEX, stdevRenderer);
    plot.mapDatasetToDomainAxis(STDEV_INDEX, 0);
    plot.mapDatasetToRangeAxis(STDEV_INDEX, 0);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);

    NumberAxis domainAxis = new NumberAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    return result;
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.SingleCellAnalysisController.java

/**
 * Generate Box Plot Chart given a dataset and something to put on the y
 * label./*from  ww  w  . j a  va  2s  .  c o m*/
 *
 * @param dataset
 * @param yLabel
 * @return
 */
private JFreeChart generateBoxPlotChart(DefaultBoxAndWhiskerCategoryDataset dataset, String yLabel,
        String title) {
    CategoryAxis xAxis = new CategoryAxis("Condition");
    NumberAxis yAxis = new NumberAxis(yLabel);
    yAxis.setAutoRangeIncludesZero(false);
    CategoryPlot boxPlot = new CategoryPlot(dataset, xAxis, yAxis, new ExtendedBoxAndWhiskerRenderer());
    JFreeChart boxPlotChart = new JFreeChart(title, JFreeChartUtils.getChartFont(), boxPlot, false);
    JFreeChartUtils.setupBoxPlotChart(boxPlotChart);
    return boxPlotChart;
}

From source file:com.charts.TenYearChart.java

public TenYearChart(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.setBaseToolTipGenerator(//from ww w . jav  a 2 s . c o  m
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));

    renderer.setDrawVolume(false);
    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:org.csa.rstb.dat.toolviews.HaAlphaPlotPanel.java

private void createUI() {
    plot = new XYImagePlot();
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setAutoRangeIncludesZero(false);
    domainAxis.setUpperMargin(0);//from  w  ww . j a v  a  2s.  c  om
    domainAxis.setLowerMargin(0);
    rangeAxis.setUpperMargin(0);
    rangeAxis.setLowerMargin(0);
    plot.setNoDataMessage(NO_DATA_MESSAGE);
    plot.getRenderer().setBaseToolTipGenerator(new XYPlotToolTipGenerator());
    JFreeChart chart = new JFreeChart(CHART_TITLE, plot);
    ChartFactory.getChartTheme().apply(chart);

    chart.removeLegend();
    createUI(createChartPanel(chart), createOptionsPanel(), bindingContext);
    updateUIState();
}

From source file:edu.ucla.stat.SOCR.analyses.gui.Chart.java

protected JFreeChart createQQChart(String title, String xLabel, String yLabel, XYDataset dataset,
        String other) {//  w  ww.j  a v  a 2s  .c o  m

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            xLabel, // x axis label
            yLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

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

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

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    // renderer.setShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    //  renderer.setLinesVisible(false);
    renderer.setSeriesLinesVisible(1, true);
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);

    //renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setUpperMargin(0.02);
    rangeAxis.setLowerMargin(0.02);

    // rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setUpperMargin(0.02);
    domainAxis.setLowerMargin(0.02);

    // domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // OPTIONAL CUSTOMISATION COMPLETED.
    //setQQSummary(dataset);    // very confusing   
    return chart;

}

From source file:com.vgi.mafscaling.VECalc.java

protected void createChart(JPanel plotPanel, String xAxisName, String yAxisName) {
    JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false,
            true, false);//from   w  w  w .j  a  v  a  2 s .c  o m
    chart.setBorderVisible(true);

    chartPanel = new ChartPanel(chart, true, true, true, true, true);
    chartPanel.setAutoscrolls(true);
    chartPanel.setMouseZoomable(false);

    GridBagConstraints gbl_chartPanel = new GridBagConstraints();
    gbl_chartPanel.anchor = GridBagConstraints.CENTER;
    gbl_chartPanel.insets = new Insets(3, 3, 3, 3);
    gbl_chartPanel.weightx = 1.0;
    gbl_chartPanel.weighty = 1.0;
    gbl_chartPanel.fill = GridBagConstraints.BOTH;
    gbl_chartPanel.gridx = 0;
    gbl_chartPanel.gridy = 1;
    plotPanel.add(chartPanel, gbl_chartPanel);

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
    lineRenderer.setUseFillPaint(true);
    lineRenderer.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new DecimalFormat("0.00"), new DecimalFormat("0.00")));

    Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
    lineRenderer.setSeriesStroke(0, stroke);
    lineRenderer.setSeriesPaint(0, Color.RED);
    lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));

    lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
        private static final long serialVersionUID = 7593430826693873496L;

        public String generateLabel(XYDataset dataset, int series) {
            XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
            return xys.getDescription();
        }
    });

    NumberAxis xAxis = new NumberAxis(xAxisName);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisName);
    yAxis.setAutoRangeIncludesZero(false);

    XYSeriesCollection lineDataset = new XYSeriesCollection();

    XYPlot plot = chart.getXYPlot();
    plot.setRangePannable(true);
    plot.setDomainPannable(true);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    plot.setBackgroundPaint(new Color(224, 224, 224));

    plot.setDataset(0, lineDataset);
    plot.setRenderer(0, lineRenderer);
    plot.setDomainAxis(0, xAxis);
    plot.setRangeAxis(0, yAxis);
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    LegendTitle legend = new LegendTitle(plot.getRenderer());
    legend.setItemFont(new Font("Arial", 0, 10));
    legend.setPosition(RectangleEdge.TOP);
    chart.addLegend(legend);
}

From source file:com.rapidminer.gui.plotter.charts.MultipleSeriesChartPlotter.java

private JFreeChart createChart() {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            null, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );//w w  w .j av a 2  s .com

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customization...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // domain axis

    if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
        if ((dataTable.isDate(indexAxis)) || (dataTable.isDateTime(indexAxis))) {
            DateAxis domainAxis = new DateAxis(dataTable.getColumnName(indexAxis));
            domainAxis.setTimeZone(Tools.getPreferredTimeZone());
            chart.getXYPlot().setDomainAxis(domainAxis);
        }
    } else {
        plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
        ((NumberAxis) plot.getDomainAxis()).setAutoRangeStickyZero(false);
        ((NumberAxis) plot.getDomainAxis()).setAutoRangeIncludesZero(false);
    }
    ValueAxis xAxis = plot.getDomainAxis();
    if (indexAxis > -1) {
        xAxis.setLabel(getDataTable().getColumnName(indexAxis));
    } else {
        xAxis.setLabel(SERIESINDEX_LABEL);
    }
    xAxis.setAutoRange(true);
    xAxis.setLabelFont(LABEL_FONT_BOLD);
    xAxis.setTickLabelFont(LABEL_FONT);
    xAxis.setVerticalTickLabels(isLabelRotating());
    if (indexAxis > 0) {
        if (getRangeForDimension(indexAxis) != null) {
            xAxis.setRange(getRangeForDimension(indexAxis));
        }
    } else {
        if (getRangeForName(SERIESINDEX_LABEL) != null) {
            xAxis.setRange(getRangeForName(SERIESINDEX_LABEL));
        }
    }

    // renderer and range axis
    synchronized (dataTable) {
        int numberOfSelectedColumns = 0;
        for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
            if (getPlotColumn(c)) {
                if (dataTable.isNumerical(c)) {
                    numberOfSelectedColumns++;
                }
            }
        }

        int columnCount = 0;
        for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
            if (getPlotColumn(c)) {
                if (dataTable.isNumerical(c)) {
                    // YIntervalSeries series = new
                    // YIntervalSeries(this.dataTable.getColumnName(c));
                    XYSeriesCollection dataset = new XYSeriesCollection();
                    XYSeries series = new XYSeries(dataTable.getColumnName(c));
                    Iterator<DataTableRow> i = dataTable.iterator();
                    int index = 1;
                    while (i.hasNext()) {
                        DataTableRow row = i.next();
                        double value = row.getValue(c);

                        if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
                            double indexValue = row.getValue(indexAxis);
                            series.add(indexValue, value);
                        } else {
                            series.add(index++, value);
                        }
                    }
                    dataset.addSeries(series);

                    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

                    Color color = getColorProvider().getPointColor(1.0d);
                    if (numberOfSelectedColumns > 1) {
                        color = getColorProvider()
                                .getPointColor(columnCount / (double) (numberOfSelectedColumns - 1));
                    }
                    renderer.setSeriesPaint(0, color);
                    renderer.setSeriesStroke(0,
                            new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
                    renderer.setSeriesShapesVisible(0, false);

                    NumberAxis yAxis = new NumberAxis(dataTable.getColumnName(c));
                    if (getRangeForDimension(c) != null) {
                        yAxis.setRange(getRangeForDimension(c));
                    } else {
                        yAxis.setAutoRange(true);
                        yAxis.setAutoRangeStickyZero(false);
                        yAxis.setAutoRangeIncludesZero(false);
                    }
                    yAxis.setLabelFont(LABEL_FONT_BOLD);
                    yAxis.setTickLabelFont(LABEL_FONT);
                    if (numberOfSelectedColumns > 1) {
                        yAxis.setAxisLinePaint(color);
                        yAxis.setTickMarkPaint(color);
                        yAxis.setLabelPaint(color);
                        yAxis.setTickLabelPaint(color);
                    }

                    plot.setRangeAxis(columnCount, yAxis);
                    plot.setRangeAxisLocation(columnCount, AxisLocation.TOP_OR_LEFT);

                    plot.setDataset(columnCount, dataset);
                    plot.setRenderer(columnCount, renderer);
                    plot.mapDatasetToRangeAxis(columnCount, columnCount);

                    columnCount++;
                }
            }
        }
    }

    chart.setBackgroundPaint(Color.white);

    return chart;
}