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.wattzap.view.graphs.MMPGraph.java

public MMPGraph(XYSeries series) {
    super();//from   w w w.  j  a  va2 s .c o m

    NumberAxis yAxis = new NumberAxis(userPrefs.messages.getString("poWtt"));
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    double maxY = series.getMaxY();
    yAxis.setRange(0, maxY + 20);
    yAxis.setTickLabelPaint(Color.white);
    yAxis.setLabelPaint(Color.white);

    LogAxis xAxis = new LogAxis(userPrefs.messages.getString("time"));
    xAxis.setTickLabelPaint(Color.white);
    xAxis.setBase(4);
    xAxis.setAutoRange(false);

    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    xAxis.setRange(1, series.getMaxX() + 500);
    xAxis.setNumberFormatOverride(new NumberFormat() {

        @Override
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {

            long millis = (long) number * 1000;

            if (millis >= 60000) {
                return new StringBuffer(String.format("%d m %d s",
                        TimeUnit.MILLISECONDS.toMinutes((long) millis),
                        TimeUnit.MILLISECONDS.toSeconds((long) millis)
                                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis))));
            } else {
                return new StringBuffer(String.format("%d s",

                        TimeUnit.MILLISECONDS.toSeconds((long) millis)
                                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis))));
            }
        }

        @Override
        public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
            return new StringBuffer(String.format("%s", number));
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    });

    XYPlot plot = new XYPlot(new XYSeriesCollection(series), xAxis, yAxis,
            new XYLineAndShapeRenderer(true, false));

    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    chart.setBackgroundPaint(Color.gray);
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.darkGray);
    /*plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);*/

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelPaint(Color.white);
    domainAxis.setLabelPaint(Color.white);

    chartPanel = new ChartPanel(chart);
    chartPanel.setSize(100, 800);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setBackground(Color.gray);

    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);
    setBackground(Color.black);
    chartPanel.revalidate();
    setVisible(true);
}

From source file:net.sf.profiler4j.console.AllocDiffPanel.java

