Example usage for org.jfree.chart.axis DateTickUnit DateTickUnit

List of usage examples for org.jfree.chart.axis DateTickUnit DateTickUnit

Introduction

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

Prototype

public DateTickUnit(int unit, int count) 

Source Link

Document

Creates a new date tick unit.

Usage

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

public TimePeriodValuesDemo1(String s) {
    super(s);//from ww  w . j  av  a 2  s.co  m
    XYDataset xydataset = createDataset1();
    XYBarRenderer xybarrenderer = new XYBarRenderer();
    DateAxis dateaxis = new DateAxis("Date");
    dateaxis.setVerticalTickLabels(true);
    dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1));
    dateaxis.setDateFormatOverride(new SimpleDateFormat("hh:mm"));
    dateaxis.setLowerMargin(0.01D);
    dateaxis.setUpperMargin(0.01D);
    NumberAxis numberaxis = new NumberAxis("Value");
    XYPlot xyplot = new XYPlot(xydataset, dateaxis, numberaxis, xybarrenderer);
    XYDataset xydataset1 = createDataset2();
    StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer(3);
    standardxyitemrenderer.setBaseShapesFilled(true);
    xyplot.setDataset(1, xydataset1);
    xyplot.setRenderer(1, standardxyitemrenderer);
    JFreeChart jfreechart = new JFreeChart("Supply and Demand", xyplot);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    chartpanel.setMouseZoomable(true, false);
    setContentPane(chartpanel);
}

From source file:be.ac.ua.comp.scarletnebula.gui.BareGraph.java

/**
 * Constructor./*from   ww w  .  java  2 s. c  om*/
 * 
 * @param maximumAge
 *            The age after which data is no longer displayed in the graph
 */
public BareGraph(final long maximumAge) {
    super(maximumAge);
    domain.setVisible(false);
    domain.setAutoRange(true);
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setTickLabelsVisible(true);
    final int secondsBetweenTicks = 30;
    domain.setTickUnit(new DateTickUnit(DateTickUnitType.SECOND, secondsBetweenTicks));

    range.setTickUnit(new NumberTickUnit(0.2, new DecimalFormat(), 5));
    range.setRange(0, 1);
    range.setVisible(false);
}

From source file:be.ac.ua.comp.scarletnebula.gui.DecoratedGraph.java

/**
 * Constructor/*from  w w w.  j ava 2s . com*/
 * 
 * @param maximumAge
 *            The age after which data is no longer displayed in the graph
 */
public DecoratedGraph(final long maximumAge, final Datastream stream) {
    super(maximumAge);
    this.stream = stream;
    domain.setVisible(false);
    domain.setAutoRange(true);
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setTickLabelsVisible(true);
    domain.setTickUnit(new DateTickUnit(DateTickUnitType.SECOND, 30));

    range.setTickUnit(new NumberTickUnit(0.2, new DecimalFormat(), 5));
    range.setAutoRange(true);
    range.setVisible(true);

}

From source file:org.sonar.server.charts.deprecated.SparkLinesChart.java

private void configureXAxis() {
    x = new DateAxis();
    x.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1));
    x.setTickLabelsVisible(false);/*from w w  w  .  ja  v a 2  s .c o  m*/
    x.setTickMarksVisible(false);
    x.setAxisLineVisible(false);
    x.setNegativeArrowVisible(false);
    x.setPositiveArrowVisible(false);
    x.setVisible(false);
}

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

/**
 * A demonstration application showing how to....
 *
 * @param title  the frame title.//from   ww  w. j  a va2  s  .com
 */
public TimePeriodValuesDemo(final String title) {

    super(title);

    final XYDataset data1 = createDataset1();
    final XYItemRenderer renderer1 = new XYBarRenderer();

    final DateAxis domainAxis = new DateAxis("Date");
    domainAxis.setVerticalTickLabels(true);
    domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.HOUR, 1));
    domainAxis.setDateFormatOverride(new SimpleDateFormat("hh:mm"));
    domainAxis.setLowerMargin(0.01);
    domainAxis.setUpperMargin(0.01);
    final ValueAxis rangeAxis = new NumberAxis("Value");

    final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1);

    final XYDataset data2 = createDataset2();
    final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(
            StandardXYItemRenderer.SHAPES_AND_LINES);
    renderer2.setShapesFilled(true);

    plot.setDataset(1, data2);
    plot.setRenderer(1, renderer2);

    final JFreeChart chart = new JFreeChart("Supply and Demand", plot);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setMouseZoomable(true, false);
    setContentPane(chartPanel);

}

From source file:org.perfmon4j.visualvm.chart.DynamicTimeSeriesChart.java

