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.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet.java

public JFreeChart getChart(CategoryDataset dataset) {
    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart3D(" ", // chart title
            "", // domain axis label
            " (.)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//from   ww w.jav a2s .c o m

    //      #44639C;

    TextTitle title = new TextTitle("  ", labelFont);
    //      Paint paint = title.getPaint();
    title.setPaint(new Color(68, 99, 156));
    chart.setTitle(title);

    // 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());
    rangeAxis.setTickLabelFont(labelFont);

    // 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.blue);
    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.optaplanner.examples.cheaptime.swingui.CheapTimePanel.java

private XYPlot createTaskAssignmentPlot(TangoColorFactory tangoColorFactory, CheapTimeSolution solution) {
    OHLCSeriesCollection seriesCollection = new OHLCSeriesCollection();
    Map<Machine, OHLCSeries> machineSeriesMap = new LinkedHashMap<Machine, OHLCSeries>(
            solution.getMachineList().size());
    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setTickLength(0.0);/*  w  w w .j a  va  2s  . c  om*/
    int seriesIndex = 0;
    OHLCSeries unassignedProjectSeries = new OHLCSeries("Unassigned");
    seriesCollection.addSeries(unassignedProjectSeries);
    machineSeriesMap.put(null, unassignedProjectSeries);
    renderer.setSeriesStroke(seriesIndex, new BasicStroke(3.0f));
    renderer.setSeriesPaint(seriesIndex, TangoColorFactory.SCARLET_1);
    seriesIndex++;
    for (Machine machine : solution.getMachineList()) {
        OHLCSeries machineSeries = new OHLCSeries(machine.getLabel());
        seriesCollection.addSeries(machineSeries);
        machineSeriesMap.put(machine, machineSeries);
        renderer.setSeriesStroke(seriesIndex, new BasicStroke(3.0f));
        renderer.setSeriesPaint(seriesIndex, tangoColorFactory.pickColor(machine));
        seriesIndex++;
    }
    List<TaskAssignment> taskAssignmentList = new ArrayList<TaskAssignment>(solution.getTaskAssignmentList());
    Collections.sort(taskAssignmentList,
            groupByMachineCheckBox.isSelected() ? groupByMachineTaskAssignmentComparator
                    : stableTaskAssignmentComparator);
    int pixelIndex = 0;
    for (TaskAssignment taskAssignment : taskAssignmentList) {
        Task task = taskAssignment.getTask();
        Integer startPeriod = taskAssignment.getStartPeriod();
        Integer endPeriod = taskAssignment.getEndPeriod();
        if (startPeriod == null) {
            startPeriod = task.getStartPeriodRangeFrom();
            endPeriod = startPeriod + task.getDuration();
        }
        OHLCSeries machineSeries = machineSeriesMap.get(taskAssignment.getMachine());
        machineSeries.add(new FixedMillisecond(pixelIndex), task.getStartPeriodRangeFrom(), startPeriod,
                endPeriod, task.getStartPeriodRangeTo() + task.getDuration());
        pixelIndex++;
    }
    NumberAxis domainAxis = new NumberAxis("Task");
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setRange(-0.5, taskAssignmentList.size() - 0.5);
    domainAxis.setInverted(true);
    return new XYPlot(seriesCollection, domainAxis, null, renderer);
}

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 a  v a2s .  co  m
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    numberaxis.setAutoRange(true);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}

From source file:org.sbml.bargraph.MainWindow.java

/**
 * Creates an empty bar graph.//ww  w  .j  ava 2 s.  c  o  m
 * @return
 */
public JFreeChart createModelBarGraph() {
    // Initialize the style. Have to do this before creating charts.

    BarRenderer.setDefaultShadowsVisible(false);
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());

    // Create the actual chart.

    chartData = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createBarChart(null, // chart title
            null, // domain axis label
            "Total count", // range axis label
            chartData, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            false, // tooltips?
            false // URLs?
    );

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, new Color(0, 101, 178));

    return chart;
}

From source file:com.redhat.thermostat.byteman.chart.swing.SwingBarChart.java

