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

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

Introduction

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

Prototype

public void setStandardTickUnits(TickUnitSource source) 

Source Link

Document

Sets the source for obtaining standard tick units for the axis and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:vista.DestinosMasConsultados.java

public void iniciarGraficos(CategoryDataset dataset) {
    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Paises mas consultados", // chart title
            "Paises", // domain axis label
            "Cantidad de consultas", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//from   w  w  w .j a  v a  2s . c o m

    // 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));

    ChartPanel chartFinal = new ChartPanel(chart);
    chartFinal.setSize(new Dimension(600, 400));

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(panelDestinosMasConsultados);
    panelDestinosMasConsultados.setLayout(jPanel1Layout);
    jPanel1Layout
            .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartFinal)
                            .addContainerGap(0, Short.MAX_VALUE)));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartFinal)
                    .addContainerGap(0, Short.MAX_VALUE)));

}

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

@Override
protected JFreeChart generateChart(WCChartTheme chartTheme) {
    setChartHeight(36);//from   w  w  w.j ava  2 s  .  com

    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(null, null, yAxisLabel(), boxAndWhiskerXYDataset(),
            false);
    chart.getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    chart.setPadding(new RectangleInsets(0, 6, 0, 6));

    XYPlot plot = chart.getXYPlot();
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(new Color(0, 0, 0, 0));
    XYBoxAndWhiskerRenderer renderer = (XYBoxAndWhiskerRenderer) plot.getRenderer();
    renderer.setAutoPopulateSeriesOutlinePaint(true);

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(false);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(-0.5, assignmentOffering.assignment().submissionProfile().availablePoints() + 0.5);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    Font oldFont = rangeAxis.getTickLabelFont();
    rangeAxis.setTickLabelFont(oldFont.deriveFont(oldFont.getSize2D() * 0.8f));

    return chart;
}

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

/**
 * Creates a sample chart./*from  ww w  .j  ava2 s  .c o  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            !legendPanelOn, // include legend
            true, // tooltips?
            false // URLs?
    );

    // 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...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    IntervalMarker target = new IntervalMarker(4.5, 7.5);
    target.setLabel("Target Range");
    target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    target.setLabelAnchor(RectangleAnchor.LEFT);
    target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    target.setPaint(new Color(222, 222, 255, 128));
    plot.addRangeMarker(target, Layer.BACKGROUND);

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

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

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    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);
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    renderer.setBaseItemLabelGenerator(new CustomCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT,
            TextAnchor.CENTER_RIGHT, -Math.PI / 2.0);
    renderer.setBasePositiveItemLabelPosition(p);

    ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT,
            TextAnchor.CENTER_LEFT, -Math.PI / 2.0);
    renderer.setPositiveItemLabelPositionFallback(p2);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    // OPTIONAL CUSTOMISATION COMPLETED.
    setCategorySummary(dataset);
    return chart;

}

From source file:com.bt.aloha.batchtest.Chart.java

private JFreeChart createChart(XYDataset xydataset, String title, String xLabel, String yLabel) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart(title, xLabel, yLabel, xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    if (xydataset instanceof IntervalXYDataset) {
        DeviationRenderer deviationrenderer = new DeviationRenderer(true, true);
        deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
        deviationrenderer.setSeriesFillPaint(0, new Color(255, 200, 200));
        xyplot.setRenderer(deviationrenderer);
    }/*from w w w .  j av a  2 s . c om*/
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    numberaxis.setAutoRange(true);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}

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

/**
 * Creates a chart.//from   w ww.  j  av  a  2s.c  o m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    //   create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            domainLabel, // x axis label 
            rangeLabel, // y axis label  
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // 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...
    XYPlot plot = (XYPlot) chart.getPlot();

    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    //  renderer.setSeriesShape(0, java.awt.Shape.round);
    renderer.setBaseShapesVisible(false);
    renderer.setBaseShapesFilled(false);
    renderer.setBaseLinesVisible(true);

    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    //change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setUpperMargin(0.05);
    rangeAxis.setLowerMargin(0.05);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setAutoRangeIncludesZero(false);
    //  domainAxis.setTickLabelsVisible(false);
    //  domainAxis.setTickMarksVisible(false);      
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);

    // OPTIONAL CUSTOMISATION COMPLETED.
    setYSummary(dataset);

    return chart;
}

From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet.java

public JFreeChart getChart(CategoryDataset dataset) {
    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("? ?", // chart title
            "", // domain axis label
            "? (.)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*ww w.  j  av  a2 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);

    // final IntervalMarker target = new IntervalMarker(2000000, 3000000);
    // target.setLabel(" ");
    // target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    // target.setLabelAnchor(RectangleAnchor.LEFT);
    // target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    // target.setPaint(new Color(222, 222, 255, 128));
    // plot.addRangeMarker(target, Layer.BACKGROUND);

    // 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);
    renderer.setItemMargin(0.10);

    // 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 / 4.0)
    // CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
    );
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
}

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

/**
 * Creates a sample chart.//from   w w  w  . j a  va 2 s  . c  o m
 * 
 * @param dataset the dataset.
 * @return The chart.
 */
