Example usage for org.jfree.chart.axis NumberAxis createIntegerTickUnits

List of usage examples for org.jfree.chart.axis NumberAxis createIntegerTickUnits

Introduction

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

Prototype

public static TickUnitSource createIntegerTickUnits() 

Source Link

Document

Returns a collection of tick units for integer values.

Usage

From source file:org.perfrepo.web.controller.reports.testgroup.TestGroupChartBean.java

public void drawChart(OutputStream out, Object data) throws IOException {
    if (data instanceof ChartData) {
        ChartData chartData = (ChartData) data;
        JFreeChart chart = ChartFactory.createBarChart(chartData.getTitle(), "Test", "%",
                processDataSet(chartData), PlotOrientation.HORIZONTAL, false, true, false);
        chart.addSubtitle(new TextTitle("Comparison", new Font("Dialog", Font.ITALIC, 10)));
        chart.setBackgroundPaint(Color.white);
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CustomRenderer renderer = new CustomRenderer();

        plot.setBackgroundPaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        renderer.setBaseItemLabelGenerator(
                new StandardCategoryItemLabelGenerator("{2}%", NumberFormat.getInstance()));
        renderer.setBaseItemLabelsVisible(true);
        renderer.setDrawBarOutline(false);
        renderer.setMaximumBarWidth(1d / (chartData.getTests().length + 4.0));
        plot.setRenderer(renderer);//from ww  w .jav  a2  s  . c o  m

        CategoryAxis categoryAxis = plot.getDomainAxis();
        categoryAxis.setCategoryMargin(0.1);

        categoryAxis.setUpperMargin(0.1);
        categoryAxis.setLowerMargin(0.1);
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setUpperMargin(0.10);
        BufferedImage buffImg = chart.createBufferedImage(640, chartData.getTests().length * 100 + 100);
        ImageIO.write(buffImg, "gif", out);
    }
}

From source file:com.google.jenkins.flakyTestHandler.plugin.TestFlakyStatsOverRevision.java

private JFreeChart createChart(CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title
            null, // unused
            "count", // range axis label*/master
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );//w  ww.j  a  v  a  2s.c  om

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    StackedAreaRenderer ar = new StackedAreaRenderer2() {

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            RevisionLabel label = (RevisionLabel) dataset.getColumnKey(column);
            Number value = dataset.getValue(row, column);
            switch (row) {
            case 0:
                return label.revision + ": " + value + " fails";
            case 1:
                return label.revision + ": " + value + " passes";
            default:
                return label.revision;
            }
        }
    };
    plot.setRenderer(ar);
    ar.setSeriesPaint(0, ColorPalette.RED); // Fails.
    ar.setSeriesPaint(1, ColorPalette.BLUE); // Passes.

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo4.java

protected JFreeChart createChart(IntervalXYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, false, rangeLabel, dataset,
            PlotOrientation.VERTICAL, false, //!legendPanelOn,
            true, false);//from  ww  w .  j a v  a  2s  . co m

    // then customise it a little...
    // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do"));
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new ClusteredXYBarRenderer());
    XYItemRenderer renderer = plot.getRenderer();

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    return chart;
}

From source file:com.thalesgroup.hudson.plugins.cccc.CcccChartBuilder.java

protected JFreeChart createGraph() {

    JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, "Number of modules",
            buildDataset(action), PlotOrientation.VERTICAL, true, false, true);

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);//from   w  w w .  j a  va 2s .co  m
    plot.setForegroundAlpha(0.8f);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    CategoryItemRenderer firstRender = new DefaultCategoryItemRenderer();
    CcccAreaRenderer renderer = new CcccAreaRenderer(action.getUrlName());
    plot.setRenderer(firstRender);

    //Second
    NumberAxis axis2 = new NumberAxis("Lines of Code");
    axis2.setLabelPaint(Color.BLUE);
    axis2.setAxisLinePaint(Color.BLUE);
    axis2.setTickLabelPaint(Color.BLUE);
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    categoryPlot.setRangeAxis(1, axis2);
    //CategoryAxis categoryAxis = categoryPlot.getDomainAxis();
    categoryPlot.setDataset(1, buildDataset2(action));
    categoryPlot.mapDatasetToRangeAxis(1, 1);
    CategoryItemRenderer rendu = new DefaultCategoryItemRenderer();
    rendu.setBasePaint(Color.BLUE);
    categoryPlot.setRenderer(1, rendu);

    //Third
    NumberAxis axis3 = new NumberAxis("McCabe's Cyclomatic Number");
    axis3.setLabelPaint(Color.GREEN);
    axis3.setAxisLinePaint(Color.GREEN);
    axis3.setTickLabelPaint(Color.GREEN);
    CategoryPlot categoryPlot3 = chart.getCategoryPlot();
    categoryPlot3.setRangeAxis(2, axis3);
    categoryPlot3.setDataset(2, buildDataset3(action));
    categoryPlot3.mapDatasetToRangeAxis(2, 2);
    categoryPlot3.mapDatasetToDomainAxis(2, 0);
    CategoryItemRenderer rendu3 = new DefaultCategoryItemRenderer();
    rendu3.setBasePaint(Color.GREEN);
    categoryPlot3.setRenderer(2, rendu3);

    return chart;
}

From source file:org.ow2.clif.jenkins.chart.CallChart.java

