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.jfree.chart.demo.StackedBarChart3DDemo5.java

private static JFreeChart createChart(int i, CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedBarChart3D("Chart " + (i + 1), "Category", "Value",
            categorydataset, PlotOrientation.VERTICAL, false, false, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.getDomainAxis().setMaximumCategoryLabelLines(2);
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.white);
    ValueAxis valueaxis = categoryplot.getRangeAxis();
    valueaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}

From source file:org.uncommons.watchmaker.swing.evolutionmonitor.PopulationFitnessView.java

PopulationFitnessView(boolean islands) {
    super(new BorderLayout());
    meanSeries = new XYSeries(islands ? "Global Mean Fitness" : "Population Mean Fitness");
    dataSet.addSeries(bestSeries);/* w ww .j ava2s  . c om*/
    dataSet.addSeries(meanSeries);
    chart = ChartFactory.createXYLineChart(islands ? "Global Population Fitness" : "Population Fitness",
            islands ? "Epochs" : "Generations", "Fitness", dataSet, PlotOrientation.VERTICAL, true, // Legend.
            false, // Tooltips.
            false);
    this.domainAxis = chart.getXYPlot().getDomainAxis();
    this.rangeAxis = chart.getXYPlot().getRangeAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setLowerMargin(0);
    domainAxis.setUpperMargin(0.05);
    domainAxis.setRangeWithMargins(0, SHOW_FIXED_GENERATIONS);
    rangeAxis.setRange(minY, maxY);
    ChartPanel chartPanel = new ChartPanel(chart, ChartPanel.DEFAULT_WIDTH, ChartPanel.DEFAULT_HEIGHT,
            ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MINIMUM_DRAW_HEIGHT,
            ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, false, // Buffered
            false, // Properties
            true, // Save
            true, // Print
            false, // Zoom
            false); // Tooltips
    add(chartPanel, BorderLayout.CENTER);
    add(createControls(islands), BorderLayout.SOUTH);
}

From source file:com.csc.GUI.ProfileGUIPanel.java

private JFreeChart createBarChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Expenses Statistics", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//from  ww w  . j  ava  2 s  . c om

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

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

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}

From source file:eu.delving.sip.base.ReportChartHelper.java

private static JPanel finishBarChart(JFreeChart chart, Color... colors) {
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangePannable(true);/*from  ww w  .  j  a  v a  2 s.  c o  m*/
    if (colors.length > 0)
        plot.setRenderer(new CustomRenderer(colors));
    BarRenderer bar = (BarRenderer) plot.getRenderer();
    bar.setItemLabelAnchorOffset(9D);
    bar.setBaseItemLabelsVisible(true);
    bar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    bar.setMaximumBarWidth(0.05);
    bar.setItemMargin(0.03D);
    bar.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(INSIDE12, CENTER_RIGHT, CENTER_RIGHT, -1.5707963267948966D));
    bar.setPositiveItemLabelPositionFallback(
            new ItemLabelPosition(OUTSIDE12, CENTER_LEFT, CENTER_LEFT, -1.5707963267948966D));
    CategoryAxis x = plot.getDomainAxis();
    x.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    x.setCategoryMargin(0.25D);
    x.setUpperMargin(0.02D);
    x.setLowerMargin(0.02D);
    NumberAxis y = (NumberAxis) plot.getRangeAxis();
    y.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    y.setUpperMargin(0.10000000000000001D);
    ChartUtilities.applyCurrentTheme(chart);
    return new ChartPanel(chart);
}

From source file:statistic.graph.XYChart.java

private void initXAxis(String label) {
    plot.setDomainAxis(new NumberAxis(label));
    double max = Double.NEGATIVE_INFINITY;
    double min = Double.POSITIVE_INFINITY;
    for (int s = 0; s < collection.getSeriesCount(); s++) {
        for (int d = 0; d < collection.getItemCount(s); d++) {
            XYDataItem data = collection.getSeries(s).getDataItem(d);
            if (data.getX().longValue() == Integer.MAX_VALUE || data.getX().longValue() == Integer.MIN_VALUE) {
                continue;
            }/*from   w ww . ja v a2  s .co m*/
            if (data.getX().doubleValue() > max) {
                max = data.getX().doubleValue();
            }
            if (data.getX().doubleValue() < min) {
                min = data.getX().doubleValue();
            }
        }
    }
    plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.getDomainAxis().setRange(min - 0.5, max + 0.5);
}

From source file:eu.choreos.vv.chart.XYChart.java

private static JFreeChart createChart(XYDataset dataset, String chartTitle, String xLabel, String yLabel) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            xLabel, // domain axis label
            yLabel, // range axis label
            dataset, // initial series
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//ww  w .j  a  v a  2  s  . co  m

    // set chart background
    chart.setBackgroundPaint(Color.white);

    // set a few custom plot features
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the plot's axes to display integers
    TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setStandardTickUnits(ticks);
    domain.resizeRange(1.1);
    domain.setLowerBound(0.5);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setStandardTickUnits(ticks);
    range.setUpperBound(range.getUpperBound() * 1.1);

    // render shapes and lines
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
    plot.setRenderer(renderer);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // set the renderer's stroke
    Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    renderer.setBaseOutlineStroke(stroke);

    // label the points
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator(
            StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format);
    renderer.setBaseItemLabelGenerator(generator);
    renderer.setBaseItemLabelsVisible(true);

    return chart;
}

