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:gavisualizer.LineChart.java

@Override
public void generate() {
    // Creates Line Chart from variables
    JFreeChart chart = ChartFactory.createLineChart(_title, // chart title
            _axisLabelDomain, // domain axis label
            _axisLabelRange, // range axis label
            _dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            false, // tooltips
            false // urls
    );//from   ww w.j  a  v a 2  s. c o  m

    // Set the Plot to certain colors
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setOutlinePaint(Color.white);

    // Set Legend to the right of the chart
    final LegendTitle lt = (LegendTitle) chart.getLegend();
    lt.setPosition(RectangleEdge.RIGHT);

    // Set paints for lines in the chart
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    DefaultDrawingSupplier dw = new DefaultDrawingSupplier(PAINTS,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
    plot.setDrawingSupplier(dw);

    // Customize stroke width of the series
    ((AbstractRenderer) renderer).setAutoPopulateSeriesStroke(false);
    renderer.setBaseStroke(STROKE_WIDTH);
    renderer.setBaseShapesVisible(false);

    // Include dashed lines if necessary
    List<String> rows = _dataset.getRowKeys();

    // See if the title includes Downloads (Dashed lines are for Download lines)
    if (rows.get(rows.size() - 1).endsWith("Downloads")) {
        // Set the start to half the rows
        int start = _dataset.getRowCount() / 2;

        // Create an initial value
        int init = 0;

        // Iterate through the Download lines
        while (start < _dataset.getRowCount()) {
            // Make sure series and legend have dashes
            renderer.setSeriesStroke(start, DASHED_STROKE);
            LegendItemCollection legend = renderer.getLegendItems();
            LegendItem li = legend.get(start - 1);
            li.setLineStroke(DASHED_STROKE);

            // Make sure the color matches the undashed year
            renderer.setSeriesPaint(start, renderer.getItemPaint(init, 0));
            init++;
            start++;
        }
    }

    // Customise the range axis...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);

    _chart = chart;
}

From source file:slash.navigation.converter.gui.profileview.ProfileView.java

private XYPlot createPlot(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();//from   w w  w .  ja  v a  2  s  .  c o  m
    plot.setForegroundAlpha(0.65F);
    plot.setDomainGridlinesVisible(preferences.getBoolean(X_GRID_PREFERENCE, true));
    plot.setRangeGridlinesVisible(preferences.getBoolean(Y_GRID_PREFERENCE, true));

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(createIntegerTickUnits());
    Font font = new JLabel().getFont();
    rangeAxis.setLabelFont(font);

    NumberAxis valueAxis = (NumberAxis) plot.getDomainAxis();
    valueAxis.setStandardTickUnits(createIntegerTickUnits());
    valueAxis.setLowerMargin(0.0);
    valueAxis.setUpperMargin(0.0);
    valueAxis.setLabelFont(font);

    plot.getRenderer().setBaseToolTipGenerator(null);
    return plot;
}

From source file:co.udea.edu.proyectointegrador.gr11.parqueaderoapp.domain.stadistics.graphics.implement.Grafica.java

@Override
public JFreeChart createBarChartToVehicleType(List<TipoVehiculoEstadistica> tipoVehiculos) {
    //Se crea el conjunto de datos para realizar el grafico de barras

    DefaultCategoryDataset dataset = createDataForVehicleType(tipoVehiculos);

    //Se crea el grafico de barras
    JFreeChart chart = ChartFactory.createBarChart3D(TITLE_OF_BAR_CHART, //Titulo del grfico
            DOMAIN_AXIS_LABEL, //Nombre del dominio
            RANGE_AXIS_LABEL, //Nombre del Rango
            dataset, //Conjunto de datos
            PlotOrientation.VERTICAL, //Orientacion del grafico
            true, //Incluye leyendas
            true, false);/* w  w  w  . j a  v  a2 s  .  com*/
    //Se pinta el fondo de blanco
    chart.setBackgroundPaint(Color.WHITE);

    //Se pintan el fondo del grafico de gris y las lineas de blanco
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    categoryPlot.setBackgroundPaint(Color.LIGHT_GRAY);
    categoryPlot.setDomainGridlinePaint(Color.WHITE);
    categoryPlot.setRangeGridlinePaint(Color.WHITE);
    categoryPlot.setNoDataMessage(NO_DATA_TO_DISPLAY);

    //Se configura para que solo muestre nmeros enteros
    NumberAxis rangeAxis = (NumberAxis) categoryPlot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    BarRenderer barRenderer = (BarRenderer) categoryPlot.getRenderer();
    barRenderer.setDrawBarOutline(false);

    return chart;
}

From source file:Main.Chart.java

/**
 * Creates a chart.// w w  w .ja v a2s .  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("Weather Forecast", // chart title
            "Time", // x axis label
            "Temperature", // 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());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:msi.gama.hpc.gui.perspective.chart.HeadlessChart.java

private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart from XML output file", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from   ww w. ja va  2  s . c  o  m*/

    // 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());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:org.amanzi.awe.distribution.ui.widgets.DistributionChartWidget.java

public void updateChartType(final ChartType chartType) {
    final CategoryPlot plot = (CategoryPlot) distributionChart.getPlot();

    switch (chartType) {
    case LOGARITHMIC:
        final LogarithmicAxis logAxis = new LogarithmicAxis("Logarithmic");
        logAxis.setAllowNegativesFlag(true);
        plot.setRangeAxis(logAxis);//w  w w .j  a  va  2 s .  c  o m

        logAxis.setAutoRange(true);
        break;
    case COUNTS:
        final NumberAxis countAxis = new NumberAxis("Counts");
        countAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

        plot.setRangeAxis(countAxis);
        countAxis.setAutoRange(true);
        break;
    case PERCENTS:
        final NumberAxis percentageAxis = new NumberAxis("Percentage");
        percentageAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        percentageAxis.setRange(0, 100);

        plot.setRangeAxis(percentageAxis);
        break;
    }

    dataset.updateDelegate(chartType);

    update();
}

From source file:Client.Gui.TeamBarChart.java

/**
 * Creates a sample chart.//from  ww  w .  j  a  va2s  .com
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Distribution of Trainging", // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // 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...
    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));

    return chart;

}

From source file:com.argeloji.server.BarChartDemo4.java

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

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Cevap Dalm", // chart title
            "Seenekler", // domain axis label
            "renci Says", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );

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

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(0xFFFFFF));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();

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

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.GREEN, 0.0f, 0.0f, Color.GREEN);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.RED, 0.0f, 0.0f, Color.RED);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.RED, 0.0f, 0.0f, Color.RED);
    final GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.RED, 0.0f, 0.0f, Color.RED);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(3, gp3);

    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:net.nosleep.superanalyzer.analysis.views.TimeView.java

private void createChart() {
    // create the chart...
    _chart = ChartFactory.createLineChart(Misc.getString("LISTENING_TIMES"), // chart
            // title
            Misc.getString("HOUR_OF_DAY"), // domain axis label
            Misc.getString("SONG_COUNT"), // range axis label
            _dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );//from  w w w.ja v a 2s . c  o  m

    CategoryPlot plot = (CategoryPlot) _chart.getPlot();
    plot.setRangePannable(true);
    plot.setRangeZeroBaselineVisible(false);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);

    _chart.addSubtitle(HomePanel.createSubtitle(Misc.getString("LISTENING_TIMES_TOOLTIP")));

    ChartUtilities.applyCurrentTheme(_chart);

    // format the renderer after applying the theme
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(Color.white);
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0));

    // get rid of the little line above/next to the axis
    // plot.setRangeZeroBaselinePaint(Color.white);

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

    Misc.formatChart(plot);
    renderer.setSeriesPaint(0, Theme.getColorSet()[1]);

}

From source file:hudson.plugins.codeviation.RepositoryView.java

private JFreeChart createChart(CategoryDataset dataset, int max) {

    final JFreeChart chart = ChartFactory.createLineChart(null, // chart title
            null, // unused
            "counts", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );//  ww w.  j  av  a2s.  co  m

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

    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    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());
    rangeAxis.setUpperBound(max * 1.2);
    rangeAxis.setLowerBound(0);

    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setStroke(new BasicStroke(4.0f));

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

    return chart;
}