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

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

Introduction

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

Prototype

public void setOrientation(PlotOrientation orientation) 

Source Link

Document

Sets the orientation for the plot and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:org.drools.planner.benchmark.core.statistic.PlannerStatistic.java

private void writeScalabilitySummaryChart() {
    NumberAxis xAxis = new NumberAxis("Problem scale");
    NumberAxis yAxis = new NumberAxis("Time spend");
    yAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    int seriesIndex = 0;
    for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) {
        String solverLabel = solverBenchmark.getName();
        if (solverBenchmark.isRankingBest()) {
            solverLabel += " (winner)";
        }//w  ww.  ja  v  a 2s  .  c om
        XYSeries series = new XYSeries(solverLabel);
        for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) {
            if (singleBenchmark.isSuccess()) {
                long problemScale = singleBenchmark.getProblemScale();
                long timeMillisSpend = singleBenchmark.getTimeMillisSpend();
                series.add((Long) problemScale, (Long) timeMillisSpend);
            }
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
        // Use dashed line
        renderer.setSeriesStroke(0, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 2.0f, 6.0f }, 0.0f));
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart("Scalability summary (lower is better)", JFreeChart.DEFAULT_TITLE_FONT,
            plot, true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    scalabilitySummaryFile = new File(plannerBenchmark.getBenchmarkReportDirectory(), "scalabilitySummary.png");
    OutputStream out = null;
    try {
        out = new FileOutputStream(scalabilitySummaryFile);
        ImageIO.write(chartImage, "png", out);
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing scalabilitySummaryFile: " + scalabilitySummaryFile,
                e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final XYPlot plot = chart.getXYPlot();
    final XYItemRenderer renderer = plot.getRenderer();

    if (StringUtils.isEmpty(getTooltipFormula()) == false) {
        renderer.setBaseToolTipGenerator(new FormulaXYZTooltipGenerator(getRuntime(), getTooltipFormula()));
    }// www.ja va  2  s  .  com
    if (StringUtils.isEmpty(getUrlFormula()) == false) {
        renderer.setURLGenerator(new FormulaXYZURLGenerator(getRuntime(), getUrlFormula()));
    }

    renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(Boolean.TRUE.equals(getItemsLabelVisible()));
    if (getItemLabelFont() != null) {
        renderer.setBaseItemLabelFont(getItemLabelFont());
    }

    plot.setOrientation(computePlotOrientation());

    // May be an axis that supports dates
    final ValueAxis domainAxis = plot.getDomainAxis();
    if (domainAxis instanceof NumberAxis) {
        final NumberAxis numberAxis = (NumberAxis) domainAxis;
        numberAxis.setAutoRangeIncludesZero(isDomainIncludesZero());
        numberAxis.setAutoRangeStickyZero(isDomainStickyZero());
        if (getDomainPeriodCount() > 0) {
            if (getDomainTickFormat() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(getDomainPeriodCount(), getDomainTickFormat()));
            } else if (getDomainTickFormatString() != null) {
                final FastDecimalFormat formatter = new FastDecimalFormat(getDomainTickFormatString(),
                        getResourceBundleFactory().getLocale());
                numberAxis.setTickUnit(new FastNumberTickUnit(getDomainPeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(new FastNumberTickUnit(getDomainPeriodCount()));
            }
        } else {
            if (getDomainTickFormat() != null) {
                numberAxis.setNumberFormatOverride(getDomainTickFormat());
            } else if (getDomainTickFormatString() != null) {
                final DecimalFormat formatter = new DecimalFormat(getDomainTickFormatString(),
                        new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setNumberFormatOverride(formatter);
            }
        }
    } else if (domainAxis instanceof DateAxis) {
        final DateAxis numberAxis = (DateAxis) domainAxis;

        if (getDomainPeriodCount() > 0 && getDomainTimePeriod() != null) {
            if (getDomainTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getDomainTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getDomainTimePeriod()),
                        (int) getDomainPeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getDomainTimePeriod()),
                        (int) getDomainPeriodCount()));
            }
        }
    }

    if (domainAxis != null) {
        domainAxis.setLabel(getDomainTitle());
        if (getDomainTitleFont() != null) {
            domainAxis.setLabelFont(getDomainTitleFont());
        }
        domainAxis.setVerticalTickLabels(isDomainVerticalTickLabels());
        if (getDomainTickFont() != null) {
            domainAxis.setTickLabelFont(getDomainTickFont());
        }
        final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
        if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) {
            if (getDomainMinimum() != 0) {
                domainAxis.setLowerBound(getDomainMinimum());
            }
            if (getDomainMaximum() != 1) {
                domainAxis.setUpperBound(getDomainMaximum());
            }
            if (getDomainMinimum() == 0 && getDomainMaximum() == 0) {
                domainAxis.setLowerBound(0);
                domainAxis.setUpperBound(1);
                domainAxis.setAutoRange(true);
            }
        } else {
            domainAxis.setLowerBound(getDomainMinimum());
            domainAxis.setUpperBound(getDomainMaximum());
            domainAxis.setAutoRange(isDomainAxisAutoRange());
        }
    }

    final ValueAxis rangeAxis = plot.getRangeAxis();
    if (rangeAxis instanceof NumberAxis) {
        final NumberAxis numberAxis = (NumberAxis) rangeAxis;
        numberAxis.setAutoRangeIncludesZero(isRangeIncludesZero());
        numberAxis.setAutoRangeStickyZero(isRangeStickyZero());

        if (getRangePeriodCount() > 0) {
            if (getRangeTickFormat() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(getRangePeriodCount(), getRangeTickFormat()));
            } else if (getRangeTickFormatString() != null) {
                final FastDecimalFormat formatter = new FastDecimalFormat(getRangeTickFormatString(),
                        getResourceBundleFactory().getLocale());
                numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount()));
            }
        } else {
            if (getRangeTickFormat() != null) {
                numberAxis.setNumberFormatOverride(getRangeTickFormat());
            } else if (getRangeTickFormatString() != null) {
                final DecimalFormat formatter = new DecimalFormat(getRangeTickFormatString(),
                        new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setNumberFormatOverride(formatter);
                standardTickUnitsApplyFormat(numberAxis, formatter);
            }
        }
    } else if (rangeAxis instanceof DateAxis) {
        final DateAxis numberAxis = (DateAxis) rangeAxis;

        if (getRangePeriodCount() > 0 && getRangeTimePeriod() != null) {
            if (getRangeTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()),
                        (int) getRangePeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(
                        new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount()));
            }
        } else {
            if (getRangeTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setDateFormatOverride(formatter);
            }
        }
    }

    if (rangeAxis != null) {
        rangeAxis.setLabel(getRangeTitle());
        if (getRangeTitleFont() != null) {
            rangeAxis.setLabelFont(getRangeTitleFont());
        }
        if (getRangeTickFont() != null) {
            rangeAxis.setTickLabelFont(getRangeTickFont());
        }
        final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
        if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) {
            if (getRangeMinimum() != 0) {
                rangeAxis.setLowerBound(getRangeMinimum());
            }
            if (getRangeMaximum() != 1) {
                rangeAxis.setUpperBound(getRangeMaximum());
            }
            if (getRangeMinimum() == 0 && getRangeMaximum() == 0) {
                rangeAxis.setLowerBound(0);
                rangeAxis.setUpperBound(1);
                rangeAxis.setAutoRange(true);
            }
        } else {
            rangeAxis.setLowerBound(getRangeMinimum());
            rangeAxis.setUpperBound(getRangeMaximum());
            rangeAxis.setAutoRange(isRangeAxisAutoRange());
        }
    }

    final String[] colors = getSeriesColor();
    for (int i = 0; i < colors.length; i++) {
        renderer.setSeriesPaint(i, parseColorFromString(colors[i]));
    }
}

