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.artemc.socialCost.MeanTravelTimeWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 *//* w  ww .j av  a  2 s  .  c om*/
private JFreeChart getGraphic(String modeName, double data[]) {

    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries dataSerie = new XYSeries("mean trip travel time", false, true);

    for (int i = 0; i < data.length; i++) {
        dataSerie.add(i, data[i]);
    }

    xyData.addSeries(dataSerie);

    //      final JFreeChart chart = ChartFactory.createXYStepChart(
    final JFreeChart chart = ChartFactory.createXYLineChart("mean travel time, " + modeName, "iteration",
            "travel time", 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:org.openmicroscopy.shoola.util.ui.graphutils.BarPlot.java

/**
 * Creates a new instance./*from   w  w w.j  a va  2s.c o  m*/
 * 
 * @param title       The title of the graph.
 * @param newLegends    The legends of each series. 
 * @param newData       The data for each series. 
 * @param newColours    The colours for each series. 
 */
public BarPlot(String title, List<String> newLegends, List<Double> newData, List<Color> newColours) {
    super(title);
    if (newLegends == null || newData == null || newColours == null
            || newLegends.size() != newData.size() && newLegends.size() != newColours.size()
            || newLegends.size() == 0)
        throw new IllegalArgumentException("Mismatch between argument " + "length");
    initialize();
    for (int i = 0; i < newLegends.size(); i++)
        addValue(newLegends.get(i), newData.get(i), newColours.get(i));
    setDefaultAxis();
    categoryAxis = new CategoryAxis(X_AXIS);
}

From source file:org.apache.qpid.disttest.charting.chartbuilder.StatisticalBarChartBuilder.java

@Override
public JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, final Dataset dataset,
        PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) {
    CategoryAxis xAxis = new CategoryAxis(xAxisTitle);
    ValueAxis yAxis = new NumberAxis(yAxisTitle);
    CategoryItemRenderer renderer = new StatisticalBarRenderer();

    CategoryPlot plot = new CategoryPlot((StatisticalCategoryDataset) dataset, xAxis, yAxis, renderer);

    JFreeChart chart = new JFreeChart(title, new Font("Arial", Font.PLAIN, 10), plot, true);

    chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    return chart;
}

From source file:net.sf.jsfcomp.chartcreator.utils.ChartAxisUtils.java

public static void createCategorySeriesAxis(JFreeChart chart, ChartAxisData chartAxisData, int axisIndex) {
    CategoryPlot plot = chart.getCategoryPlot();
    if (chartAxisData.isDomain()) {
        CategoryAxis axis = new CategoryAxis(chartAxisData.getLabel());
        axis.setTickLabelsVisible(chartAxisData.isTickLabels());
        axis.setTickMarksVisible(chartAxisData.isTickMarks());

        if (chartAxisData.getTickLabelFontSize() > 0) {
            Font tickFont = CategoryAxis.DEFAULT_TICK_LABEL_FONT
                    .deriveFont(chartAxisData.getTickLabelFontSize());
            axis.setTickLabelFont(tickFont);
        }/*from  w  w w .  j  a  v a  2s.co m*/
        if (chartAxisData.isVerticalTickLabels()) {
            axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        }
        plot.setDomainAxis(plot.getDomainAxisCount() - 1, axis);
    } else {
        ValueAxis axis = createNumberAxis(chart, chartAxisData);
        axis.setTickLabelsVisible(chartAxisData.isTickLabels());
        axis.setTickMarksVisible(chartAxisData.isTickMarks());

        if (chartAxisData.getTickLabelFontSize() > 0) {
            Font tickFont = CategoryAxis.DEFAULT_TICK_LABEL_FONT
                    .deriveFont(chartAxisData.getTickLabelFontSize());
            axis.setTickLabelFont(tickFont);
        }
        plot.setRangeAxis(axis);
    }
}

From source file:playground.anhorni.counts.StdDevBoxPlot.java

public JFreeChart createChart() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    ArrayList<Double>[] lists = this.createArrayLists();

    // add the collected values to the graph / dataset
    for (int i = 0; i < 24; i++) {
        dataset.add(lists[i], "hour", Integer.toString(i + 1));
    }//w w  w.  j a  v  a 2 s. co  m
    final CategoryAxis xAxis = new CategoryAxis(xlabel);
    xAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 10));
    //xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    final NumberAxis yAxis = new NumberAxis(ylabel);
    yAxis.setAutoRangeIncludesZero(true);

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setSeriesPaint(0, Color.blue);
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    this.chart_ = new JFreeChart(chartTitle, new Font("SansSerif", Font.BOLD, 14), plot, false);
    return this.chart_;
}

From source file:org.matsim.counts.algorithms.graphs.BoxPlotErrorGraph.java