private JFreeChart createChart(CategoryDataset dataset, int typeOfChart) {
    String title = "";
    if (typeOfChart == 1)
        title = VCTTracUtil.getMessage("vcttrac.graph.statistic.compare.todayandyesterday", null);
    else if (typeOfChart == 2)
        title = VCTTracUtil.getMessage("vcttrac.year", null) + " : " + (new Date().getYear() + 1900);
    else if (typeOfChart == 3)
        title = VCTTracUtil.getMessage("vcttrac.graph.statistic.years", null);
    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(title, null, null, // chart title
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

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

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    Paint[] colors = createPaint();
    CustomBarRenderer renderer = new CustomBarRenderer(colors);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    plot.setRenderer(renderer);

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

    //      CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 12));
    if (typeOfChart < 2)
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
    else
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);

    return chart;

}

From source file:ac.kaist.ccs.presentation.CCSHubSelectionCost.java

/**
 * Creates a chart./*from   w  w w.  j a v a  2 s  .com*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            "Number of Hubs", // x axis label
            "Cost for pipeline transportation \nfrom CO2 emission source node to hubs", // 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);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

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

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    //renderer.setSeriesLinesVisible(0, false);
    //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());
    rangeAxis.setRange(minVal - (maxVal - minVal) * 0.05, maxVal + (maxVal - minVal) * 0.05);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

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

protected JFreeChart createChart(IntervalXYDataset dataset) {
    domainLabel = "Row_Number";
    rangeLabel = "Frequency";

    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, false, rangeLabel, dataset,
            PlotOrientation.VERTICAL, false, //!legendPanelOn,
            true, false);/*from w  w w.  j  ava2 s.c  om*/

    // 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.googlecode.refit.jenkins.ReFitGraph.java

/**
 * Creates a chart from the test result data set.
 * <p>//w w w. j av a  2  s.c o  m
 * The i-th row of the data set corresponds to the results from the i-th build.
 * Each row has columns 0, 1, 2 containing the number of failed, skipped and passed tests.
 * The chart stacks these values from bottom to top, joins the values for the same columns
 * with lines and fills the areas between the lines with given colours.
 * <p> 
 * TODO Find out if Jenkins core provides any caching for the chart or the data set.
 */
@Override
protected JFreeChart createGraph() {

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title
            null, // domain axis label 
            "count", // range axis label
            data, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );

    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();
    ChartUtil.adjustChebyshev(data, rangeAxis);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRange(true);

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        private static final long serialVersionUID = 1L;

        /**
         * Colour brush for the given data point.
         */
        @Override
        public Paint getItemPaint(int row, int column) {
            return super.getItemPaint(row, column);
        }

        /**
         * URL for the given data point, which gets opened when the user clicks on or near
         * the data point in the chart.
         */
        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getUrl();
        }

        /**
         * Tooltip to be displayed on the chart when the user hovers at or near the
         * data point.
         * <p>
         * The tooltip has the format {@code #17 : 300 Passed}, indicating the build number
         * and the number of tests with the given result.
         */
        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            TestResult result = label.getResult();
            String rowKey = (String) dataset.getRowKey(row);
            return result.getOwner().getDisplayName() + " : " + dataset.getValue(row, column) + " "
                    + rowKey.substring(1);
        }
    };
    plot.setRenderer(ar);

    // Define colours for the data points by column index
    ar.setSeriesPaint(0, ColorPalette.RED); // Failed
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Skipped
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Passed

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

    return chart;
}