From source file:org.drools.planner.benchmark.statistic.bestscore.BestScoreStatistic.java

private CharSequence writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) {
    NumberAxis xAxis = new NumberAxis("Time millis spend");
    xAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    NumberAxis yAxis = new NumberAxis("Score");
    yAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    int seriesIndex = 0;
    for (Map.Entry<String, BestScoreStatisticListener> listenerEntry : bestScoreStatisticListenerMap
            .entrySet()) {//  w w w.j  av a  2 s  . c om
        String configName = listenerEntry.getKey();
        XYSeries series = new XYSeries(configName);
        List<BestScoreStatisticPoint> statisticPointList = listenerEntry.getValue().getStatisticPointList();
        for (BestScoreStatisticPoint statisticPoint : statisticPointList) {
            long timeMillisSpend = statisticPoint.getTimeMillisSpend();
            Score score = statisticPoint.getScore();
            Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
            if (scoreGraphValue != null) {
                series.add(timeMillisSpend, scoreGraphValue);
            }
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer;
        // No direct lines between 2 points
        renderer = new XYStepRenderer();
        if (statisticPointList.size() <= 1) {
            // Workaround for https://sourceforge.net/tracker/?func=detail&aid=3387330&group_id=15494&atid=115494
            renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
        }
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(baseName + " best score statistic", JFreeChart.DEFAULT_TITLE_FONT, plot,
            true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "BestScoreStatistic.png");
    OutputStream out = null;
    try {
        out = new FileOutputStream(graphStatisticFile);
        ImageIO.write(chartImage, "png", out);
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing graphStatisticFile: " + graphStatisticFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
    return "  <img src=\"" + graphStatisticFile.getName() + "\"/>\n";
}

From source file:org.drools.planner.benchmark.core.statistic.BenchmarkReport.java

private void writeScalabilitySummaryChart() {
    NumberAxis xAxis = new NumberAxis("Problem scale");
    xAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    NumberAxis yAxis = new NumberAxis("Time spend");
    yAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat(locale));
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    int seriesIndex = 0;
    for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) {
        String solverLabel = solverBenchmark.getNameWithFavoriteSuffix();
        XYSeries series = new XYSeries(solverLabel);
        for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) {
            if (singleBenchmark.isSuccess()) {
                long problemScale = singleBenchmark.getProblemBenchmark().getProblemScale();
                long timeMillisSpend = singleBenchmark.getTimeMillisSpend();
                series.add((Long) problemScale, (Long) timeMillisSpend);
            }//from   ww  w . ja v a 2 s. c  om
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
        // Use dashed line
        renderer.setSeriesStroke(0, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 2.0f, 6.0f }, 0.0f));
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart("Scalability summary (lower is better)", JFreeChart.DEFAULT_TITLE_FONT,
            plot, true);
    scalabilitySummaryChartFile = writeChartToImageFile(chart, "scalabilitySummary");
}