@SuppressWarnings("unchecked")
@Override// w  w w  . j av  a2  s. c  om
public JFreeChart createChart(final int nbr) {

    DefaultBoxAndWhiskerCategoryDataset dataset0 = new DefaultBoxAndWhiskerCategoryDataset();
    DefaultBoxAndWhiskerCategoryDataset dataset1 = new DefaultBoxAndWhiskerCategoryDataset();

    final ArrayList<Double>[] listRel = new ArrayList[24];
    final ArrayList<Double>[] listAbs = new ArrayList[24];

    // init
    for (int i = 0; i < 24; i++) {
        listRel[i] = new ArrayList<Double>();
        listAbs[i] = new ArrayList<Double>();
    }

    // add the values of all counting stations to each hour
    for (CountSimComparison cc : this.ccl_) {
        int hour = cc.getHour() - 1;
        listRel[hour].add(cc.calculateRelativeError());
        listAbs[hour].add(cc.getSimulationValue() - cc.getCountValue());
    }

    // add the collected values to the graph / dataset
    for (int i = 0; i < 24; i++) {
        dataset0.add(listRel[i], "Rel Error", Integer.toString(i + 1));
        dataset1.add(listAbs[i], "Abs Error", Integer.toString(i + 1));
    }

    String title = "Iteration: " + this.iteration_;

    final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();

    final CategoryAxis xAxis = new CategoryAxis("Hour");
    final NumberAxis yAxis0 = new NumberAxis("Signed Rel. Error [%]");
    final NumberAxis yAxis1 = new NumberAxis("Signed Abs. Error [veh]");
    yAxis0.setAutoRangeIncludesZero(false);
    yAxis1.setAutoRangeIncludesZero(false);

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesToolTipGenerator(0, new BoxAndWhiskerToolTipGenerator());

    CategoryPlot subplot0 = new CategoryPlot(dataset0, xAxis, yAxis0, renderer);
    CategoryPlot subplot1 = new CategoryPlot(dataset1, xAxis, yAxis1, renderer);

    plot.add(subplot0);
    plot.add(subplot1);

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    axis1.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    plot.setDomainAxis(axis1);

    this.chart_ = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 14), plot, false);
    return this.chart_;
}

From source file:org.amanzi.awe.charts.builder.CategoryChartBuilder.java

@Override
protected CategoryAxis configDomainAxis(String domainAxisName) {
    CategoryAxis domainAxis = new CategoryAxis(domainAxisName);
    domainAxis.setMaximumCategoryLabelWidthRatio(MAXIMUM_CATEGORY_LABEL_WIDTH);
    domainAxis.setMaximumCategoryLabelLines(MAXIMUM_CATEGORY_LABEL_LINES);
    domainAxis.setLabel(domainAxisName);
    domainAxis.setTickLabelFont(getDefaulTickLabelFont());
    domainAxis.setLabelFont(getDefaultAxisFont());
    return domainAxis;
}

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

/**
 * Creates a new demo.// ww w.  j  av  a 2s .c o  m
 */
public IntervalBarChartDemo1() {

    DefaultIntervalCategoryDataset data = null;
    final double[][] lows = { { -.0315, .0159, .0306, .0453, .0557 } };
    final double[][] highs = { { .1931, .1457, .1310, .1163, .1059 } };
    data = new DefaultIntervalCategoryDataset(lows, highs);
    data.setCategoryKeys(CATEGORIES);

    final String title = "Strategie Sicherheit";
    final String xTitle = "Zeitraum (in Jahren)";
    final String yTitle = "Performance";
    final CategoryAxis xAxis = new CategoryAxis(xTitle);
    xAxis.setLabelFont(titleFont);
    xAxis.setTickLabelFont(labelFont);
    xAxis.setTickMarksVisible(false);
    final NumberAxis yAxis = new NumberAxis(yTitle);
    yAxis.setLabelFont(titleFont);
    yAxis.setTickLabelFont(labelFont);
    yAxis.setRange(-0.2, 0.40);
    final DecimalFormat formatter = new DecimalFormat("0.##%");
    yAxis.setTickUnit(new NumberTickUnit(0.05, formatter));

    final IntervalBarRenderer renderer = new IntervalBarRenderer();
    renderer.setSeriesPaint(0, new Color(51, 102, 153));
    //        renderer.setLabelGenerator(new IntervalCategoryLabelGenerator());
    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelPaint(Color.white);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER);
    renderer.setPositiveItemLabelPosition(p);

    final CategoryPlot plot = new CategoryPlot(data, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setOutlinePaint(Color.white);
    plot.setOrientation(PlotOrientation.VERTICAL);

    this.chart = new JFreeChart(title, titleFont, plot, false);
    this.chart.setBackgroundPaint(Color.white);
}