public DynamicTimeSeriesChart(int maxAgeInSeconds) {
    super(new BorderLayout());
    this.maxAgeInSeconds = maxAgeInSeconds;

    dataset = new TimeSeriesCollection();
    renderer = new MyXYRenderer();
    renderer.setBaseStroke(NORMAL_STROKE);

    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setAutoRange(false);//from  w  ww  .  j  a v a2  s .  co  m
    numberAxis.setRange(new Range(0d, 100d));

    DateAxis dateAxis = new DateAxis();
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
    dateAxis.setAutoRange(true);
    dateAxis.setFixedAutoRange(maxAgeInSeconds * 1000);
    dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.SECOND, 30));

    XYPlot plot = new XYPlot(dataset, dateAxis, numberAxis, renderer);
    JFreeChart chart = new JFreeChart(null, null, plot, false);
    chart.setBackgroundPaint(Color.white);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);
    chartPanel.setPopupMenu(null);

    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1),
            BorderFactory.createLineBorder(Color.black)));

    add(chartPanel);
}

From source file:de.atomfrede.tools.evalutation.tools.plot.TimePlot.java

@Override
protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) {
    XYDatasetWrapper mainDataset = datasetWrappers[0];

    JFreeChart chart = ChartFactory.createTimeSeriesChart(mainDataset.getSeriesName(), "Time",
            mainDataset.getSeriesName(), mainDataset.getDataset(), true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    // all adjustments for first/main dataset
    plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum());
    plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum());
    // some additional "design" stuff for the plot
    plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor());
    plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke()));

    for (int i = 1; i < datasetWrappers.length; i++) {
        XYDatasetWrapper wrapper = datasetWrappers[i];
        plot.setDataset(i, wrapper.getDataset());
        chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName());

        NumberAxis axis = new NumberAxis(wrapper.getSeriesName());
        plot.setRangeAxis(i, axis);/* w  w  w  .  j av  a 2 s  . c  o  m*/
        plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT);

        plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0);
        plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0);
        // map the second dataset to the second axis
        plot.mapDatasetToRangeAxis(i, i);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(false);
        renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke()));
        plot.setRenderer(i, renderer);
        plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor());
    }
    // change the background and gridline colors
    plot.setBackgroundPaint(Color.white);
    plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // format the date axis
    DateAxis axis = (DateAxis) plot.getDomainAxis();

    axis.setDateFormatOverride(new SimpleDateFormat("dd.MM HH:mm"));
    axis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1));
    axis.setVerticalTickLabels(true);
    return chart;
}

From source file:msec.org.Tools.java

public static String generateFullDayChart(String filename, OneDayValue[] data, String title) {
    if (data[0].getValues().length != 1440) {
        return "data size invalid";
    }//from   w  w w. j a  va 2  s. c  o  m
    if (data.length > 1) {
        if (data[1].getValues() == null || data[1].getValues().length != 1440) {
            return "data 1 invalid";
        }
    }

    XYDataset xydataset = createDataset(data);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true);

    try {
        XYPlot xyplot = (XYPlot) jfreechart.getPlot();

        //
        DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
        dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
        dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); //
        dateaxis.setLabelPaint(ChartColor.gray);
        dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        dateaxis.setTickLabelPaint(ChartColor.GRAY);

        GregorianCalendar endgc = (GregorianCalendar) gc.clone();
        endgc.add(GregorianCalendar.DATE, 1);
        dateaxis.setMaximumDate(endgc.getTime());

        dateaxis.setTickMarksVisible(true);
        dateaxis.setTickMarkInsideLength(5);
        dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2));
        dateaxis.setVerticalTickLabels(true);
        dateaxis.setLabel("");

        //
        ValueAxis rangeAxis = xyplot.getRangeAxis();//?
        rangeAxis.setLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setLabelPaint(ChartColor.gray);
        rangeAxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setTickLabelPaint(ChartColor.gray);
        rangeAxis.setLowerBound(0);

        //
        jfreechart.getLegend().setItemFont(new Font("", Font.PLAIN, 12));
        jfreechart.getLegend().setItemPaint(ChartColor.gray);
        jfreechart.getLegend().setBorder(0, 0, 0, 0);//

        //
        jfreechart.getTitle().setFont(new Font("", Font.PLAIN, 18));//
        jfreechart.getTitle().setPaint(ChartColor.gray);

        //?
        xyplot.setRangeGridlinePaint(ChartColor.GRAY);
        xyplot.setBackgroundPaint(ChartColor.WHITE);
        xyplot.setOutlinePaint(null);//

        int w = 500;
        int h = 300;

        // ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h);
        ChartUtilities.saveChartAsJPEG(new File(filename), 0.8f, jfreechart, w, h);

        return "success";

    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.TimeChartRenderer.java

