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() 

Source Link

Document

Creates a new category axis with no label.

Usage

From source file:org.sonar.plugins.core.charts.DistributionAreaChart.java

@Override
protected Plot getPlot(ChartParameters params) {
    DefaultCategoryDataset dataset = createDataset(params);

    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setCategoryMargin(0.0);/*from   w w w  .  j a va 2s. c o m*/
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setNumberFormatOverride(NumberFormat.getIntegerInstance(params.getLocale()));
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    AreaRenderer renderer = new AreaRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
    plot.setForegroundAlpha(0.5f);
    plot.setDomainGridlinesVisible(true);
    configureColors(dataset, plot, params.getValues(PARAM_COLORS, ","));
    return plot;
}

From source file:org.xwiki.chart.internal.plot.BarPlotGenerator.java

/**
 * {@inheritDoc}/*w w  w .  jav  a2  s  . c o  m*/
 */
public Plot generate(ChartModel model, Map<String, String> parameters) {
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryAxis domainAxis = new CategoryAxis();
    ValueAxis rangeAxis = new NumberAxis();
    return new CategoryPlot(buildCategoryDataset(model, parameters), domainAxis, rangeAxis, renderer);
}

From source file:jgnash.ui.budget.BudgetSparkline.java

public static Icon getSparklineImage(final List<BigDecimal> amounts) {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    final boolean[] negate = new boolean[amounts.size()];

    for (int i = 0; i < amounts.size(); i++) {
        dataset.addValue(amounts.get(i), CATEGORY, i);
        negate[i] = amounts.get(i).signum() == -1;
    }// w ww  .j a  va2s . co  m

    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setTickLabelsVisible(false);
    xAxis.setTickMarksVisible(false);
    xAxis.setAxisLineVisible(false);
    xAxis.setVisible(false);

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setAxisLineVisible(false);
    yAxis.setNegativeArrowVisible(false);
    yAxis.setPositiveArrowVisible(false);
    yAxis.setAutoRangeIncludesZero(true);
    yAxis.setAutoRange(true);
    yAxis.setVisible(false);

    BarRenderer renderer = new BarRenderer() {

        @Override
        public Paint getItemPaint(final int row, final int column) {
            return negate[column] ? Color.RED : Color.BLACK;
        }
    };

    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardBarPainter());

    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setInsets(INSETS);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(CLEAR);

    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(CLEAR);

    Icon icon = EMPTY_ICON;

    try {
        byte[] image = ENCODER
                .encode(chart.createBufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.BITMASK, null));
        icon = new ImageIcon(image);
    } catch (IOException ex) {
        Logger.getLogger(BudgetSparkline.class.getName()).log(Level.SEVERE, null, ex);
    }

    return icon;
}

From source file:org.operamasks.faces.render.graph.CurveAreaChartRenderer.java

private JFreeChart createCurveAreaChart(CategoryDataset dataset, PlotOrientation orientation) {
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setLowerMargin(0.0);/*from   w w  w .ja v  a 2 s  .co  m*/
    xAxis.setUpperMargin(0.0);
    xAxis.setCategoryMargin(0.0);

    NumberAxis yAxis = new NumberAxis();
    yAxis.setAutoRangeIncludesZero(false);

    CurveAndShapeRenderer renderer = new CurveAndShapeRenderer(true, false);
    renderer.setDrawArea(true);

    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    if (dataset.getRowCount() > 1) {
        plot.setForegroundAlpha(0.75f);
    }

    return new JFreeChart(null, null, plot, false);
}

From source file:de.fub.maps.project.plugins.tasks.eval.Barchart.java