From source file:org.matsim.counts.algorithms.graphs.BoxPlotNormalizedErrorGraph.java

@SuppressWarnings("unchecked")
@Override//from   w ww . j a  v  a  2  s  .c  o  m
public JFreeChart createChart(final int nbr) {

    DefaultBoxAndWhiskerCategoryDataset dataset0 = new DefaultBoxAndWhiskerCategoryDataset();
    DefaultBoxAndWhiskerCategoryDataset dataset1 = new DefaultBoxAndWhiskerCategoryDataset();

    final ArrayList<Double>[] listRel = new ArrayList[24];
    final ArrayList<Double>[] listAbs = new ArrayList[24];

    // init
    for (int i = 0; i < 24; i++) {
        listRel[i] = new ArrayList<Double>();
        listAbs[i] = new ArrayList<Double>();
    }

    // add the values of all counting stations to each hour
    for (CountSimComparison cc : this.ccl_) {
        int hour = cc.getHour() - 1;
        listRel[hour].add(cc.calculateNormalizedRelativeError() * 100);
        listAbs[hour].add(cc.getSimulationValue() - cc.getCountValue());
    }

    // add the collected values to the graph / dataset
    for (int i = 0; i < 24; i++) {
        dataset0.add(listRel[i], "Rel Norm Error", Integer.toString(i + 1));
        dataset1.add(listAbs[i], "Abs Error", Integer.toString(i + 1));
    }

    String title = "Iteration: " + this.iteration_;

    final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();

    final CategoryAxis xAxis = new CategoryAxis("Hour");
    final NumberAxis yAxis0 = new NumberAxis("Norm. Rel. Error [%]");
    final NumberAxis yAxis1 = new NumberAxis("Signed Abs. Error [veh]");
    yAxis0.setAutoRangeIncludesZero(false);
    yAxis1.setAutoRangeIncludesZero(false);

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesToolTipGenerator(0, new BoxAndWhiskerToolTipGenerator());

    CategoryPlot subplot0 = new CategoryPlot(dataset0, xAxis, yAxis0, renderer);
    CategoryPlot subplot1 = new CategoryPlot(dataset1, xAxis, yAxis1, renderer);

    plot.add(subplot0);
    plot.add(subplot1);

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    axis1.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    plot.setDomainAxis(axis1);

    this.chart_ = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 14), plot, false);
    return this.chart_;
}

From source file:ui.results.ResultChartPanel.java

/**
 * Construct new Result panel/* w w  w. ja  va  2 s.c om*/
 */
public ResultChartPanel() {
    // The charting objects
    dataset = new DefaultStatisticalCategoryDataset();
    upper = new DefaultCategoryDataset();
    lower = new DefaultCategoryDataset();

    // The Renderers
    lineRenderer0 = new LineAndShapeRenderer();
    lineRenderer1 = new LineAndShapeRenderer();
    lineRenderer2 = new LineAndShapeRenderer();
    lineRenderer0.setSeriesPaint(0, lowerColor);
    lineRenderer1.setSeriesPaint(0, mspColor);
    lineRenderer2.setSeriesPaint(0, upperColor);
    lineRenderer0.setSeriesShapesVisible(0, false);
    lineRenderer1.setSeriesShapesVisible(0, false);
    lineRenderer2.setSeriesShapesVisible(0, false);

    barRenderer = new StatisticalBarRenderer();
    barRenderer.setSeriesPaint(0, mspColor);

    // The Plot: begin as a line plot
    CategoryPlot plot = new CategoryPlot();
    plot.setDomainAxis(new CategoryAxis("Datasets"));
    plot.setRangeAxis(new NumberAxis("MSP"));
    plot.setRenderer(0, lineRenderer0);
    plot.setRenderer(1, lineRenderer1);
    plot.setRenderer(2, lineRenderer2);
    plot.setDataset(0, lower);
    plot.setDataset(1, dataset);
    plot.setDataset(2, upper);

    // Adding the new plot
    chart = new JFreeChart(plot);
    panel = new ChartPanel(chart);

    // Listening to changes
    //dataset.addChangeListener(chart.getPlot());
    chart.getPlot().addChangeListener(chart);
    chart.addChangeListener(panel);

    ((CategoryPlot) chart.getPlot()).getRangeAxis().setAutoRange(true);

    // Choice panel: choicing between line and bar chart
    JPanel choicePanel = createChoicePanel();

    // Doing the interface
    setLayout(new BorderLayout());
    add(choicePanel, BorderLayout.NORTH);
    add(panel, BorderLayout.CENTER);
    setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Chart"));

    // size stuff
    //setPreferredSize(new Dimension(500, 400));
}