private JFreeChart createChart(Collection<PlotRecord> records) {
    // data//from  ww w. j  ava  2  s.c  o m
    DefaultCategoryDataset ds = new DefaultCategoryDataset();
    for (PlotRecord re : records) {
        Long label = re.getPeriodStart() + ((re.getPeriodEnd() - re.getPeriodStart()) / 2);
        ds.addValue(re.getValue(), re.getCategory(), label);
    }
    // chart
    BarRenderer3D br = new StackedBarRenderer3D(cf.rendered3dXOffset, cf.rendered3dYOffset);
    ZoomablePlot plot = new ZoomablePlot(zm, ds, new CategoryAxis(), new NumberAxis(), br);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    ChartFactory.getChartTheme().apply(chart);
    // renderer
    br.setSeriesPaint(0, toColor(cf.seriesPaint0));
    br.setSeriesPaint(1, toColor(cf.seriesPaint1));
    br.setSeriesPaint(2, toColor(cf.seriesPaint2));
    br.setSeriesPaint(3, toColor(cf.seriesPaint3));
    br.setSeriesPaint(4, toColor(cf.seriesPaint4));
    br.setSeriesPaint(5, toColor(cf.seriesPaint5));
    br.setWallPaint(toColor(cf.wallPaint));
    br.setBaseItemLabelsVisible(cf.baseItemLabelsVisible);
    br.setShadowVisible(cf.shadowVisible);
    br.setItemMargin(cf.itemMargin);
    // plot
    plot.setBackgroundPaint(toColor(cf.backgroundPaint));
    plot.setBackgroundImageAlpha((float) cf.backgroundImageAlpha);
    plot.setDomainGridlinesVisible(cf.domainGridlinesVisible);
    plot.setRangeGridlinePaint(toColor(cf.rangeGridlinePaint));
    //        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 * cf.domainAxisLabelAngle));
    plot.getDomainAxis().setLowerMargin(cf.domainAxisLowerMargin);
    plot.getDomainAxis().setUpperMargin(cf.domainAxisUpperMargin);
    plot.getDomainAxis().setLabel(cf.domainAxisLabel);
    plot.setOutlineVisible(cf.outlineVisible);

    return chart;
}

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

/**
 * Creates a chart.//from ww  w .j  av a2  s.  c  o  m
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

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

    // set the background color for the chart...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setAnchor(StandardLegend.SOUTH);

    chart.setBackgroundPaint(Color.white);
    final TextTitle subtitle = new TextTitle("An area chart demonstration.  We use this subtitle "
            + " as an example of what happens when you get a really long title or subtitle.");
    subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12));
    subtitle.setPosition(RectangleEdge.TOP);
    //        subtitle.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.05));
    subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
    chart.addSubtitle(subtitle);

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

    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelAngle(0 * Math.PI / 2.0);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:model.LineChart.java

/**
 * Creates a chart./*w  w w.ja va  2  s . c o m*/
 *
 * @param dataset the data for the chart.
 *
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset, final int variableOption, final String machine) {

    String title = "";
    switch (variableOption) {
    case 0:
        title = "Quantity";
        break;
    case 1:
        title = "Size";
        break;
    default:
        title = "Type";
        break;
    }

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart(title + " Line Chart: " + machine, // chart title
            title, // x axis label
            "Time", // 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:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java

private static JFreeChart createBarChart3D(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createBarChart3D("Bar Chart 3D Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from w w w . j a v  a  2 s.  co m*/

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setForegroundAlpha(0.5f);

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

    BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();

    // set up gradient paints for series...
    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);

    return chart;

}

From source file:EHRAppointment.ChartPanelDraw.java

private ChartPanel createChart(XYDataset dataset, String type) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(type, "Date", getValueAxis(), dataset);

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    plot.setRenderer(renderer);/*from  w  ww.  j a  v a  2 s  . com*/

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return new ChartPanel(chart);
}

From source file:gov.sandia.umf.platform.ui.jobs.Raster.java

public JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createScatterPlot(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );/*from   w  w w. j ava 2 s. c o m*/

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setDomainPannable(true);
    plot.setRangePannable(true);

    plot.setRenderer(new XYDotRenderer() {
        public void drawItem(java.awt.Graphics2D g2, XYItemRendererState state,
                java.awt.geom.Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis,
                ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState,
                int pass) {
            // Copied from org.jfree.chart.renderer.xy.XYDotRenderer.java and modified.
            // This would only need to be a couple of lines if they authors of jfreechart had not made dotWidth and dotHeight private members.
            // Yet another example of textbook OO programming gone awry. (Can anyone hear me scream?)

            if (!getItemVisible(series, item))
                return;

            int dotWidth = 1;

            double rasterLines = rangeAxis.getRange().getLength();
            int pixels = g2.getClipBounds().height;
            double height = pixels / rasterLines;
            if (height > 10)
                height -= 2;
            else if (height > 2)
                height -= 1;
            int dotHeight = (int) Math.min(20, Math.max(1, Math.floor(height)));

            double x = dataset.getXValue(series, item);
            double y = dataset.getYValue(series, item);
            if (Double.isNaN(y))
                return;
            double adjx = (dotWidth - 1) / 2.0;
            double adjy = (dotHeight - 1) / 2.0;

            RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
            RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
            double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
            double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;

            g2.setPaint(Color.black);
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL)
                g2.fillRect((int) transY, (int) transX, dotHeight, dotWidth);
            else
                g2.fillRect((int) transX, (int) transY, dotWidth, dotHeight);

            int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
            int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
            updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                    orientation);
        }
    });

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Integer units only

    return chart;
}