Example usage for org.jfree.chart JFreeChart JFreeChart

List of usage examples for org.jfree.chart JFreeChart JFreeChart

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart JFreeChart.

Prototype

public JFreeChart(String title, Font titleFont, Plot plot, boolean createLegend) 

Source Link

Document

Creates a new chart with the given title and plot.

Usage

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

/**
 * Creates a ContourPlot chart.//from w  w  w  .  ja  v  a 2 s. co m
 *
 * @return the chart.
 */
private JFreeChart createContourPlot() {

    final String title = "Contour Plot";
    final String xAxisLabel = "X Values";
    final String yAxisLabel = "Y Values";
    final String zAxisLabel = "Color Values";

    if (xIsDate) {
        this.xAxis = new DateAxis(xAxisLabel);
        xIsLog = false; // force axis to be linear when displaying dates
    } else {
        if (xIsLog) {
            this.xAxis = new LogarithmicAxis(xAxisLabel);
        } else {
            this.xAxis = new NumberAxis(xAxisLabel);
        }
    }

    if (yIsLog) {
        this.yAxis = new LogarithmicAxis(yAxisLabel);
    } else {
        this.yAxis = new NumberAxis(yAxisLabel);
    }

    if (zIsLog) {
        this.zColorBar = new ColorBar(zAxisLabel);
    } else {
        this.zColorBar = new ColorBar(zAxisLabel);
    }

    if (this.xAxis instanceof NumberAxis) {
        ((NumberAxis) this.xAxis).setAutoRangeIncludesZero(false);
        ((NumberAxis) this.xAxis).setInverted(xIsInverted);
    }

    this.yAxis.setAutoRangeIncludesZero(false);

    this.yAxis.setInverted(yIsInverted);

    if (!xIsDate) {
        ((NumberAxis) this.xAxis).setLowerMargin(0.0);
        ((NumberAxis) this.xAxis).setUpperMargin(0.0);
    }

    this.yAxis.setLowerMargin(0.0);
    this.yAxis.setUpperMargin(0.0);

    this.zColorBar.getAxis().setInverted(zIsInverted);
    this.zColorBar.getAxis().setTickMarksVisible(true);

    final ContourDataset data = createDataset();

    final ContourPlot plot = new ContourPlot(data, this.xAxis, this.yAxis, this.zColorBar);

    if (xIsDate) {
        ratio = Math.abs(ratio); // don't use plot units for ratios when x axis is date
    }
    plot.setDataAreaRatio(ratio);

    final JFreeChart chart = new JFreeChart(title, null, plot, false);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.green));

    return chart;

}

From source file:scheduler.benchmarker.manager.CreateCombinedCategoryPlot.java

public ChartPanel createChartPanel() {
    CustomBarRenderer renderer = new CustomBarRenderer(pluginColors);
    CategoryPlot subplot1 = new CategoryPlot(createDataset1(), new CategoryAxis("Category"),
            new NumberAxis("Value"), renderer);
    subplot1.setDomainGridlinesVisible(true);

    CategoryPlot subplot2 = new CategoryPlot(createDataset2(), new CategoryAxis("Category"),
            new NumberAxis("Value"), renderer);
    subplot2.setDomainGridlinesVisible(true);

    final CategoryAxis domainAxis = new CategoryAxis("Category");
    final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
    plot.add(subplot1, 1);/*  w w w  .j  a v a 2s  . c  o  m*/
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.setFixedLegendItems(createCustomLegend());
    plot.setRenderer(renderer);

    subplot1.setBackgroundPaint(new Color(246, 244, 242));
    subplot2.setBackgroundPaint(new Color(246, 244, 242));

    subplot1.addRangeMarker(generateMarker("CLASSIFICATION FINISH FOR '" + schedNames[0] + "'",
            dataSource[0].getSumTotalTime()), Layer.FOREGROUND);
    subplot2.addRangeMarker(generateMarker("CLASSIFICATION FINISH FOR '" + schedNames[1] + "'",
            dataSource[1].getSumTotalTime()), Layer.FOREGROUND);

    final JFreeChart result = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 12), plot, true);

    cPanel = new ChartPanel(result);
    cPanel.setForeground(new Color(76, 76, 76));
    cPanel.setBackground(new Color(246, 244, 242));

    return cPanel;

}

From source file:com.tonbeller.jpivot.chart.ChartFactory.java

/**
 * Creates a vertical 3D-effect bar chart with default settings.
 *
 * @param title  the chart title./* ww  w.jav  a 2s .  c  om*/
 * @param categoryAxisLabel  the label for the category axis.
 * @param valueAxisLabel  the label for the value axis.
 * @param data  the dataset for the chart.
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return a vertical 3D-effect bar chart.
 */
public static JFreeChart createBarChart3D(String title, java.awt.Font titleFont, String categoryAxisLabel,
        String valueAxisLabel, CategoryDataset data, PlotOrientation orientation, boolean legend,
        boolean tooltips, boolean urls, CategoryURLGenerator urlGenerator) {

    CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);

    BarRenderer3D renderer = new BarRenderer3D();

    //renderer.setLabelGenerator(new StandardCategoryLabelGenerator());
    if (tooltips) {
        renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setItemURLGenerator(urlGenerator);
    }

    CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    plot.setForegroundAlpha(0.75f);

    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;

}