private DateTickUnit getTickUnit(TimePeriod timePeriod) {
    DateTickUnit tickUnit = null;/*ww w .  ja  v a2  s . c o  m*/
    if (timePeriod.equals(TimePeriod.MINUTE)) {
        tickUnit = new DateTickUnit(DateTickUnit.MINUTE, 10);
    } else if (timePeriod.equals(TimePeriod.HOUR)) {
        tickUnit = new DateTickUnit(DateTickUnit.HOUR, 1);
    } else if (timePeriod.equals(TimePeriod.DAY)) {
        tickUnit = new DateTickUnit(DateTickUnit.DAY, 1);
    } else if (timePeriod.equals(TimePeriod.WEEK)) {
        tickUnit = new DateTickUnit(DateTickUnit.DAY, 7);
    } else if (timePeriod.equals(TimePeriod.MONTH)) {
        tickUnit = new DateTickUnit(DateTickUnit.MONTH, 1);
    } else {
        tickUnit = new DateTickUnit(DateTickUnit.HOUR, 1);
    }
    return tickUnit;
}

From source file:com.mothsoft.alexis.web.ChartServlet.java

private void doLineGraph(final HttpServletRequest request, final HttpServletResponse response,
        final String title, final String[] dataSetIds, final Integer width, final Integer height,
        final Integer numberOfSamples) throws ServletException, IOException {

    final DataSetService dataSetService = WebApplicationContextUtils
            .getWebApplicationContext(this.getServletContext()).getBean(DataSetService.class);

    final OutputStream out = response.getOutputStream();
    response.setContentType("image/png");
    response.setHeader("Cache-Control", "max-age: 5; must-revalidate");

    final XYSeriesCollection seriesCollection = new XYSeriesCollection();

    final DateAxis dateAxis = new DateAxis(title != null ? title : "Time");
    final DateTickUnit unit = new DateTickUnit(DateTickUnit.HOUR, 1);
    final DateFormat chartFormatter = new SimpleDateFormat("ha");
    dateAxis.setDateFormatOverride(chartFormatter);
    dateAxis.setTickUnit(unit);/*from   w  w w  .j  a v  a2 s.c o  m*/
    dateAxis.setLabelFont(DEFAULT_FONT);
    dateAxis.setTickLabelFont(DEFAULT_FONT);

    if (numberOfSamples > 12) {
        dateAxis.setTickLabelFont(
                new Font(DEFAULT_FONT.getFamily(), Font.PLAIN, (int) (DEFAULT_FONT.getSize() * .8)));
    }

    final NumberAxis yAxis = new NumberAxis("Activity");

    final StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);

    int colorCounter = 0;

    if (dataSetIds != null) {
        for (final String dataSetIdString : dataSetIds) {
            final Long dataSetId = Long.valueOf(dataSetIdString);
            final DataSet dataSet = dataSetService.get(dataSetId);

            // go back for numberOfSamples, but include current hour
            final Calendar calendar = new GregorianCalendar();
            calendar.add(Calendar.HOUR_OF_DAY, -1 * (numberOfSamples - 1));
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            final Timestamp startDate = new Timestamp(calendar.getTimeInMillis());

            calendar.add(Calendar.HOUR_OF_DAY, numberOfSamples);
            calendar.set(Calendar.MINUTE, 59);
            calendar.set(Calendar.SECOND, 59);
            calendar.set(Calendar.MILLISECOND, 999);
            final Timestamp endDate = new Timestamp(calendar.getTimeInMillis());

            logger.debug(String.format("Generating chart for period: %s to %s", startDate.toString(),
                    endDate.toString()));

            final List<DataSetPoint> dataSetPoints = dataSetService
                    .findAndAggregatePointsGroupedByUnit(dataSetId, startDate, endDate, TimeUnits.HOUR);

            final boolean hasData = addSeries(seriesCollection, dataSet.getName(), dataSetPoints, startDate,
                    numberOfSamples, renderer);

            if (dataSet.isAggregate()) {
                renderer.setSeriesPaint(seriesCollection.getSeriesCount() - 1, Color.BLACK);
            } else if (hasData) {
                renderer.setSeriesPaint(seriesCollection.getSeriesCount() - 1,
                        PAINTS[colorCounter++ % PAINTS.length]);
            } else {
                renderer.setSeriesPaint(seriesCollection.getSeriesCount() - 1, Color.LIGHT_GRAY);
            }
        }
    }

    final XYPlot plot = new XYPlot(seriesCollection, dateAxis, yAxis, renderer);

    // create the chart...
    final JFreeChart chart = new JFreeChart(plot);

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

    // get a reference to the plot for further customisation...
    plot.setBackgroundPaint(new Color(253, 253, 253));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabelFont(DEFAULT_FONT);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerBound(0.00d);

    ChartUtilities.writeChartAsPNG(out, chart, width, height);
}