@Override
protected JFreeChart createChart() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(this.eventSerie);

    JFreeChart chart;//from w ww .j  ava2 s . c  o  m
    if (this.scatterPlot) {
        chart = ChartFactory.createScatterPlot(getBasicTitle(),
                // chart title
                Messages.CallChart_Time(), // x axis label
                Messages.CallChart_ResponseTime(), // y axis label
                dataset, // data
                PlotOrientation.VERTICAL, true, // include legend
                true, // tooltips
                false // urls
        );
    } else {
        chart = ChartFactory.createXYLineChart(getBasicTitle(),
                // chart title
                Messages.CallChart_Time(), // x axis label
                this.chartId.getEvent(), // y axis label
                dataset, // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
    }

    chart.setBackgroundPaint(Color.white);
    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    Shape cross = ShapeUtilities.createDiamond(3);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShape(cross);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShape(0, cross);
    plot.setRenderer(renderer);

    // Force the 0 on vertical axis
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(true);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Force the 0 on horizontal axis
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(true);
    return chart;
}

From source file:sim.app.sugarscape.Charts.java

JFreeChart createAgeHistoChart() {
    JFreeChart chart = ChartFactory.createHistogram("Age Distribution", "Age", "Count", model.age_hist_dataset,
            PlotOrientation.VERTICAL, true, true, false);
    model.age_histo_chart = chart;//www.j a  va  2s .  co  m

    //CategoryDataset dataset1 = createDataset1();
    NumberAxis rangeAxis1 = new NumberAxis("Age");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    org.jfree.chart.axis.NumberAxis domainAxis = new NumberAxis("Bins");
    XYPlot plot = chart.getXYPlot();
    ValueAxis xAxis = plot.getDomainAxis();
    xAxis.setRange(0, 100);
    XYItemRenderer renderer1 = plot.getRenderer();
    renderer1.setSeriesPaint(0, Color.MAGENTA);
    return chart;
}

From source file:sas.BarChart.java

public static JFreeChart createChart(CategoryDataset categorydataset, String name, String type, String t) {
    JFreeChart jfreechart = ChartFactory.createLineChart(name, null, type, categorydataset,
            PlotOrientation.VERTICAL, false, true, false);
    jfreechart.addSubtitle(new TextTitle(t));
    TextTitle texttitle = new TextTitle("");
    texttitle.setFont(new Font("SansSerif", 0, 10));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.CENTER);
    jfreechart.addSubtitle(texttitle);//from w  ww . j  a  v a2 s.  com
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setRangePannable(true);
    categoryplot.setRangeGridlinesVisible(false);
    java.net.URL url = (BarChart.class).getClassLoader().getResource("line_Chart_example.png");
    if (url != null) {
        ImageIcon imageicon = new ImageIcon(url);
        jfreechart.setBackgroundImage(imageicon.getImage());
        categoryplot.setBackgroundPaint(null);
    }
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ChartUtilities.applyCurrentTheme(jfreechart);
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    lineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F));
    lineandshaperenderer.setSeriesOutlineStroke(0, new BasicStroke(2.0F));
    lineandshaperenderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
    return jfreechart;
}

From source file:de.fhffm.jad.demo.view.LineChartPanel.java

/**
 * Creates a sample chart./*w  w  w.java 2 s.c o m*/
 * 
 * @param dataset  a dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Realtime Anomaly Detection", // chart title
            "Time", // x axis label
            "Percent", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
}

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

protected void configureRangeAxis() {
    numberAxis = new NumberAxis();
    numberAxis.setLabelFont(DEFAULT_FONT);
    numberAxis.setLabelPaint(BASE_COLOR);
    numberAxis.setTickLabelFont(DEFAULT_FONT);
    numberAxis.setTickLabelPaint(BASE_COLOR);
    numberAxis.setTickMarksVisible(true);
    numberAxis.setVisible(false);/* w  w  w  . ja va2 s  .c o  m*/
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
}

From source file:org.jrecruiter.web.actions.admin.ShowStatisticsAction.java

private static JFreeChart createChart(final CategoryDataset categorydataset, final String chartTitle) {
    final JFreeChart chart = ChartFactory.createBarChart(chartTitle, "Jobs", "Number of Hits", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);

    final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setNoDataMessage("NO DATA!");

    chart.setBackgroundPaint(new Color(245, 245, 255));
    chart.setBorderPaint(new Color(204, 204, 204));
    chart.setBorderStroke(new BasicStroke(1f));

    final LegendTitle legend = chart.getLegend();
    legend.setWidth(1000);/* ww  w . ja  v  a 2  s . c o  m*/
    legend.setPosition(RectangleEdge.BOTTOM);

    final BlockBorder border = new BlockBorder(new Color(204, 204, 204));
    legend.setBorder(border);

    final CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot();
    categoryPlot.setBackgroundPaint(Color.WHITE);
    categoryPlot.setRangeGridlinePaint(new Color(204, 204, 204));
    categoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    final NumberAxis numberaxis = (NumberAxis) categoryPlot.getRangeAxis();

    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    final BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer();
    renderer.setDrawBarOutline(true);

    final ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.CENTER);
    renderer.setPositiveItemLabelPosition(itemlabelposition);

    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());

    renderer.setItemLabelsVisible(true);
    return chart;
}