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:org.jfree.chart.demo.XYBarChartDemo4.java

/**
 * Constructs the demo application./*from   w w w.j  a va2  s  . c  o  m*/
 *
 * @param title  the frame title.
 */
public XYBarChartDemo4(final String title) {

    super(title);

    final IntervalXYDataset dataset = createDataset();

    final JFreeChart chart = ChartFactory.createXYBarChart(title, "X", false, "Y", dataset,
            PlotOrientation.VERTICAL, true, false, false);

    // then customise it a little...
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue));
    final XYPlot plot = (XYPlot) chart.getPlot();
    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
    setContentPane(chartPanel);

}

From source file:uom.research.thalassemia.util.BarChartCreator.java

/**
 * Creates a sample chart./*from  w w w. j av  a2 s  . c o m*/
 *
 * @param dataset the dataset.
 *
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(mainTitle, xTitle, yTitle, dataset);
    chart.addSubtitle(new TextTitle(subTitle));
    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);
    chart.getLegend().setFrame(BlockBorder.NONE);
    return chart;
}

From source file:org.btrg.df.betterologist.swingui.ProjectJobSchedulingPanel.java

private JFreeChart createChart(Schedule schedule) {
    YIntervalSeriesCollection seriesCollection = new YIntervalSeriesCollection();
    Map<Project, YIntervalSeries> projectSeriesMap = new LinkedHashMap<Project, YIntervalSeries>(
            schedule.getProjectList().size());
    YIntervalRenderer renderer = new YIntervalRenderer();
    int maximumEndDate = 0;
    int seriesIndex = 0;
    for (Project project : schedule.getProjectList()) {
        YIntervalSeries projectSeries = new YIntervalSeries(project.getLabel());
        seriesCollection.addSeries(projectSeries);
        projectSeriesMap.put(project, projectSeries);
        renderer.setSeriesShape(seriesIndex, new Rectangle());
        renderer.setSeriesStroke(seriesIndex, new BasicStroke(3.0f));
        seriesIndex++;//  ww w.  j  a va 2  s  . com
    }
    for (Allocation allocation : schedule.getAllocationList()) {
        int startDate = allocation.getStartDate();
        int endDate = allocation.getEndDate();
        YIntervalSeries projectSeries = projectSeriesMap.get(allocation.getProject());
        projectSeries.add(allocation.getId(), (startDate + endDate) / 2.0, startDate, endDate);
        maximumEndDate = Math.max(maximumEndDate, endDate);
    }
    NumberAxis domainAxis = new NumberAxis("Job");
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setRange(-0.5, schedule.getAllocationList().size() - 0.5);
    domainAxis.setInverted(true);
    NumberAxis rangeAxis = new NumberAxis("Day (start to end date)");
    rangeAxis.setRange(-0.5, maximumEndDate + 0.5);
    XYPlot plot = new XYPlot(seriesCollection, domainAxis, rangeAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    return new JFreeChart("Project Job Scheduling", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

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  w  w .j a v a 2s  .com*/
    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: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);/*from  w w w.j ava 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.mili.jmibs.jfree.JFreeChartBarIterationObjectLoadBenchmarkSuiteResultRenderer.java

private JFreeChart createChart(String title, CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(title, "Benchmark (Iteration/Object Loading)", "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);//from   w  w  w .  ja  v a2s  .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.mili.jmibs.jfree.JFreeChartBarIterationObjectLoadIntervalBenchmarkSuiteResultRenderer.java

private JFreeChart createChart(String title, CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(title, "Benchmark (Iteration/Object Loading/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 . j  a  v  a  2  s.  c om
    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:ejemplo.Ejemplo.java

private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart Demo 6", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );//from www . j a v a2  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.jfree.chart.demo.LineChartDemo3.java

/**
 * Creates a chart.//  ww  w.j  a v  a  2  s .c o  m
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart based on the supplied dataset.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart Demo 3", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

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

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPlotShapes(true);

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

    return chart;
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java

/**
 * Creates either a domain- or a range-axis according to its <code>AxesSettings</code>
 * //from  w  w w.  jav  a 2s.com
 * @param aLabel
 *            Axis label.
 * @param aTick
 *            Flag indicating if IntegerTicks are to be created.
 * @param aLog
 *            Flag indicating if axis must be logarithmic.
 * @param aRange
 *            Suggested data as specified in the settings. Currently ignored.
 * @param aDataRange
 *            Range of the data, as computed from the point coordinates.
 * @return Newly initialized <code>NumberAxis</code>.
 */
private static NumberAxis createAxis(String aLabel, boolean aTick, boolean aLog, IntRange aRange,
        Range aDataRange) {
    NumberAxis axis = null;
    if (aLog) {
        MyLogarithmicAxis logAxis = new MyLogarithmicAxis(aLabel, aDataRange);
        // LogarithmicAxis logAxis = new LogarithmicAxis(aLabel);
        axis = logAxis;
        logAxis.autoAdjustRange();
        logAxis.setAllowNegativesFlag(true);
        // logAxis.setAutoTickUnitSelection(false);
        logAxis.setAutoRange(false);
    } else {
        axis = new NumberAxis(aLabel);
        if (aTick)
            axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    return axis;
}