From source file:org.drools.planner.benchmark.core.statistic.PlannerStatistic.java

private void writeAverageCalculateCountPerSecondSummaryChart() {
    NumberAxis xAxis = new NumberAxis("Problem scale");
    NumberAxis yAxis = new NumberAxis("Average calculate count per second");
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    int seriesIndex = 0;
    for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) {
        String solverLabel = solverBenchmark.getName();
        if (solverBenchmark.isRankingBest()) {
            solverLabel += " (winner)";
        }/* ww w. j a  v a 2 s  .c o  m*/
        XYSeries series = new XYSeries(solverLabel);
        for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) {
            if (singleBenchmark.isSuccess()) {
                long problemScale = singleBenchmark.getProblemScale();
                long averageCalculateCountPerSecond = singleBenchmark.getAverageCalculateCountPerSecond();
                series.add((Long) problemScale, (Long) averageCalculateCountPerSecond);
            }
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
        // Use dashed line
        renderer.setSeriesStroke(0, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 2.0f, 6.0f }, 0.0f));
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart("Average calculate count summary (higher is better)",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    averageCalculateCountSummaryFile = new File(plannerBenchmark.getBenchmarkReportDirectory(),
            "averageCalculateCountSummary.png");
    OutputStream out = null;
    try {
        out = new FileOutputStream(averageCalculateCountSummaryFile);
        ImageIO.write(chartImage, "png", out);
    } catch (IOException e) {
        throw new IllegalArgumentException(
                "Problem writing averageCalculateCountSummaryFile: " + averageCalculateCountSummaryFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:org.drools.planner.benchmark.core.statistic.BenchmarkReport.java

private void writeAverageCalculateCountPerSecondSummaryChart() {
    NumberAxis xAxis = new NumberAxis("Problem scale");
    xAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    NumberAxis yAxis = new NumberAxis("Average calculate count per second");
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    int seriesIndex = 0;
    for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) {
        String solverLabel = solverBenchmark.getNameWithFavoriteSuffix();
        XYSeries series = new XYSeries(solverLabel);
        for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) {
            if (singleBenchmark.isSuccess()) {
                long problemScale = singleBenchmark.getProblemBenchmark().getProblemScale();
                long averageCalculateCountPerSecond = singleBenchmark.getAverageCalculateCountPerSecond();
                series.add((Long) problemScale, (Long) averageCalculateCountPerSecond);
            }//  ww  w . j a  v  a 2 s .  co  m
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(series);
        plot.setDataset(seriesIndex, seriesCollection);
        XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
        // Use dashed line
        renderer.setSeriesStroke(0, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 2.0f, 6.0f }, 0.0f));
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart("Average calculate count summary (higher is better)",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    averageCalculateCountSummaryChartFile = writeChartToImageFile(chart, "averageCalculateCountSummary");
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java

private void plotOrientationChanged(PlotOrientation orientation) {
    JFreeChart chart = getCurrentChart();
    if (chart != null) {
        Plot plot = chart.getPlot();/*from   w  w w. j  av a  2  s .c om*/
        if (plot instanceof CategoryPlot) {
            CategoryPlot categoryPlot = (CategoryPlot) plot;
            categoryPlot.setOrientation(orientation);
        } else if (plot instanceof XYPlot) {
            XYPlot xyPlot = (XYPlot) plot;
            xyPlot.setOrientation(orientation);
        }
    }

}

From source file:com.jtstand.swing.StatsPanel.java

public JFreeChart getChartValues(Iterator<TestStepInstance> values) {
    if (values == null || !values.hasNext()) {
        return null;
    }// w  w w .  j  ava  2  s.c  o  m

    XYSeriesCollection dataset = new XYSeriesCollection();
    int count = 0;
    TreeMap<String, XYSeries> map = new TreeMap<String, XYSeries>();
    while (values.hasNext()) {
        TestStepInstance step = values.next();
        Number num = getNumber(step);
        if (num != null) {
            String groupName = getGroupName(step);
            XYSeries pop = map.get(groupName);
            if (pop == null) {
                pop = new XYSeries(groupName);
                map.put(groupName, pop);
            }

            pop.add(++count, num.doubleValue());
        }

    }
    for (Iterator<XYSeries> it = map.values().iterator(); it.hasNext();) {
        dataset.addSeries(it.next());
    }

    //        NumberAxis xAxis = new NumberAxis("#");
    NumberAxis xAxis = new NumberAxis();
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(getValueString());
    yAxis.setAutoRangeIncludesZero(false);
    XYLineAndShapeRenderer renderer6 = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer6);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairVisible(true);
    renderer6.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    renderer6.setBaseSeriesVisibleInLegend(false);

    //        StandardXYItemLabelGenerator itemlabels=new StandardXYItemLabelGenerator();
    //        renderer.setBaseItemLabelGenerator(itemlabels);
    //        renderer.setBaseItemLabelsVisible(true);

    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, isGrouping());
    //chart.setTitle(title);
    placeLimitMarkers(plot, true);
    /* coloring */
    if (isCategorization()) {
        //            TreeMap<String, Color> cmap = new TreeMap<String, Color>();
        int i = 0;
        for (Iterator<String> it = catstats.keySet().iterator(); it.hasNext(); i++) {
            String groupName = it.next();
            Color c = ChartCategories.getColor(i);
            for (int j = 0; j < dataset.getSeriesCount(); j++) {
                XYSeries s = dataset.getSeries(j);
                if (s.getKey().equals(groupName)) {
                    renderer6.setSeriesPaint(j, c);
                }
            }
        }
    } else {
        renderer6.setSeriesPaint(0, ChartCategories.getColor(0));
    }
    chart.setTextAntiAlias(false);
    return chart;
}

From source file:com.jtstand.swing.StatsPanel.java

public JFreeChart getChartDistribution(boolean horizontal) {
    //        System.out.println("Min: " + minValue());
    //        System.out.println("Max: " + maxValue());
    XYIntervalSeriesCollection datasetDistribution = createIntervalXYDatasetDistribution(horizontal);
    XYSeriesCollection dataset2 = createXYDatasetGauss(horizontal);
    // create the chart...
    NumberAxis xAxis = new NumberAxis(getValueString());
    xAxis.setAutoRangeIncludesZero(false);
    //        NumberAxis yAxis = new NumberAxis("Distribution");
    NumberAxis yAxis = new NumberAxis();
    yAxis.setAutoRangeIncludesZero(true);
    //XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer = new MyBarRenderer();
    XYPlot plot = new XYPlot(datasetDistribution, xAxis, yAxis, renderer);
    plot.setOrientation(horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL);
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, isGrouping());
    chart.setBackgroundPaint((Paint) UIManager.get("Panel.background"));
    //        plot.setBackgroundPaint(Color.white);
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    StandardXYItemLabelGenerator itemlabels = new StandardXYItemLabelGenerator();
    renderer.setBaseItemLabelGenerator(itemlabels);
    renderer.setBaseItemLabelsVisible(true);
    plot.setDataset(1, dataset2);/*from   www.j  a v  a  2 s . c o m*/
    plot.mapDatasetToRangeAxis(1, 1);
    //        ValueAxis domainAxis = plot.getDomainAxis();
    //domainAxis.setCategoryLabelPositions(horizontal?CategoryLabelPositions.STANDARD:CategoryLabelPositions.UP_90);
    ValueAxis axis2 = new NumberAxis("Gaussian");
    plot.setRangeAxis(1, axis2);
    axis2.setVisible(false);
    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    //renderer2.setShapesVisible(false);
    //renderer2.setSeriesVisibleInLegend(false);
    renderer2.setBaseSeriesVisibleInLegend(false);
    //renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    plot.setRenderer(1, renderer2);
    renderer.setUseYInterval(true);
    renderer.setBaseSeriesVisibleInLegend(false);
    /* coloring */
    Color c;
    if (isMultipleCategorization()) {
        //            TreeMap<String, Color> cmap = new TreeMap<String, Color>();
        int i = 0;
        for (Iterator<String> it = catstats.keySet().iterator(); it.hasNext(); i++) {
            String groupName = it.next();
            c = ChartCategories.getColor(i);
            for (int j = 0; j < datasetDistribution.getSeriesCount(); j++) {
                XYIntervalSeries s = datasetDistribution.getSeries(j);
                if (s.getKey().equals(groupName)) {
                    GradientPaint gp = new GradientPaint(0.0f, 0.0f, c, 0.0f, 0.0f, c.darker().darker());
                    renderer.setSeriesPaint(j, gp);
                }
            }
            for (int j = 0; j < dataset2.getSeriesCount(); j++) {
                XYSeries s = dataset2.getSeries(j);
                if (s.getKey().equals(groupName)) {
                    renderer2.setSeriesPaint(j, c);
                    renderer2.setSeriesShapesVisible(j, false);
                    renderer2.setSeriesStroke(j, myStroke);
                }
            }
        }
        c = Color.black;
    } else {
        c = ChartCategories.getColor(0);
        GradientPaint gp = new GradientPaint(0.0f, 0.0f, c, 0.0f, 0.0f, c.darker().darker());
        renderer.setSeriesPaint(0, gp);
    }
    renderer2.setSeriesPaint(0, c);
    renderer2.setSeriesShapesVisible(0, false);
    renderer2.setSeriesStroke(0, myStroke);

    placeLimitMarkers(plot, false);
    //        renderer.setAutoPopulateSeriesOutlinePaint(true);
    //        renderer.setBaseOutlinePaint(Color.black);
    //        renderer.setSeriesOutlinePaint(0, Color.black, true);
    //        renderer.setDrawBarOutline(true);

    renderer.setHighlightedItem(0, 0);
    yAxis.setAutoRange(false);
    yAxis.setAutoRange(true);
    xAxis.setRange(leftValue(0), rightValue(numberOfCategories - 1));
    chart.setTextAntiAlias(false);
    return chart;
}