public Barchart() {
    setLayout(new BorderLayout());
    plot = new CategoryPlot() {
        private static final long serialVersionUID = 1L;

        @Override/*w  w  w. j  a v a2s . c o  m*/
        public LegendItemCollection getLegendItems() {

            CategoryItemRenderer renderer = getRenderer(0);
            return renderer.getLegendItems();
        }
    };
    plot.setRangeAxis(new NumberAxis());
    plot.setDomainAxis(new CategoryAxis());
    plot.getDomainAxis().setMaximumCategoryLabelLines(3);
    plot.getDomainAxis().setCategoryLabelPositionOffset(5);
    plot.setDataset(dataset);
    plot.setOrientation(PlotOrientation.VERTICAL);
    chart = new JFreeChart(null, null, plot, true);
    chart.setBackgroundPaint(Color.white);
    BarRenderer renderer = new BarRenderer();
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    renderer.setAutoPopulateSeriesFillPaint(true);
    renderer.setAutoPopulateSeriesPaint(true);
    renderer.setShadowVisible(false);
    renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    plot.setRenderer(renderer);
    plot.setBackgroundPaint(Color.white);
    chartPanel = new ChartPanel(chart, false);
    chartPanel.setBackground(Color.white);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:com.xpn.xwiki.plugin.charts.plots.CategoryPlotFactory.java

public Plot create(DataSource dataSource, CategoryItemRenderer renderer, ChartParams params)
        throws GenerateException, DataSourceException {
    String dataSeries = params.getString(ChartParams.SERIES);

    CategoryAxis domainAxis = new CategoryAxis();
    ValueAxis rangeAxis = new NumberAxis();
    ChartCustomizer.customizeCategoryAxis(domainAxis, params, ChartParams.AXIS_DOMAIN_PREFIX);
    ChartCustomizer.customizeValueAxis(rangeAxis, params, ChartParams.AXIS_RANGE_PREFIX);

    Class rendererClass = params.getClass(ChartParams.RENDERER);

    ChartCustomizer.customizeCategoryItemRenderer(renderer, params);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    if ("columns".equals(dataSeries)) {
        for (int row = 0; row < dataSource.getRowCount(); row++) {
            for (int column = 0; column < dataSource.getColumnCount(); column++) {
                dataset.addValue(dataSource.getCell(row, column),
                        dataSource.hasHeaderRow() ? dataSource.getHeaderRowValue(column)
                                : ("Category " + (column + 1)),
                        dataSource.hasHeaderColumn() ? dataSource.getHeaderColumnValue(row)
                                : ("Series " + (row + 1)));
            }//ww w.jav  a 2 s.co m
        }
    } else if ("rows".equals(dataSeries)) {
        for (int row = 0; row < dataSource.getRowCount(); row++) {
            for (int column = 0; column < dataSource.getColumnCount(); column++) {
                dataset.addValue(dataSource.getCell(row, column),
                        dataSource.hasHeaderColumn() ? dataSource.getHeaderColumnValue(row)
                                : ("Category " + (row + 1)),
                        dataSource.hasHeaderRow() ? dataSource.getHeaderRowValue(column)
                                : ("Series " + (column + 1)));
            }
        }
    } else {
        throw new GenerateException("Invalid series parameter: " + dataSeries);
    }
    return new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
}

From source file:org.jboss.weld.benchmark.charts.Chart.java

/**
 * Saving a chart to hard disk as png image
 *
 * @param path absolute path// w  ww  .j a v  a  2s .com
 * @return true if no errors occurred
 */
public Boolean saveImageTo(String path) {
    try {
        JFreeChart lineChartObject = ChartFactory.createBarChart(NAME, X_AXIS_NAME, Y_AXIS_NAME,
                lineChartDataset, PlotOrientation.VERTICAL, true, true, false);

        CategoryPlot plot = (CategoryPlot) lineChartObject.getPlot();

        plot.setDomainAxis(new CategoryAxis() {
            private static final long serialVersionUID = 1L;

            @Override
            protected TextBlock createLabel(@SuppressWarnings("rawtypes") Comparable category, float width,
                    RectangleEdge edge, Graphics2D g2) {
                TextBlock label = TextUtilities.createTextBlock(category.toString(), getTickLabelFont(category),
                        getTickLabelPaint(category), ONE_PART_WIDTH - 30, 2, new G2TextMeasurer(g2));

                label.setLineAlignment(HorizontalAlignment.LEFT);
                return label;
            }
        });

        File lineChart = new File(path, NAME + ".png");
        ChartUtilities.saveChartAsPNG(lineChart, lineChartObject,
                ONE_PART_WIDTH * lineChartDataset.getColumnCount(), GRAPH_HEIGHT);
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:org.evosuite.jenkins.plot.Plot.java

@Override
protected JFreeChart createGraph() {
    final JFreeChart chart = ChartFactory.createLineChart(null, "Build Number #", this.yLabel, this.dataset,
            PlotOrientation.VERTICAL, true, true, true);
    chart.setBackgroundPaint(Color.WHITE);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);/* w  w  w  . java2s .c o  m*/
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    plot.setDomainAxis(domainAxis);
    plot.setBackgroundPaint(Color.WHITE);

    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    //yAxis.setRange(0.0, 100.0);

    URLAndTooltipRenderer urlRenderer = new URLAndTooltipRenderer(this.project.getProject());
    ColorPalette.apply(urlRenderer);
    plot.setRenderer(urlRenderer);

    return chart;
}

From source file:de.fub.maps.project.detector.model.inference.ui.charts.ClassificationBarChart.java

/**
 * Creates new form ClassificationBarChart
 *///  w  ww  .  j  av a  2 s  .c o m
public ClassificationBarChart() {
    super();
    initComponents();
    plot = new CustomCategoryPlot();
    barChart = new JFreeChart(NbBundle.getMessage(ClassificationBarChart.class, "CLT_Chart_Classify_Name"),
            null, plot, true);
    ChartFactory.getChartTheme().apply(barChart);
    plot.setDomainAxis(new CategoryAxis());
    plot.getDomainAxis().setLabel(NbBundle.getMessage(ClassificationBarChart.class, "CLT_Doman_Axis_Name"));
    plot.setOrientation(PlotOrientation.VERTICAL);

    Font font = new JLabel().getFont().deriveFont(Font.BOLD, 14);
    barChart.getTitle().setFont(font);
    barChart.getTitle().setPaint(new Color(153, 153, 153));

    plot.setDataset(0, relDataset);
    plot.setDataset(1, absDataset);
    plot.mapDatasetToRangeAxis(0, 0);
    plot.mapDatasetToRangeAxis(1, 1);

    NumberAxis relAxis = new NumberAxis(
            NbBundle.getMessage(ClassificationBarChart.class, "CLT_Value_Axis_Name"));
    relAxis.setAutoRange(true);
    relAxis.setUpperMargin(.20);
    NumberAxis absAxis = new NumberAxis(
            NbBundle.getMessage(ClassificationBarChart.class, "CLT_Value_Rel_Axis_Name"));
    absAxis.setAutoRange(true);
    absAxis.setUpperMargin(.20);

    plot.setRangeAxis(0, relAxis);
    plot.setRangeAxis(1, absAxis);
    plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT);
    plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT);

    BarRenderer relRenderer = new BarRenderer();
    relRenderer.setBasePaint(relColor);
    relRenderer.setAutoPopulateSeriesPaint(false);
    relRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    relRenderer.setBarPainter(new StandardBarPainter());
    relRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat()));
    relRenderer.setBaseItemLabelsVisible(true);

    BarRenderer absRenderer = new BarRenderer();
    absRenderer.setBasePaint(absColor);
    absRenderer.setAutoPopulateSeriesPaint(false);
    absRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    absRenderer.setBarPainter(new StandardBarPainter());
    absRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat()));
    absRenderer.setBaseItemLabelsVisible(true);

    plot.setRenderer(0, relRenderer);
    plot.setRenderer(1, absRenderer);

    plot.setBackgroundPaint(Color.white);
    barChart.setBackgroundPaint(Color.white);
    plot.setRangeGridlinesVisible(false);
    chartPanel = new ChartPanel(barChart, false);
    chartPanel.setVerticalAxisTrace(false);
    chartPanel.setDisplayToolTips(true);
    chartPanel.setBackground(Color.white);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:org.sonar.server.charts.deprecated.BarChart.java

protected void configureCategoryAxis() {
    categoryAxis = new CategoryAxis();
    categoryAxis.setLabelFont(DEFAULT_FONT);
    categoryAxis.setLabelPaint(BASE_COLOR);
    categoryAxis.setTickLabelFont(DEFAULT_FONT);
    categoryAxis.setTickLabelPaint(BASE_COLOR);
    categoryAxis.setVisible(false);/*from   w w  w  . jav  a2s  .co  m*/
}