From source file:com.googlecode.logVisualizer.chart.HorizontalIntervallBarChartBuilder.java

private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createBarChart(getTitle(), xLable, yLable, dataset,
            PlotOrientation.HORIZONTAL, isIncludeLegend(), true, false);
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    final CategoryAxis categoryAxis = plot.getDomainAxis();
    final LayeredBarRenderer renderer = new LayeredBarRenderer();

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.black);
    setBarShadowVisible(chart, false);/*from w w  w  . j  a v  a 2  s .  c o m*/

    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.getRangeAxis().setLowerBound(-35);
    plot.getRangeAxis().setUpperBound(35);

    renderer.setDrawBarOutline(false);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.green);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setSeriesPositiveItemLabelPosition(0,
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER));
    renderer.setSeriesPositiveItemLabelPosition(1,
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE2, TextAnchor.CENTER));
    renderer.setSeriesNegativeItemLabelPosition(0,
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER));
    renderer.setSeriesNegativeItemLabelPosition(1,
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.CENTER));
    renderer.setItemLabelAnchorOffset(9.0);
    renderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance()));
    plot.setRenderer(renderer);
    plot.setRowRenderingOrder(SortOrder.DESCENDING);

    categoryAxis.setCategoryMargin(0.15);
    categoryAxis.setUpperMargin(0.0175);
    categoryAxis.setLowerMargin(0.0175);

    return chart;
}

From source file:org.mili.jmibs.jfree.JFreeChartBarIterationIntervalBenchmarkSuiteResultRenderer.java

private JFreeChart createChart(String title, CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(title, "Benchmark (Iteration/Interval)", "Time in ns",
            dataset, PlotOrientation.HORIZONTAL, true, true, false);
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);/* w  w  w .  jav  a 2s  . c o m*/
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    return chart;
}

From source file:org.webcat.grader.graphs.HistogramChart.java

protected JFreeChart generateChart(WCChartTheme chartTheme) {
    JFreeChart chart = ChartFactory.createHistogram(null, xAxisLabel(), yAxisLabel(), intervalXYDataset(),
            orientation(), false, false, false);

    XYPlot plot = chart.getXYPlot();/* w  ww .  java  2s.  c o m*/
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setAutoPopulateSeriesOutlinePaint(true);
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);

    if (markValue != null) {
        plot.setDomainCrosshairVisible(true);
        plot.setDomainCrosshairValue(markValue.doubleValue());
        plot.setDomainCrosshairPaint(Color.red);
        plot.setDomainCrosshairStroke(MARKER_STROKE);
    }

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

    return chart;
}

From source file:Visuals.BarChart.java

public ChartPanel drawBarChart() {
    DefaultCategoryDataset bardataset = new DefaultCategoryDataset();
    bardataset.addValue(new Double(low), "Low (" + low + ")", lowValue);
    bardataset.addValue(new Double(medium), "Medium (" + medium + ")", mediumValue);
    bardataset.addValue(new Double(high), "High (" + high + ")", highValue);
    bardataset.addValue(new Double(critical), "Critical (" + critical + ")", criticalValue);

    JFreeChart barchart = ChartFactory.createBarChart(title, // Title  
            riskCategory, riskCountTitle, bardataset // Dataset   
    );// w  w w. j av a2  s .  co  m

    final CategoryPlot plot = barchart.getCategoryPlot();
    CategoryItemRenderer renderer = new CustomRenderer();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    renderer.setBaseItemLabelGenerator(
            new StandardCategoryItemLabelGenerator(riskCountTitle, NumberFormat.getInstance()));

    DecimalFormat df = new DecimalFormat("##");
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", df));
    Font m1Font;
    m1Font = new Font("Cambria", Font.BOLD, 16);
    renderer.setItemLabelFont(m1Font);
    renderer.setItemLabelPaint(null);

    //barchart.removeLegend();
    plot.setRenderer(renderer);
    //renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE5, TextAnchor.CENTER));
    //renderer.setItemLabelsVisible(true);
    barchart.getCategoryPlot().setRenderer(renderer);

    LegendItemCollection chartLegend = new LegendItemCollection();
    Shape shape = new Rectangle(10, 10);
    chartLegend.add(new LegendItem("Low (" + low + ")", null, null, null, shape, new Color(230, 219, 27)));
    chartLegend
            .add(new LegendItem("Medium (" + medium + ")", null, null, null, shape, new Color(85, 144, 176)));
    chartLegend.add(new LegendItem("High (" + high + ")", null, null, null, shape, new Color(230, 90, 27)));
    chartLegend.add(
            new LegendItem("Critical (" + critical + ")", null, null, null, shape, new Color(230, 27, 27)));
    plot.setFixedLegendItems(chartLegend);
    plot.setBackgroundPaint(new Color(210, 234, 243));
    ChartPanel chartPanel = new ChartPanel(barchart);
    return chartPanel;
}