public AllocDiffPanel(int maxAgeMillis) {
    super(new BorderLayout());

    totalSeries = new TimeSeries("Allocs/Sec", Millisecond.class);
    totalSeries.setMaximumItemAge(maxAgeMillis);

    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    seriesCollection.addSeries(totalSeries);

    NumberAxis numberAxis = new NumberAxis("Allocs/Sec");
    numberAxis.setLabelFont(new Font("SansSerif", 0, 14));
    numberAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    DateAxis dateAxis = new DateAxis("Time");
    dateAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    dateAxis.setLabelFont(new Font("SansSerif", 0, 14));
    dateAxis.setAutoRange(true);//from w ww.j a va 2s  .  c  om
    dateAxis.setLowerMargin(0);
    dateAxis.setUpperMargin(0);
    dateAxis.setTickLabelsVisible(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
    lineRenderer.setSeriesPaint(0, Color.RED);
    lineRenderer.setSeriesPaint(1, Color.GREEN.darker());
    lineRenderer.setStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

    JFreeChart chart = new JFreeChart("Object Allocactions in Remote JVM",
            new Font("SansSerif", Font.PLAIN, 18), xyplot, true);
    chart.setBackgroundPaint(Color.white);

    ChartPanel panel = new ChartPanel(chart);
    panel.setBorder(createCompoundBorder(createEmptyBorder(8, 8, 8, 8), createLineBorder(Color.LIGHT_GRAY)));
    add(panel);
    setBorder(createEmptyBorder(8, 8, 8, 8));
}

From source file:org.mustbe.consulo.xprofiler.ui.mainPanel.MemoryPlotPanel.java

public MemoryPlotPanel(int maxAge, String title) {
    super(new BorderLayout());

    totalSeries = new TimeSeries("Committed Memory");
    totalSeries.setMaximumItemAge(maxAge);
    usedSeries = new TimeSeries("Used Memory");
    usedSeries.setMaximumItemAge(maxAge);
    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    seriesCollection.addSeries(totalSeries);
    seriesCollection.addSeries(usedSeries);

    NumberAxis numberAxis = new NumberAxis("Memory (KB)");

    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    DateAxis dateAxis = new DateAxis("Time");

    dateAxis.setAutoRange(true);//from www. jav a2  s  .  c  o  m
    dateAxis.setLowerMargin(0);
    dateAxis.setUpperMargin(0);
    dateAxis.setTickLabelsVisible(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
    lineRenderer.setSeriesPaint(0, JBColor.RED);
    lineRenderer.setSeriesPaint(1, JBColor.GREEN);
    lineRenderer.setDefaultStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer);
    xyplot.setBackgroundPainter(new ColorPainter(JBColor.white));
    xyplot.setDomainGridlinePaint(JBColor.LIGHT_GRAY);
    xyplot.setRangeGridlinePaint(JBColor.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

    JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.PLAIN, 14), xyplot, true);
    chart.setBackgroundPainter(new ColorPainter(JBColor.white));

    add(new ChartPanel(chart, 300, 300, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, true, true, false, false,
            false, false), BorderLayout.CENTER);
}

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

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("YIntervalChartDemo2", "Date", "Value",
            intervalxydataset, PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(true);/* ww  w.jav a 2s.  co m*/
    xyplot.setRangePannable(true);
    xyplot.setDomainAxis(new DateAxis("Date"));
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(false);
    XYErrorRenderer xyerrorrenderer = new XYErrorRenderer();
    xyerrorrenderer.setBaseLinesVisible(true);
    xyerrorrenderer.setUseFillPaint(true);
    xyerrorrenderer.setBaseFillPaint(Color.white);
    xyplot.setRenderer(xyerrorrenderer);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:it.alus.GPSreceiver.instruments.SatelliteRadar.java

public SatelliteRadar() {
    super(null);//from  w  w w  .  j  a v  a 2  s  .c om
    azimuth = new int[MAX_SAT];
    elevation = new int[MAX_SAT];
    snr = new int[MAX_SAT];
    resetArray();
    satSeries = new XYSeries("Satellites");
    XYSeriesCollection seriescollection = new XYSeriesCollection();
    seriescollection.addSeries(satSeries);
    jChart = ChartFactory.createPolarChart("Satellites", seriescollection, true, false, false);
    jChart.setBackgroundPaint(Color.white);
    PolarPlot polarplot = (PolarPlot) jChart.getPlot();
    polarplot.setBackgroundPaint(Color.lightGray);
    polarplot.setAngleGridlinePaint(Color.white);
    polarplot.setRadiusGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) polarplot.getAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    super.setChart(jChart);
    super.setMouseZoomable(false);
    super.setPreferredSize(new Dimension(500, 270));
}

From source file:org.shredzone.bullshitcharts.chart.LineChartGenerator.java

@Override
public Plot generate() {
    LineDatasetCreator dataset = new LineDatasetCreator();
    dataset.setTendency(getTendency());// w w  w  . j av a 2  s  .c om
    dataset.setNumberOfValues(getResolution());
    dataset.setAmplitude(getAmplitude());

    CategoryAxis catAxis = new CategoryAxis(getValue("x", "Time")); // TODO: i18n
    catAxis.setLowerMargin(0.0d);
    catAxis.setUpperMargin(0.0d);
    catAxis.setTickMarksVisible(false);
    catAxis.setTickLabelsVisible(false);

    ValueAxis valAxis = new NumberAxis(getValue("y", "Value"));
    valAxis.setRange(new Range(0.0d, 1.05d));
    valAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    valAxis.setTickMarksVisible(false);
    valAxis.setTickLabelsVisible(false);

    LineAndShapeRenderer renderer = new LineRenderer3D();
    renderer.setBaseShapesVisible(false);
    //        renderer.setStroke(new BasicStroke(2.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));

    CategoryPlot plot = new CategoryPlot(dataset.generate(), catAxis, valAxis, renderer);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    return plot;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Projected Values - Test", "Date", "Index Projection",
            xydataset, true, true, false);
    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setInsets(new RectangleInsets(5D, 5D, 5D, 20D));
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    ///*from  w ww  .jav a2s. co m*/
    DeviationRenderer renderer = new DeviationRenderer(true, false);
    renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    renderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1));
    renderer.setSeriesFillPaint(0, new Color(255, 200, 200));
    renderer.setSeriesFillPaint(1, new Color(200, 200, 255));
    plot.setRenderer(renderer);
    //
    NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis();
    valueAxis.setAutoRangeIncludesZero(false);
    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return chart;
}