From source file:i2p.bote.web.PeerInfoTag.java

private String createDhtChart(DhtPeerStats dhtStats) throws IOException {
    RingPlot plot;/*from   www .j  a va  2  s. c o m*/
    int numDhtPeers = dhtStats.getData().size();
    if (numDhtPeers == 0) {
        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("", 100);

        plot = new RingPlot(dataset);
        plot.setSectionPaint("", Color.gray);
    } else {
        int reachable = 0;
        for (List<String> row : dhtStats.getData()) {
            if (_t("No").equals(row.get(4)))
                reachable += 1;
        }
        int unreachable = numDhtPeers - reachable;

        DefaultPieDataset dataset = new DefaultPieDataset();
        if (reachable > 0)
            dataset.setValue(_t("Reachable"), reachable);
        if (unreachable > 0)
            dataset.setValue(_t("Unreachable"), unreachable);

        plot = new RingPlot(dataset);
        plot.setSectionPaint(_t("Reachable"), Color.green);
        plot.setSectionPaint(_t("Unreachable"), Color.red);
    }
    plot.setLabelGenerator(null);
    plot.setShadowGenerator(null);

    JFreeChart dhtChart = new JFreeChart(_t("Kademlia Peers:"), JFreeChart.DEFAULT_TITLE_FONT, plot,
            numDhtPeers == 0 ? false : true);
    return ServletUtilities.saveChartAsPNG(dhtChart, 400, 300, null);
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.DoseResponseController.java

/**
 * Create a dose-response chart containing experimental data, simulated data
 * and an annotated R value./* w  w  w . jav  a  2  s  .  c  o  m*/
 *
 * @param dataToPlot The experimental data on which the fit was performed
 * @param analysisGroup The analysis group
 * @param normalized Whether the responses are normalized
 * @return
 */
public JFreeChart createDoseResponseChart(List<DoseResponsePair> dataToPlot,
        DoseResponseAnalysisGroup analysisGroup, boolean normalized) {
    // setup scatter data of experimental concentrations/slopes, renderer and axis
    XYSeriesCollection experimentalData = new XYSeriesCollection();
    XYSeries scatterXYSeries = JFreeChartUtils.generateXYSeries(AnalysisUtils.generateXValues(dataToPlot),
            AnalysisUtils.generateYValues(dataToPlot));
    scatterXYSeries.setKey("Experimental data");
    experimentalData.addSeries(scatterXYSeries);

    // compute how far the simulated data and axes should range: from the lowest and highest dose continue half of the range between these two
    List<Double> extremes = new ArrayList<>();
    Double range = Math.abs(scatterXYSeries.getMaxX() - scatterXYSeries.getMinX());
    extremes.add(scatterXYSeries.getMinX() - (range / 2));
    extremes.add(scatterXYSeries.getMaxX() + (range / 2));

    // Create the simulated line data, renderer, and axis
    XYSeriesCollection fitting = new XYSeriesCollection();
    // create xy series of simulated data from the parameters from the fitting
    SigmoidFittingResultsHolder resultsHolder = analysisGroup.getDoseResponseAnalysisResults()
            .getFittingResults(normalized);
    XYSeries fittingData = simulateData(resultsHolder, extremes);
    fittingData.setKey("Fitting");
    fitting.addSeries(fittingData);

    XYPlot plot = JFreeChartUtils.setupDoseResponseDatasets(experimentalData, fitting,
            getPlotAxesNames(normalized), extremes);

    // show the r squared value, put the value at a certain place between the min and max dose
    double xPlace = extremes.get(1) - range;
    double yPlace = scatterXYSeries.getMinY() + ((scatterXYSeries.getMaxY() - scatterXYSeries.getMinY()) / 4);
    plot.addAnnotation(new XYTextAnnotation(
            "R2=" + AnalysisUtils.roundThreeDecimals(AnalysisUtils.computeRSquared(dataToPlot, resultsHolder)),
            xPlace, yPlace));

    // Create the chart with the plot and no legend
    JFreeChart chart = new JFreeChart("Title", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    String title = "";
    if (normalized) {
        title = "Normalized fitting";
    } else {
        title = "Initial fitting";
    }
    JFreeChartUtils.setupDoseResponseChart(chart, title);
    return chart;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.Meter.java

/**
 * Creates the chart ./*from www . ja va2s.  c  o  m*/
 * 
 * @param chartTitle  the chart title.
 * @param dataset  the dataset.
 * 
 * @return A chart .
 */

public JFreeChart createChart(DatasetMap datasets) {

    Dataset dataset = (Dataset) datasets.getDatasets().get("1");

    MeterPlot plot = new MeterPlot((ValueDataset) dataset);
    plot.setRange(new Range(lower, upper));

    for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
        KpiInterval interval = (KpiInterval) iterator.next();

        plot.addInterval(new MeterInterval(interval.getLabel(), new Range(interval.getMin(), interval.getMax()),
                Color.lightGray, new BasicStroke(2.0f), interval.getColor()));
    }

    plot.setNeedlePaint(Color.darkGray);
    plot.setDialBackgroundPaint(Color.white);
    plot.setDialOutlinePaint(Color.gray);
    plot.setDialShape(DialShape.CHORD);
    plot.setMeterAngle(260);
    plot.setTickLabelsVisible(true);
    //set tick label style
    Font tickLabelsFont = new Font(labelsTickStyle.getFontName(), Font.PLAIN, labelsTickStyle.getSize());
    plot.setTickLabelFont(tickLabelsFont);
    plot.setTickLabelPaint(labelsTickStyle.getColor());
    plot.setTickSize(5.0);
    plot.setTickPaint(Color.lightGray);
    if (units != null) {
        plot.setUnits(units);
    }

    plot.setValuePaint(labelsValueStyle.getColor());
    plot.setValueFont(new Font(labelsValueStyle.getFontName(), Font.PLAIN, labelsValueStyle.getSize()));

    JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(color);

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    return chart;
}

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

/**
 * Creates a chart./*  ww w.  j av  a  2s  . c  o  m*/
 *
 * @return A chart.
 */
private JFreeChart createChart() {

    final CategoryDataset dataset1 = createDataset1();
    final CategoryAxis domainAxis1 = new CategoryAxis("Class 1");
    domainAxis1.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    //        domainAxis1.setMaxCategoryLabelWidthRatio(5.0f);
    final LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    final CategoryPlot subplot1 = new CategoryPlot(dataset1, domainAxis1, null, renderer1);
    subplot1.setDomainGridlinesVisible(true);

    final CategoryDataset dataset2 = createDataset2();
    final CategoryAxis domainAxis2 = new CategoryAxis("Class 2");
    domainAxis2.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    //    domainAxis2.setMaxCategoryLabelWidthRatio(5.0f);
    final BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    final CategoryPlot subplot2 = new CategoryPlot(dataset2, domainAxis2, null, renderer2);
    subplot2.setDomainGridlinesVisible(true);

    final ValueAxis rangeAxis = new NumberAxis("Value");
    final CombinedRangeCategoryPlot plot = new CombinedRangeCategoryPlot(rangeAxis);
    plot.add(subplot1, 3);
    plot.add(subplot2, 2);
    plot.setOrientation(PlotOrientation.HORIZONTAL);

    final JFreeChart result = new JFreeChart("Combined Range Category Plot Demo",
            new Font("SansSerif", Font.BOLD, 12), plot, true);
    //      result.getLegend().setAnchor(Legend.SOUTH);
    return result;

}

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 {/* www. j a va2 s .com*/
            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:net.nosleep.superanalyzer.analysis.views.YearView.java

private void createChart() {

    NumberAxis xAxis = new NumberAxis(Misc.getString("RELEASE_YEAR"));
    xAxis.setAutoRangeIncludesZero(false);

    NumberAxis yAxis = new NumberAxis(Misc.getString("SONG_COUNT"));
    yAxis.setAutoRangeIncludesZero(true);

    xAxis.setNumberFormatOverride(new DecimalFormat("0"));

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot(_dataset, xAxis, yAxis, renderer);

    // create and return the chart panel...
    _chart = new JFreeChart(Misc.getString("RELEASE_YEAR"), JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);

    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4));

    LegendTitle legend = _chart.getLegend();
    legend.setFrame(BlockBorder.NONE);/* w w  w . j  a  v  a  2  s.  c om*/

    _chart.addSubtitle(HomePanel.createSubtitle(Misc.getString("RELEASE_YEAR_TOOLTIP")));

    XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"),
            new DecimalFormat("0.00"));
    renderer.setToolTipGenerator(generator);

    ChartUtilities.applyCurrentTheme(_chart);

    // format the lines after applying the theme
    renderer.setBaseShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(Color.white);
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0));

    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesOutlineStroke(1, new BasicStroke(2.0f));
    renderer.setSeriesShape(1, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0));

    _chart.setPadding(new RectangleInsets(10, 10, 10, 10));

    Misc.formatChart(plot);
}

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

/**
 * Creates a chart./*from  w w  w.  j  a  va  2  s  .  c o m*/
 *
 * @return A chart.
 */
private JFreeChart createChart() {

    final CategoryDataset dataset1 = createDataset1();
    final NumberAxis rangeAxis1 = new NumberAxis("Value");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    final LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    final CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
    subplot1.setDomainGridlinesVisible(true);

    final CategoryDataset dataset2 = createDataset2();
    final NumberAxis rangeAxis2 = new NumberAxis("Value");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    final BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    final CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
    subplot2.setDomainGridlinesVisible(true);

    final CategoryAxis domainAxis = new CategoryAxis("Category");
    final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
    plot.add(subplot1, 2);
    plot.add(subplot2, 1);

    final JFreeChart result = new JFreeChart("Combined Domain Category Plot Demo",
            new Font("SansSerif", Font.BOLD, 12), plot, true);
    //      result.getLegend().setAnchor(Legend.SOUTH);
    return result;

}