Example usage for org.jfree.chart.axis CategoryAxis CategoryAxis

List of usage examples for org.jfree.chart.axis CategoryAxis CategoryAxis

Introduction

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

Prototype

public CategoryAxis(String label) 

Source Link

Document

Constructs a category axis, using default values where necessary.

Usage

From source file:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 *//*from w  w  w.j a  v a  2s .com*/
private JFreeChart getGraphic(String[] modeNames, int inputData[][]) {

    /*
     * Write only the number of defined picture bins to the plot.
     */
    int data[][];
    data = new int[inputData.length][];
    for (int i = 0; i < inputData.length; i++) {
        if (inputData[i].length > this.nofPictureBins) {
            data[i] = Arrays.copyOfRange(inputData[i], 0, this.nofPictureBins);
        } else
            data[i] = inputData[i];
    }

    final XYSeriesCollection xyData = new XYSeriesCollection();

    for (int j = 0; j < modeNames.length; j++) {
        String modeName = modeNames[j];
        int[] d = data[j];

        XYSeries dataSerie = new XYSeries(modeName, false, true);

        for (int i = 0; i < d.length; i++) {
            double hour = i * this.binSize / 60.0 / 60.0;
            dataSerie.add(hour, d[i]);
        }

        xyData.addSeries(dataSerie);
    }

    final JFreeChart chart = ChartFactory.createXYStepChart(
            "agents in evacuated area, all modes, it." + this.iteration, "time", "# agents", xyData,
            PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.SuperBoxAndWhiskerChart.java

protected JFreeChart createLegend(BoxAndWhiskerCategoryDataset dataset) {

    CategoryAxis domainAxis = new CategoryAxis(null);
    NumberAxis rangeAxis = new NumberAxis("Value");
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
    JFreeChart chart = new JFreeChart(chartTitle, plot);

    System.out.println(SERIES_COUNT + "," + CATEGORY_COUNT);
    renderer.setLegendItemLabelGenerator(
            new SOCRCategoryCellLabelGenerator(dataset, values_storage, SERIES_COUNT, CATEGORY_COUNT));

    return chart;

}

From source file:org.matsim.contrib.freight.usecases.analysis.LegHistogram.java

private JFreeChart getGraphic(final ModeData modeData, final String modeName) {
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries departuresSerie = new XYSeries("departures", false, true);
    final XYSeries arrivalsSerie = new XYSeries("arrivals", false, true);
    final XYSeries onRouteSerie = new XYSeries("en route", false, true);
    int onRoute = 0;
    for (int i = 0; i < modeData.countsDep.length; i++) {
        onRoute = onRoute + modeData.countsDep[i] - modeData.countsArr[i] - modeData.countsStuck[i];
        double hour = i * this.binSize / 60.0 / 60.0;
        departuresSerie.add(hour, modeData.countsDep[i]);
        arrivalsSerie.add(hour, modeData.countsArr[i]);
        onRouteSerie.add(hour, onRoute);
    }/*from   ww  w .  ja  v a  2  s  .c o  m*/

    xyData.addSeries(departuresSerie);
    xyData.addSeries(arrivalsSerie);
    xyData.addSeries(onRouteSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart(
            "Leg Histogram, " + modeName + ", it." + this.iteration, "time", "# vehicles", xyData,
            PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));

    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);

    return chart;
}

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

private void writeTimeSpendSummaryChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) {
        for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) {
            if (singleBenchmark.isSuccess()) {
                long timeMillisSpend = singleBenchmark.getTimeMillisSpend();
                String solverLabel = solverBenchmark.getName();
                if (solverBenchmark.isRankingBest()) {
                    solverLabel += " (winner)";
                }/*from ww  w .ja v  a 2 s  . c  o  m*/
                String planningProblemLabel = singleBenchmark.getProblemBenchmark().getName();
                dataset.addValue(timeMillisSpend, solverLabel, planningProblemLabel);
            }
        }
    }
    CategoryAxis xAxis = new CategoryAxis("Data");
    NumberAxis yAxis = new NumberAxis("Time spend");
    yAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
    BarRenderer renderer = new BarRenderer();
    ItemLabelPosition positiveItemLabelPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
            TextAnchor.BOTTOM_CENTER);
    renderer.setBasePositiveItemLabelPosition(positiveItemLabelPosition);
    ItemLabelPosition negativeItemLabelPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
            TextAnchor.TOP_CENTER);
    renderer.setBaseNegativeItemLabelPosition(negativeItemLabelPosition);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING,
            new MillisecondsSpendNumberFormat()));
    renderer.setBaseItemLabelsVisible(true);
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart("Time spend summary (lower time is better)",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    BufferedImage chartImage = chart.createBufferedImage(1024, 768);
    timeSpendSummaryFile = new File(plannerBenchmark.getBenchmarkReportDirectory(), "timeSpendSummary.png");
    OutputStream out = null;
    try {
        out = new FileOutputStream(timeSpendSummaryFile);
        ImageIO.write(chartImage, "png", out);
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing timeSpendSummaryFile: " + timeSpendSummaryFile, e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:org.locationtech.udig.processingtoolbox.tools.BoxPlotDialog.java

private void updateChart(SimpleFeatureCollection features, String[] fields) {
    // Setup Box plot
    int fontStyle = java.awt.Font.BOLD;
    FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0];

    CategoryAxis xPlotAxis = new CategoryAxis(EMPTY); // Type
    xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 12));

    NumberAxis yPlotAxis = new NumberAxis("Value"); // Value //$NON-NLS-1$
    yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));
    yPlotAxis.setAutoRangeIncludesZero(false);

    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setMedianVisible(true);//from  ww w .j  a  v a 2  s.co  m
    renderer.setMeanVisible(false);
    renderer.setFillBox(true);
    renderer.setSeriesFillPaint(0, java.awt.Color.CYAN);
    renderer.setBaseFillPaint(java.awt.Color.CYAN);
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());

    // Set the scatter data, renderer, and axis into plot
    CategoryDataset dataset = getDataset(features, fields);
    CategoryPlot plot = new CategoryPlot(dataset, xPlotAxis, yPlotAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setRangePannable(false);

    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setForegroundAlpha(0.85f);

    // Map the scatter to the first Domain and first Range
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    // 3. Setup Selection
    /*****************************************************************************************
     * CategoryAxis xSelectionAxis = new CategoryAxis(EMPTY);
     * xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false);
     * 
     * NumberAxis ySelectionAxis = new NumberAxis(EMPTY);
     * ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false);
     * 
     * BoxAndWhiskerRenderer selectionRenderer = new BoxAndWhiskerRenderer();
     * selectionRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 6, 6));
     * selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot
     * 
     * plot.setDataset(2, new DefaultBoxAndWhiskerCategoryDataset()); plot.setRenderer(2,
     * selectionRenderer); plot.setDomainAxis(2, xSelectionAxis); plot.setRangeAxis(2,
     * ySelectionAxis);
     * 
     * // Map the scatter to the second Domain and second Range plot.mapDatasetToDomainAxis(2,
     * 0); plot.mapDatasetToRangeAxis(2, 0);
     *****************************************************************************************/

    // 5. Finally, Create the chart with the plot and a legend
    java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20);
    JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false);
    chart.setBackgroundPaint(java.awt.Color.WHITE);
    chart.setBorderVisible(false);

    chartComposite.setChart(chart);
    chartComposite.forceRedraw();
}

