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:pwm.visualizer.MDPPolicyPanel.java

private JFreeChart createChart() {
    NumberAxis nutritionAxis = new NumberAxis("Calories/Day");
    nutritionAxis.setLowerBound(0);//from  w ww  . java  2s. c o m
    nutritionAxis.setUpperBound(5000);
    nutritionAxis.setAutoRange(false);
    //      
    CategoryPlot categoryplot = new CategoryPlot(nutritionDataSet, new CategoryAxis("Weight(KG)"),
            nutritionAxis, new BarRenderer());
    CategoryAxis xaxis = categoryplot.getDomainAxis();
    xaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);

    LegendItemCollection legend = new LegendItemCollection();
    LegendItem nutritionLegend = new LegendItem("Calories/Day");
    LegendItem exerciseLegend = new LegendItem("Physical Activity Level");
    nutritionLegend.setFillPaint(Color.BLUE);
    exerciseLegend.setFillPaint(Color.RED);

    legend.add(nutritionLegend);
    legend.add(exerciseLegend);

    categoryplot.setFixedLegendItems(legend);
    JFreeChart jfreechart = new JFreeChart("Policy Visualizer", categoryplot);
    categoryplot.setDataset(1, exerciseDataSet);
    categoryplot.mapDatasetToRangeAxis(1, 1);

    NumberAxis exerciseAxis = new NumberAxis("Physical Activity Level");
    exerciseAxis.setLowerBound(0);
    exerciseAxis.setUpperBound(3.0);
    exerciseAxis.setAutoRange(false);

    categoryplot.setRangeAxis(1, exerciseAxis);
    BarRenderer barrenderer1 = new BarRenderer();
    categoryplot.setRenderer(1, barrenderer1);

    //        BarRenderer stackedbarrenderer = (BarRenderer)categoryplot.getRenderer();
    //        stackedbarrenderer.setDrawBarOutline(true);
    //        stackedbarrenderer.setBaseItemLabelsVisible(false);
    //        stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());

    ChartUtilities.applyCurrentTheme(jfreechart);

    return jfreechart;

}

From source file:net.sf.maltcms.common.charts.ui.CategoryChartComponentOpenAction.java

