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.dgrether.analysis.charts.DgDefaultAxisBuilder.java

public CategoryAxis createCategoryAxis(String xLabel) {
    CategoryAxis categoryAxis = new CategoryAxis(xLabel);
    categoryAxis.setCategoryMargin(0.05); // percentage of space between categories
    categoryAxis.setLowerMargin(0.01); // percentage of space before first bar
    categoryAxis.setUpperMargin(0.01); // percentage of space after last bar
    categoryAxis.setLabelFont(labelFont);
    categoryAxis.setTickLabelFont(axisFont);
    return categoryAxis;
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithBoxAndWhiskerChart.java

protected void init() {
    dataset = new DefaultBoxAndWhiskerCategoryDataset();

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);/*from  w  w  w .  ja  v  a 2  s . co m*/
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryAxis xAxis = new CategoryAxis("Type");
    final NumberAxis yAxis = new NumberAxis("Value");
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    final JFreeChart chart = new JFreeChart(getName(), new Font("SansSerif", Font.BOLD, 14), plot, true);

    init(chart.getPlot());
}

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

private static JFreeChart createChart(CategoryDataset categorydataset, CategoryDataset categorydataset1) {
    CategoryAxis categoryaxis = new CategoryAxis("Category");
    NumberAxis numberaxis = new NumberAxis("Value");
    GroupedStackedBarRenderer groupedstackedbarrenderer = new GroupedStackedBarRenderer();
    KeyToGroupMap keytogroupmap = new KeyToGroupMap("G1");
    keytogroupmap.mapKeyToGroup("Series 1A", "G1");
    keytogroupmap.mapKeyToGroup("Series 1B", "G1");
    keytogroupmap.mapKeyToGroup("NOTHING", "G2");
    groupedstackedbarrenderer.setSeriesToGroupMap(keytogroupmap);
    CategoryPlot categoryplot = new CategoryPlot(categorydataset, categoryaxis, numberaxis,
            groupedstackedbarrenderer) {

        private static final long serialVersionUID = 1L;

        public LegendItemCollection getLegendItems() {
            LegendItemCollection legenditemcollection = new LegendItemCollection();
            legenditemcollection.addAll(getRenderer().getLegendItems());
            CategoryDataset categorydataset2 = getDataset(1);
            if (categorydataset2 != null) {
                CategoryItemRenderer categoryitemrenderer = getRenderer(1);
                if (categoryitemrenderer != null) {
                    org.jfree.chart.LegendItem legenditem = categoryitemrenderer.getLegendItem(1, 1);
                    legenditemcollection.add(legenditem);
                }/*  w w w  . j a  v a  2s  .com*/
            }
            return legenditemcollection;
        }

    };
    JFreeChart jfreechart = new JFreeChart("Dual Axis Bar Chart", categoryplot);
    categoryplot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    categoryplot.setDataset(1, categorydataset1);
    categoryplot.mapDatasetToRangeAxis(1, 1);
    NumberAxis numberaxis1 = new NumberAxis("Secondary");
    categoryplot.setRangeAxis(1, numberaxis1);
    categoryplot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    BarRenderer barrenderer = new BarRenderer();
    categoryplot.setRenderer(1, barrenderer);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:peakml.util.jfreechart.FastErrorBarPlot.java

public FastErrorBarPlot(String xlabel, String ylabel) {
    // create the x-axis
    xaxis = new CategoryAxis(xlabel);
    xaxis.setPlot(this);
    xaxis.addChangeListener(this);

    // create the y-axis
    yaxis = new NumberAxis(ylabel);
    yaxis.setPlot(this);
    yaxis.setAutoRange(false);//from  www. j av  a2s.  c o m
    yaxis.addChangeListener(this);
}

From source file:unalcol.termites.boxplots.HybridRoundNumberReport.java

/**
 * Creates a new demo./*from  ww w  .j  a v a  2  s  .com*/
 *
 * @param title the frame title.
 * @param pf
 */
public HybridRoundNumberReport(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Round number");
    final NumberAxis yAxis = new NumberAxis("");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 14);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Round Number" + getTitle(pf), new Font("SansSerif", Font.BOLD, 18),
            plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);

    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("roundnumber1" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 1350, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(HybridRoundNumberReport.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(HybridRoundNumberReport.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:unalcol.termites.boxplots.ECALinfoCollected.java

/**
 * Creates a new demo.//  w  w w.ja  v a 2  s  .  c  o m
 *
 * @param title the frame title.
 * @param pf
 */
public ECALinfoCollected(final String title, ArrayList<Double> pf) {
    super(title);
    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);
    final CategoryAxis xAxis = new CategoryAxis("");
    final NumberAxis yAxis = new NumberAxis("");
    //final NumberAxis yAxis = new NumberAxis("Information Collected");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 16);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Information Collected " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);
    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);
    FileOutputStream output;
    try {
        output = new FileOutputStream("ECALinfoColl" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ECALinfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ECALinfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:playground.yu.utils.charts.DoubleBarChart.java

public DoubleBarChart(final String categoryAxisLabel, final String[] valueAxisLabels, final String[] categories,
        final int numberOfSubPlots) {
    this.plot = new CombinedDomainCategoryPlot(new CategoryAxis(categoryAxisLabel));
    this.subCharts = new BarChart[numberOfSubPlots];
    for (int i = 0; i < numberOfSubPlots; i++)
        subCharts[i] = new BarChart(null, null, valueAxisLabels[i], categories);
}

From source file:org.matsim.analysis.LegHistogramChart.java

static JFreeChart getGraphic(final LegHistogram.DataFrame dataFrame, final String mode, int iteration) {
    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 < dataFrame.countsDep.length; i++) {
        onRoute = onRoute + dataFrame.countsDep[i] - dataFrame.countsArr[i] - dataFrame.countsStuck[i];
        double hour = i * dataFrame.binSize / 60.0 / 60.0;
        departuresSerie.add(hour, dataFrame.countsDep[i]);
        arrivalsSerie.add(hour, dataFrame.countsArr[i]);
        onRouteSerie.add(hour, onRoute);
    }/*  ww w  .ja  v a2  s . c o m*/

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

    final JFreeChart chart = ChartFactory.createXYStepChart("Leg Histogram, " + mode + ", it." + iteration,
            "time", "# persons", 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:unalcol.termites.boxplots.ECALAgentsRight.java

/**
 * Creates a new demo./*w  w  w.  j  av  a2  s . c  o  m*/
 *
 * @param title the frame title.
 * @param pf
 */
public ECALAgentsRight(final String title, ArrayList<Double> pf) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf);

    final CategoryAxis xAxis = new CategoryAxis("");
    //        final NumberAxis yAxis = new NumberAxis("Round number");
    final NumberAxis yAxis = new NumberAxis("");

    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    Font font = new Font("Dialog", Font.PLAIN, 13);
    xAxis.setTickLabelFont(font);
    yAxis.setTickLabelFont(font);
    yAxis.setLabelFont(font);

    final JFreeChart chart = new JFreeChart("Agents Right " + getTitle(pf),
            new Font("SansSerif", Font.BOLD, 18), plot, true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));
    setContentPane(chartPanel);
    TextTitle legendText = null;
    if (pf.size() == 1) {
        legendText = new TextTitle("Population Size");
    } else {
        legendText = new TextTitle("Population Size - Probability of Failure");
    }

    legendText.setFont(font);
    legendText.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendText);
    chart.getLegend().setItemFont(font);

    FileOutputStream output;
    try {
        output = new FileOutputStream("ECALright" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ECALAgentsRight.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ECALAgentsRight.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:de.hs.mannheim.modUro.controller.diagram.BoxAndWhiskerPlotController.java

/**
 * Plots Data for Chart/*from ww w.  j a  v a  2s.  c om*/
 */
private void boxWhiskerPlot() {
    BoxAndWhiskerCategoryDataset dataset = createDataset();
    CategoryAxis xAxis = new CategoryAxis("Model");
    NumberAxis yAxis = new NumberAxis("Fitness");
    yAxis.setRange(0.0, 1.0);

    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setMaximumBarWidth(0.2);
    renderer.setItemMargin(0.5);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);

    final JFreeChart chart = new JFreeChart("Model comparison", new Font("Palatino", Font.BOLD, 14), plot,
            true);
    chart.removeLegend();

    ChartViewer viewer = new ChartViewer(chart, this);
    boxWhiskerPane.setCenter(viewer);
}