From source file:org.openfaces.component.chart.impl.helpers.AxisUtil.java

public static void setupAxisPresentation(String label, Axis axis, FakeAxisStyle axisStyle) {
    StyleObjectModel model = axisStyle.getStyleObjectModel();
    StyleBorderModel border = model.getBorder();
    if (border != null) {
        if (border.getColor() != null) {
            axis.setAxisLinePaint(border.getColor());
        }/*from www.j a va 2  s.co m*/

        if (!border.isNone()) {
            axis.setAxisLineVisible(true);
            axis.setAxisLineStroke(PropertiesConverter.toStroke(border));
            axis.setTickMarkPaint(border.getColor());
            axis.setTickMarksVisible(true);
            if (!axis.isTickMarksVisible())
                axis.setTickMarksVisible(false);
        }

        if (border.getStyle().equalsIgnoreCase("none")) {
            axis.setAxisLineVisible(false);
            axis.setTickMarksVisible(false);
            if (axis.isTickMarksVisible())
                axis.setTickMarksVisible(true);
        }

    }

    axis.setTickLabelsVisible(axisStyle.isTickLabelsVisible());

    if (axisStyle.isLabelVisible() && label != null) {
        axis.setLabel(label);
        axis.setLabelPaint(model.getColor());
        axis.setLabelFont(CSSUtil.getFont(model));
    }

    if (axisStyle.isTickLabelsVisible()) {
        axis.setTickLabelsVisible(true);
        axis.setTickLabelPaint(model.getColor());
        axis.setTickLabelFont(CSSUtil.getFont(model));
    } else {
        axis.setTickLabelsVisible(false);
    }

    Double tickInterval = axisStyle.getTickInterval();
    if (tickInterval != null && tickInterval != 0 && axis instanceof NumberAxis) {
        NumberAxis numberAxis = (NumberAxis) axis;
        if (tickInterval > 0) {
            NumberTickUnit tickUnit = new NumberTickUnit(tickInterval);
            numberAxis.setTickUnit(tickUnit);
        } else if (tickInterval == -1) {
            TickUnitSource tickUnits = NumberAxis.createIntegerTickUnits();
            numberAxis.setStandardTickUnits(tickUnits);
        } else {
            throw new FacesException("tickInterval must be a positive number for a fixed tick interval, "
                    + "or -1 for automatic integer tick selection: " + tickInterval);
        }

        numberAxis.setMinorTickMarksVisible(true);
        numberAxis.setMinorTickCount(2);
        numberAxis.setMinorTickMarkOutsideLength(3);
        numberAxis.setMinorTickMarkInsideLength(3);
        numberAxis.setTickMarkInsideLength(5);
        numberAxis.setTickMarkOutsideLength(5);
    }

    axis.setTickMarkInsideLength(axisStyle.getTickInsideLength());
    axis.setTickMarkOutsideLength(axisStyle.getTickOutsideLength());
    if (axisStyle.getMinorTicksVisible()) {
        axis.setMinorTickMarksVisible(true);
        if (axis instanceof ValueAxis)
            ((ValueAxis) axis).setMinorTickCount(axisStyle.getMinorTickCount() + 1);
        axis.setMinorTickMarkInsideLength(axisStyle.getMinorTickInsideLength());
        axis.setMinorTickMarkOutsideLength(axisStyle.getMinorTickOutsideLength());
    } else {
        axis.setMinorTickMarksVisible(false);
    }
}

From source file:netplot.BarPlotPanel.java

private JFreeChart createChart() {
    collection = new XYSeriesCollection();
    collection.addSeries(series);/*  w w  w. ja v a2s  . c  o m*/
    dataset = new XYBarDataset(collection, 0.9);

    chart = ChartFactory.createXYBarChart(plotTitle, "", false, "", dataset, PlotOrientation.VERTICAL,
            enableLegend, true, true);

    plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    return chart;
}

From source file:grisu.frontend.view.swing.files.preview.fileViewers.JobStatusGridFileViewer.java

private static ChartPanel createChart(String title, String y_axis, XYDataset dataset, boolean createLegend) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            "Date", // x-axis label
            y_axis, // y-axis label
            dataset, // data
            createLegend, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );/*from   ww  w .j av a  2 s. c o m*/

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    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);

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

    final XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("dd.MM. HH:mm"));

    return new ChartPanel(chart);

}