@Override
public void actionPerformed(ActionEvent e) {
    Task t = RequestProcessor.getDefault().create(new Runnable() {
        @Override//w  ww  . j  a  va  2s.c  om
        public void run() {
            final ACategoryDataset<List<Double>, Double> dataset = createCategoryDataset();
            final CategoryChartBuilder builder = new CategoryChartBuilder();

            MinMaxCategoryRenderer renderer = new MinMaxCategoryRenderer();
            renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
            renderer.setBaseItemLabelsVisible(true);

            CategoryAxis domain = new CategoryAxis("Categories");
            builder.categories(dataset).renderer(renderer).domainAxis(domain).minimumDrawSize(400, 300)
                    .preferredDrawSize(800, 600).maximumDrawSize(1280, 1024).plot().chart("Sample plot")
                    .createLegend(true);
            invokeLater(new Runnable() {
                @Override
                public void run() {
                    TopComponent tc = WindowManager.getDefault().findTopComponent("navigatorTC");
                    if (tc != null) {
                        tc.open();
                    }
                }
            });
            invokeLater(new Runnable() {

                @Override
                public void run() {
                    CategoryChartTopComponent<Double> xytc = new CategoryChartTopComponent<>(Double.class,
                            dataset, builder);
                    xytc.open();
                    xytc.requestActive();
                }
            });

        }
    });
    RequestProcessor.getDefault().post(t);
}

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

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

    super(title);
    String sDirectorio = experimentsDir;

    Hashtable<String, List> info = new Hashtable();

    //String[] aMode = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4"};
    /*for (String mode : aMode) {
     info.put(mode, new ArrayList());
     }*/
    createSampleDataset(pf, info);
    AddDataFailingExperiments(sDirectorio, pf, info);
    final BoxAndWhiskerCategoryDataset dataset = addDataSet(info);

    final CategoryAxis xAxis = new CategoryAxis("");
    //final NumberAxis yAxis = new NumberAxis("Information Collected");
    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("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("BestAgentsPercentageInfoCollected" + pf + mazeMode + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 350, 350, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(BestAgentsPercentageInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(BestAgentsPercentageInfoCollected.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:no.uio.medicine.virsurveillance.charts.BoxAndWhiskerChart_AWT.java

/**
 * Creates a new demo.//  w ww.  j a  va 2  s  .  co m
 *
 * @param applicationTitle
 * @param chartTitle
 * @param xTitle
 * @param yTitle
 * @param dataPoints
 * @param categories
 * @param seriesTitles
 */
public BoxAndWhiskerChart_AWT(String applicationTitle, String chartTitle, String xTitle, String yTitle,
        ArrayList<ArrayList<ArrayList<Float>>> dataPoints, ArrayList<ArrayList<String>> categories,
        ArrayList<String> seriesTitles) {

    super(applicationTitle);

    this.dataPoints = dataPoints;
    this.categories = categories;
    this.seriesTitles = seriesTitles;

    this.chartTitle = chartTitle;
    this.xAxisTitle = xTitle;
    this.yAxisTitle = yTitle;
    this.Title = applicationTitle;

    BoxAndWhiskerCategoryDataset dataset = (BoxAndWhiskerCategoryDataset) createDataset(this.dataPoints,
            this.categories, this.seriesTitles);

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

    final JFreeChart chart = new JFreeChart(this.chartTitle, new Font("SansSerif", Font.BOLD, 14), this.plot,
            true);
    chart.setBackgroundPaint(Color.white);
    this.chartPanel = new ChartPanel(chart);
    this.chartPanel.setBackground(Color.white);
    this.chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
    setContentPane(this.chartPanel);

    this.setDefaultCloseOperation(HIDE_ON_CLOSE);
}

From source file:org.aksw.iguana.reborn.charts.datasets.StatisticalBarChartDemo.java

/**
 * Creates a new demo.//from www. ja va 2 s  . co  m
 *
 * @param title
 *            the frame title.
 * @throws DocumentException
 * @throws FileNotFoundException
 */
public StatisticalBarChartDemo(final String title) throws FileNotFoundException, DocumentException {

    super(title);
    final StatisticalCategoryDataset dataset = createDataset();

    final CategoryAxis xAxis = new CategoryAxis("Type");
    xAxis.setLowerMargin(0.01d); // percentage of space before first bar
    xAxis.setUpperMargin(0.01d); // percentage of space after last bar
    xAxis.setCategoryMargin(0.05d); // percentage of space between
    // categories
    final ValueAxis yAxis = new NumberAxis("Value");

    // define the plot
    final CategoryItemRenderer renderer = new StatisticalBarRenderer();
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    final JFreeChart chart = new JFreeChart("Statistical Bar Chart Demo", new Font("Helvetica", Font.BOLD, 14),
            plot, true);
    ChartUtilities2.saveChartAsPDF(new File("/home/raven/tmp/foo.pdf"), chart, 1000, 300);

    // chart.setBackgroundPaint(Color.white);
    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:org.jfree.chart.demo.selection.SelectionDemo7ScatterRenderer.java

/**
 * Creates a chart.//from   ww w. j a v a 2 s. c o  m
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(final MultiValueCategoryDataset dataset,
        final DatasetSelectionExtension<CategoryCursor<String, String>> ext) {

    ScatterRenderer r = new ScatterRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), r);
    plot.setBackgroundColor(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4));
    JFreeChart chart = new JFreeChart("ScatterRendererDemo1", plot);
    ChartUtilities.applyCurrentTheme(chart);

    //register the plot
    ext.addChangeListener(plot);

    //illustrates the usage of a shape item rendering strategy
    final CategoryCursor<String, String> cursor = new CategoryCursor<String, String>();
    r.setShapeIRS(new DefaultShapeIRS(r) {
        private static final long serialVersionUID = 1L;

        @Override
        public Shape getItemShape(int row, int column) {
            cursor.setPosition((String) dataset.getRowKey(row), (String) dataset.getColumnKey(column));
            if (ext.isSelected(cursor)) {
                return new Rectangle2D.Double(-10.0, -10.0, 20.0, 20.0);
            } else {
                return super.getItemShape(row, column);
            }
        }
    });

    return chart;
}

From source file:smellminer.engine.JFreeChartDemo.java

/**
 * Creates a new demo./*  w  w  w  .j a va 2  s .  c  o  m*/
 *
 * @param title  the frame title.
 */
public JFreeChartDemo(final String title) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset();

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

    final JFreeChart chart = new JFreeChart("Box-and-Whisker Demo", new Font("SansSerif", Font.BOLD, 14), plot,
            true);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(450, 270));
    setContentPane(chartPanel);

}

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