From source file:com.ewcms.plugin.report.generate.service.chart.ChartGenerationService.java

/**
 * /*from   w w w. jav a 2 s.c o  m*/
 *
 * @param title 
 * @param titleFont 
 * @param categoryAxisLabel 
 * @param valueAxisLabel 
 * @param data ??
 * @param orientation ?
 * @param legend 
 * @param tooltips ????
 * @param urls ??URL
 * @param urlGenerator
 *
 * @return 
 */
public static JFreeChart createLineChart(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 CategoryAxis(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    LineAndShapeRenderer renderer = new LineAndShapeRenderer();
    //        renderer.setLinesVisible(true);
    renderer.setBaseLinesVisible(true);
    //        renderer.setShapesVisible(false);
    renderer.setBaseShapesVisible(false);
    if (tooltips) {
        //            renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        //            renderer.setItemURLGenerator(urlGenerator);
        renderer.setBaseItemURLGenerator(urlGenerator);
    }
    CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;

}

From source file:playground.johannes.socialnets.GraphStatistics.java

public static JFreeChart makeChart(Histogram1D hist, String title) {
    final XYSeriesCollection data = new XYSeriesCollection();
    final XYSeries wave = new XYSeries(title, false, true);

    for (int i = 0; i < 100; i++) {
        wave.add(hist.xAxis().binCentre(i), hist.binHeight(i));
    }/*  w ww  .j a  v  a  2  s  .  c o m*/

    data.addSeries(wave);

    final JFreeChart chart = ChartFactory.createXYStepChart("title", "x", "y", data, PlotOrientation.VERTICAL,
            true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("x");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("y"));
    return chart;
}

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

/**
 * Creates a line chart with default settings.
 *
 * @param title  the chart title./*from w w  w.  j a  v a  2  s.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 line chart.
 */
public static JFreeChart createLineChart(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 CategoryAxis(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    LineAndShapeRenderer renderer = new LineAndShapeRenderer();
    renderer.setLinesVisible(true);
    renderer.setShapesVisible(false);
    if (tooltips) {
        renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setItemURLGenerator(urlGenerator);
    }
    CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;

}

From source file:FaceRatios.java

public PropertyBoxWhisker(String propertyName, BoxAndWhiskerCategoryDataset dataset) {
    super(propertyName);
    final CategoryAxis xAxis = new CategoryAxis("Face");
    final NumberAxis yAxis = new NumberAxis("Value");
    yAxis.setAutoRangeIncludesZero(false);

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);/*ww  w.  j  a v a 2 s.c  o m*/
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    final JFreeChart chart = new JFreeChart(propertyName, new Font("SansSerif", Font.BOLD, 14), plot, true);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(900, 540));
    setContentPane(chartPanel);
}

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java

private static JFreeChart createStackedBarChart(CategoryDataset dataset) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    StackedBarRenderer renderer = new StackedBarRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }// w w w  .  jav  a  2 s  . c o  m
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart("StackedBar Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    renderer.setDrawBarOutline(false);

    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    return chart;

}