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:com.googlecode.logVisualizer.chart.HorizontalStackedBarChartBuilder.java

private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createStackedBarChart(getTitle(), xLable, yLable, dataset,
            PlotOrientation.HORIZONTAL, isIncludeLegend(), true, false);
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    final StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
    final CategoryAxis categoryAxis = plot.getDomainAxis();
    final NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();

    plot.setNoDataMessage("No data available");
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    setBarShadowVisible(chart, false);//  w w w  . j a  v a 2s.com

    renderer.setDrawBarOutline(false);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance()));

    categoryAxis.setCategoryMargin(0.02);
    categoryAxis.setUpperMargin(0.02);
    categoryAxis.setLowerMargin(0.02);
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberAxis.setUpperMargin(0.1);

    return chart;
}

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

private static JFreeChart createChart(TableXYDataset tablexydataset) {
    DateAxis dateaxis = new DateAxis("Date");
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    dateaxis.setLowerMargin(0.01D);/* w  w  w .j  ava  2 s  .c o m*/
    dateaxis.setUpperMargin(0.01D);
    NumberAxis numberaxis = new NumberAxis("Count");
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setUpperMargin(0.10000000000000001D);
    StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.14999999999999999D);
    stackedxybarrenderer.setDrawBarOutline(false);
    stackedxybarrenderer.setBaseItemLabelsVisible(true);
    stackedxybarrenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    stackedxybarrenderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));
    stackedxybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} : {1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0")));
    XYPlot xyplot = new XYPlot(tablexydataset, dateaxis, numberaxis, stackedxybarrenderer);
    JFreeChart jfreechart = new JFreeChart("Holes-In-One / Double Eagles", xyplot);
    jfreechart.removeLegend();
    jfreechart.addSubtitle(new TextTitle("PGA Tour, 1983 to 2003"));
    TextTitle texttitle = new TextTitle(
            "http://www.golfdigest.com/majors/masters/index.ssf?/majors/masters/gw20040402albatross.html",
            new Font("Dialog", 0, 8));
    jfreechart.addSubtitle(texttitle);
    jfreechart.setTextAntiAlias(RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
    LegendTitle legendtitle = new LegendTitle(xyplot);
    legendtitle.setBackgroundPaint(Color.white);
    legendtitle.setFrame(new BlockBorder());
    legendtitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(legendtitle);
    return jfreechart;
}

From source file:com.redhat.thermostat.byteman.plot.impl.TestPlotRenderer.java

void renderToFile(Collection<PlotRecord> records, String filename) throws Exception {
    DefaultCategoryDataset ds = new DefaultCategoryDataset();
    for (PlotRecord re : records) {
        Long label = re.getPeriodStart() + ((re.getPeriodEnd() - re.getPeriodStart()) / 2);
        ds.addValue(re.getValue(), re.getCategory(), label);
    }/*from   ww w.j  av  a  2 s . c  om*/
    JFreeChart chart = ChartFactory.createStackedBarChart(EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, ds,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(toColor("#FFFFFFFF"));
    plot.setBackgroundImageAlpha((float) 0.0d);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(toColor("#FFAAAAAA"));
    //        plot.getRangeAxis().setRange(new Range(ds.getMin(), ds.getMax() * 1.1));
    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    //        plot.getRangeAxis().setLabel(cf.rangeAxisLabel);
    //        colorAxis(plot.getRangeAxis());
    //        colorAxis(plot.getDomainAxis());
    //        plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI * 0.12d));
    //        plot.getDomainAxis().setLowerMargin(cf.domainAxisLowerMargin);
    //        plot.getDomainAxis().setUpperMargin(cf.domainAxisUpperMargin);
    //        plot.getDomainAxis().setLabel(cf.domainAxisLabel);
    BarRenderer3D barrenderer = new StackedBarRenderer3D(16.0d, 12.0d);
    barrenderer.setSeriesPaint(0, toColor("#00FFFFFF"));
    barrenderer.setSeriesPaint(1, toColor("#BB669900"));
    barrenderer.setSeriesPaint(2, toColor("#BBFF8800"));
    barrenderer.setWallPaint(toColor("#FFEEEEEE"));
    //        barrenderer.setBaseItemLabelsVisible(cf.baseItemLabelsVisible);
    barrenderer.setShadowVisible(false);
    barrenderer.setItemMargin(0.0d);
    plot.setRenderer(barrenderer);
    plot.setOutlineVisible(false);

    chartToSvg(chart, 1024, 600, filename);
}

From source file:statistic.graph.JChartPanel.java

protected static JFreeChart createChart() {
    stepDataset = new XYSeriesCollection();
    linearDataset = new XYSeriesCollection();

    chart = ChartFactory.createXYLineChart("Fluss", "Zeiteinheiten", "Flusseinheiten", stepDataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.WHITE);

    plot = (XYPlot) chart.getPlot();/*from   w  w w . j  a va2  s .c  o m*/
    plot.setBackgroundPaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    plot.setDataset(0, stepDataset);
    plot.setDataset(1, linearDataset);

    XYItemRenderer r = plot.getRenderer();
    //r.setBaseOutlinePaint(Color.BLACK);
    //r.setBasePaint();
    //r.setItemLabelPaint();
    //r.setOutlinePaint(Color.BLACK);
    //r.setSeriesItemLabelPaint();
    //r.setSeriesOutlinePaint();
    r.setSeriesPaint(0, Color.GREEN.darker());
    r.setSeriesPaint(1, Color.MAGENTA.darker());
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    //XYStepRenderer r3 = new XYStepRenderer();
    //r.setBaseOutlinePaint(Color.BLACK);
    //r.setBasePaint();
    //r.setItemLabelPaint();
    //r.setOutlinePaint(Color.BLACK);
    //r.setSeriesItemLabelPaint();
    //r.setSeriesOutlinePaint();
    //r3.setSeriesPaint(0, Color.BLACK);
    //r3.setShapesVisible(true);
    //r3.setShapesFilled(true);
    //r3.setSeriesShapesFilled(0,true);
    //r3.set
    //r3.setSeriesStroke(0, new BasicStroke(2.0f));

    XYItemRenderer r2 = new XYStepRenderer();
    r2.setSeriesPaint(2, Color.BLACK);
    plot.setRenderer(r2);
    plot.setRenderer(1, r);
    //plot.setRenderer(2, r3);

    plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.getDomainAxis().setRange(-0.5, 10);

    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.getRangeAxis().setRange(-0.5, 8.5);

    return chart;
}

From source file:com.sonyericsson.jenkins.plugins.bfa.graphs.StackedBarChart.java

@Override
protected JFreeChart createGraph() {
    DefaultCategoryDataset dataset = createDataset();

    JFreeChart chart = ChartFactory.createStackedBarChart(getTitle(), getXAxisTitle(), getYAxisTitle(), dataset,
            PlotOrientation.VERTICAL, true, true, false);

    final CategoryPlot plot = chart.getCategoryPlot();
    int index = dataset.getRowIndex(NO_FAILURE);
    if (index >= 0) {
        plot.getRenderer().setSeriesVisibleInLegend(index, false);
    }//from   w w  w . j  a  v a 2s. co m
    CategoryAxis domainAxis = plot.getDomainAxis();

    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setCategoryMargin(0);

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

    return chart;
}

From source file:org.openmrs.module.vcttrac.web.view.chart.EvolutionOfClientRegisteredPerDay.java

/**
 * @see org.openmrs.module.vcttrac.web.view.chart.AbstractChartView#createChart(java.util.Map,
 *      javax.servlet.http.HttpServletRequest)
 *///from  ww w. java  2 s. c  o m
@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {

    String categoryAxisLabel = VCTTracUtil.getMessage("vcttrac.graph.evolution.yAxis.days", null);
    String valueAxisLabel = VCTTracUtil.getMessage("vcttrac.graph.evolution.xAxis.numberofclient", null);

    int numberOfDays = 7, dayFormat = 1;

    if (request.getParameter("graphCategory") != null) {
        if (request.getParameter("graphCategory").trim().compareTo("2") == 0) {
            Date d = new Date();
            d.setDate(1);
            d.setMonth((new Date()).getMonth());
            d.setYear((new Date()).getYear());

            numberOfDays = (int) (((new Date()).getTime() - d.getTime())
                    / VCTTracConstant.ONE_DAY_IN_MILLISECONDS);

            categoryAxisLabel = VCTTracUtil.getMessage("vcttrac.month." + ((new Date()).getMonth() + 1), null);
            dayFormat = 2;

        }
    }

    String title = "";
    title = VCTTracUtil.getMessage("vcttrac.graph.evolution.client.received", null);

    JFreeChart chart = ChartFactory.createLineChart(title, categoryAxisLabel, valueAxisLabel,
            createDataset(numberOfDays, dayFormat), // data
            PlotOrientation.VERTICAL, true, false, false);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // customise the range axis...   
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setUpperMargin(0.15);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // customise the renderer...   
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setItemLabelsVisible(true);

    return chart;
}

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

private JFreeChart createChart(XYDataset dataset, String chartTitle) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            "Execution size", // domain axis label
            "Range", // range axis label
            dataset, // initial series
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from  w w  w . ja  v a 2  s. c  o  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:loldmg.GUI.MainFrame.java

private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart newchart = ChartFactory.createXYLineChart("Auto Attack DPS", // chart title
            "Level", // x axis label
            "Damage", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );//  www .j  a va 2s  .c o m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    newchart.setBackgroundPaint(Color.GRAY);

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

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(1, false);
    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 newchart;

}

From source file:org.fhaes.FHRecorder.GraphicsPanel.java

/**
 * Recalculates the charts based on the latest sample
 * data/*from  ww  w  .  j  av  a  2  s . c o m*/
 * @return
 */
private JFreeChart updateGraph() {
    try {
        NumberAxis rangeAxis = new NumberAxis();
        XYBarRenderer renderer = new XYBarRenderer();
        renderer.setSeriesPaint(0, Color.BLUE);
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.configure();

        numEventsDataset = new SlidingCategoryDataset(getNumEventsDataset(), 0, NUM_COLUMNS);
        BarRenderer numEventsRenderer = new BarRenderer();
        numEventsRenderer.setSeriesPaint(0, Color.BLUE);
        plot = new CategoryPlot(numEventsDataset, new CategoryAxis("Event Years"), rangeAxis,
                numEventsRenderer);

        numSamplesDataset = new SlidingCategoryDataset(getNumSamplesDataset(), 0, NUM_COLUMNS);
        plot.setDataset(1, numSamplesDataset);
        LineAndShapeRenderer numSamplesRenderer = new LineAndShapeRenderer();
        numSamplesRenderer.setSeriesPaint(0, Color.RED);
        plot.setRenderer(1, numSamplesRenderer);

        numRecordersDataset = new SlidingCategoryDataset(getNumRecordersDataset(), 0, NUM_COLUMNS);
        plot.setDataset(2, numRecordersDataset);
        LineAndShapeRenderer numRecordersRenderer = new LineAndShapeRenderer();
        numRecordersRenderer.setSeriesPaint(0, Color.GREEN);
        plot.setRenderer(2, numRecordersRenderer);

        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

        updateVisibleYears(savedPercent);

        return new JFreeChart(plot);
    } catch (IllegalArgumentException e) {
        // Something was wrong with the file
    }
    return null;
}

From source file:edu.coeia.charts.BarChartPanel.java

private JFreeChart createChart(final CategoryDataset dataset, String str) {
    final JFreeChart chart = ChartFactory.createBarChart3D(str, // chart title
            "Names", // domain axis label
            "Values(%)", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );// ww  w .  jav a 2 s. c o m

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(1.0f);

    // left align the category labels...
    final CategoryAxis axis = plot.getDomainAxis();
    final CategoryLabelPositions p = axis.getCategoryLabelPositions();

    final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT,
            TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f);
    axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left));

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(from, to);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}