/**
 * Creates a new demo.//from   w  w w . ja v  a2  s  .c o  m
 *
 * @param title  the frame title.
 */
public BoxAndWhiskerDemo(final String title) {

    super(title);

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset();

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

    final JFreeChart chart = new JFreeChart("Box-and-Whisker Demo", new Font("SansSerif", Font.BOLD, 14), plot,
            true);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(450, 270));
    setContentPane(chartPanel);

}

From source file:br.upe.ecomp.dosa.controller.chart.FileBoxplotChartManager.java

private JFreeChart createChart(String title, String xLabel, String yLabel, BoxAndWhiskerCategoryDataset dataset,
        boolean logarithmicYAxis) {

    final CategoryAxis xAxis = new CategoryAxis("Sample");
    final NumberAxis yAxis;
    if (logarithmicYAxis) {
        yAxis = new LogarithmicAxis("Fitness (Log10)");
        ((LogarithmicAxis) yAxis).setExpTickLabelsFlag(true);
    } else {//  w w w . j  a va 2s.  c  o m
        yAxis = new NumberAxis("Fitness");
    }
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setAutoRange(true);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(true);
    renderer.setBaseCreateEntities(true);
    // renderer.setArtifactPaint(Color.green);
    renderer.setBaseOutlinePaint(Color.blue);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(title, xAxis.getLabel(), yAxis.getLabel(),
            dataset, true);
    final CategoryPlot plot = chart.getCategoryPlot();// new CategoryPlot(dataset, xAxis, yAxis,
                                                      // renderer);
    plot.setBackgroundPaint(Color.white);
    // chart.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setRenderer(renderer);
    plot.setRangeAxis(yAxis);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return chart;
}

From source file:com.googlecode.jchav.chart.MinMeanMaxChart.java

/**
 * Construct a new chart to display the given data.
 *
 * @param title The page id, used for the title of the chart.
 * @param data the data to plot.//from w ww.j av  a 2s . c  om
 */
public MinMeanMaxChart(final String title, final SortedSet<Measurement> data) {
    // The renderer that does all the real work here:
    final MinMaxCategoryRenderer minMaxRenderer = new MinMaxCategoryRenderer();
    minMaxRenderer.setObjectIcon(new FilledCircle());

    // Munge the data into form JFreeChart can use:
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Measurement m : data) {
        // This ordering gives max=red, min=green, mean=blue
        dataset.addValue(m.getMaximumTime(), "max", m.getBuildId().getBuildName());
        dataset.addValue(m.getAverageTime(), "mean", m.getBuildId().getBuildName());
        dataset.addValue(m.getMinimumTime(), "min", m.getBuildId().getBuildName());
    }

    // Create the plot area:
    final CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset);
    plot.setRenderer(minMaxRenderer);
    plot.setDomainAxis(new CategoryAxis("Build")); // TO DO: i18n
    plot.setRangeAxis(new NumberAxis("RT"));

    // Build labels running diagonally under the bars of the chart.
    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(false);

    // the legend here would be the "min", "max", "mean" strings used when created int category data set.
    boolean showLegend = true;

    // Render the chart:
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend);
    chart.setTitle(title);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderVisible(false);

    if (showLegend) {
        chart.getLegend().setBorder(BlockBorder.NONE);
    }

    this.setChart(chart);

}