From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java

protected void customizeXYPlot(ChartPanel chartPanel, ChartDefinition cd, XYPlot plot) {
    PlotInformation pi = cd.getPlotInformation();

    customizeBasicPlot(plot, pi);/*from   w  w  w.  ja  v a2s  .c o  m*/
    plot.clearRangeMarkers();
    plot.clearDomainMarkers();

    PlotOrientation po = cd.isVertical() ? PlotOrientation.VERTICAL : PlotOrientation.HORIZONTAL;

    plot.setOrientation(po);

    boolean showGrid = (pi == null) ? true : pi.isShowGridLines();

    if (showGrid) {
        Color c = getGridColor(pi);
        UIStroke stroke = getGridStroke(pi);

        plot.setRangeGridlinePaint(c);
        plot.setDomainGridlinePaint(c);

        Stroke s = SwingHelper.getStroke(stroke);

        plot.setRangeGridlineStroke(s);
        plot.setDomainGridlineStroke(s);
    } else {
        plot.setRangeGridlinesVisible(false);
        plot.setDomainGridlinesVisible(false);
    }

    if (pi != null) {
        Color c = pi.getBorderColor();

        if (c != null) {
            plot.setOutlinePaint(c);
        }
    }

    int angle = cd.getDomainAxis().getAngle();

    if ((angle != 0) && (angle != 180)) {
        plot.getDomainAxis().setLabelAngle(((angle) / 180f) * Math.PI);
    } else {
        plot.getDomainAxis().setLabelAngle(0);
    }

    angle = cd.getRangeAxis().getAngle();

    if ((angle > 0) && (angle != 180)) {
        plot.getRangeAxis().setLabelAngle(((angle) / 180f) * Math.PI);
    } else {
        plot.getRangeAxis().setLabelAngle(0);
    }

    updateMarkers(cd, plot, true);
    updateMarkers(cd, plot, false);
    customizeXYLineAndShapeRenderer(cd, plot, pi);
    customizeSeriesAttributes(chartPanel, cd, plot, plot.getDatasetCount() > 1);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
}