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

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

Introduction

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

Prototype

public DateAxis() 

Source Link

Document

Creates a date axis with no label.

Usage

From source file:de.aidger.view.utils.Charts.java

/**
 * Creates a xy area chart./*from  w w w.  j ava  2 s  .  c o  m*/
 * 
 * @param title
 *            the diagram title
 * @param dataset
 *            the dataset.
 * @param width
 *            the width of the chart as image
 * @param height
 *            the height of the chart as image
 * @return the xy area chart as image
 */
public static ImageIcon createXYAreaChart(String title, XYDataset dataset, int width, int height) {
    JFreeChart chart = ChartFactory.createXYAreaChart(title, "", "", dataset, PlotOrientation.VERTICAL, false,
            false, false);

    Font titleFont = UIManager.getFont("TitledBorder.font");

    chart.setBackgroundPaint(null);
    chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14));
    chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor"));
    chart.setBorderPaint(null);

    XYPlot plot = chart.getXYPlot();
    plot.setInsets(new RectangleInsets(10, 1, 5, 1));
    plot.setBackgroundPaint(null);
    plot.setOutlineVisible(false);
    plot.setNoDataMessage(_("No data to display."));

    ValueAxis domainAxis = new DateAxis();
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setTickLabelFont(UIManager.getFont("RootPane.font"));

    ValueAxis rangeAxis = new NumberAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    plot.setDomainAxis(domainAxis);
    plot.setRangeAxis(rangeAxis);

    plot.setForegroundAlpha(0.5f);

    return new ImageIcon(chart.createBufferedImage(width, height));
}

From source file:org.projectforge.charting.XYChartBuilder.java

public XYChartBuilder setDateXAxis(final boolean showAxisValues) {
    xAxis = new DateAxis();
    ((DateAxis) xAxis).setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    xAxis.setLowerMargin(0.0);//from w w w .  j  a  v a  2s  . c  om
    xAxis.setUpperMargin(0.0);
    xAxis.setVisible(showAxisValues);
    plot.setDomainAxis(xAxis);
    return this;
}

From source file:com.sonyericsson.jenkins.plugins.bfa.graphs.TimeSeriesUnkownFailuresChart.java

@Override
protected JFreeChart createGraph() {
    TimeTableXYDataset dataset = createDataset();

    ValueAxis xAxis = new DateAxis();
    xAxis.setLowerMargin(0.0);/*  ww  w  .j  av  a 2 s . c  o m*/
    xAxis.setUpperMargin(0.0);

    Calendar lowerBound = getLowerGraphBound();
    xAxis.setRange(lowerBound.getTimeInMillis(), Calendar.getInstance().getTimeInMillis());

    NumberAxis yAxis = new NumberAxis(Y_AXIS_LABEL);
    yAxis.setRange(0, HUNDRED_PERCENT);

    XYItemRenderer renderer = new XYBarRenderer();

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);

    JFreeChart chart = new JFreeChart(graphTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.removeLegend();

    return chart;
}

From source file:ec.nbdemetra.benchmarking.calendarization.CalendarizationChartView.java

private static JFreeChart createChart(String title) {
    JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);

    result.setTitle(new TextTitle(title, new Font("SansSerif", Font.PLAIN, 12)));

    XYPlot plot = result.getXYPlot();/* w  w w .j a  v  a  2 s .  com*/
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    LinesThickness linesThickness = LinesThickness.Thin;

    XYLineAndShapeRenderer daily = new XYLineAndShapeRenderer(true, false);
    daily.setAutoPopulateSeriesPaint(false);

    daily.setAutoPopulateSeriesStroke(false);
    daily.setBaseStroke(TsCharts.getStrongStroke(linesThickness));
    plot.setRenderer(DAILY_INDEX, daily);

    XYDifferenceRenderer difference = new XYDifferenceRenderer();
    difference.setAutoPopulateSeriesPaint(false);
    difference.setAutoPopulateSeriesStroke(false);
    difference.setBaseStroke(TsCharts.getNormalStroke(linesThickness));
    plot.setRenderer(DIFF_INDEX, difference);

    XYLineAndShapeRenderer smooth = new XYLineAndShapeRenderer(true, false);
    smooth.setAutoPopulateSeriesPaint(false);
    smooth.setAutoPopulateSeriesStroke(false);
    smooth.setBaseStroke(TsCharts.getStrongStroke(linesThickness));
    plot.setRenderer(SMOOTH_INDEX, smooth);

    DateAxis domainAxis = new DateAxis();
    domainAxis.setTickMarkPosition(DateTickMarkPosition.START);
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);

    return result;
}

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 w w .  j a v  a 2s .c o 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:org.cds06.speleograph.GraphPanel.java

/**
 * Construct a new GraphPanel for an application instance.
 *
 * @param app The instance which should be linked with this Chart.
 *///from  ww w  . j a  va 2s  . co  m
public GraphPanel(SpeleoGraphApp app) {
    Validate.notNull(app);
    application = app;
    setLayout(new BorderLayout());
    dateAxis = new DateAxis();
    plot = new SpeleoXYPlot();
    chart = new JFreeChart(plot);
    new StandardChartTheme("JFree").apply(chart); // NON-NLS
    chartPanel = new ChartPanel(chart, false, true, false, true, true);
    chartPanel.addChartMouseListener(this);
    setupEmptyChart();
    Series.setGraphPanel(this);
    chartPanel.setPopupMenu(null);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setMouseZoomable(false);
    chartPanel.setDomainZoomable(true);
    add(chartPanel);
    log.info("GraphPanel is initialized");
}

From source file:ec.util.chart.swing.JTimeSeriesRendererSupportDemo.java

private static JFreeChart createTsChart() {
    XYPlot plot = new XYPlot();

    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

    DateAxis domainAxis = new DateAxis();
    domainAxis.setTickLabelsVisible(false);
    domainAxis.setLowerMargin(0.02);// www.j  a va2 s  .c  o m
    domainAxis.setUpperMargin(0.02);
    plot.setDomainAxis(domainAxis);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelsVisible(false);
    rangeAxis.setLowerMargin(0.02);
    rangeAxis.setUpperMargin(0.02);
    plot.setRangeAxis(rangeAxis);

    JFreeChart result = new JFreeChart("", null, plot, true);
    result.setPadding(new RectangleInsets(5, 5, 5, 5));
    result.getLegend().setFrame(BlockBorder.NONE);
    result.getLegend().setBackgroundPaint(null);

    return result;
}

From source file:no.met.jtimeseries.netcdf.plot.SimplePlotProvider.java

/**
 * Create a domain axis for the data.// w ww.  java 2  s .  c  o m
 * 
 * @param dataList List to create axis from
 * @return An axis for plotting, with time elements
 */
private DateAxis getDomainAxis(List<NumberPhenomenon> dataList) {
    DateAxis domainAxis = new DateAxis();
    domainAxis.setRange(dataList.get(0).getStartTime(), dataList.get(0).getEndTime());
    return domainAxis;
}

From source file:com.hmsinc.epicenter.webapp.chart.ChartService.java

/**
 * @param adapter/*  w w w .ja v  a 2  s.c  o m*/
 * @param annotations
 * @return
 */
private static JFreeChart createChart(final AbstractChart adapter, final List<XYAnnotation> annotations) {

    final JFreeChart chart;
    if (adapter.getItems() instanceof XYDataset) {

        chart = ChartFactory.createTimeSeriesChart(adapter.getTitle(), adapter.getXLabel(), adapter.getYLabel(),
                (XYDataset) adapter.getItems(), true, false, false);
        final ValueAxis domainAxis = new DateAxis();
        domainAxis.setLabelFont(LABEL_FONT);
        domainAxis.setTickLabelFont(LABEL_FONT);
        domainAxis.setLowerMargin(0.0);
        domainAxis.setUpperMargin(0.0);

        chart.getXYPlot().setDomainAxis(domainAxis);
        chart.getXYPlot().getRangeAxis().setLabelFont(LABEL_FONT);
        chart.getXYPlot().getRangeAxis().setTickLabelFont(LABEL_FONT);
        chart.getXYPlot().getRangeAxis().setStandardTickUnits(adapter.getRangeTickUnits());

        if (adapter.isAlwaysScaleFromZero()) {
            final double upperBound = chart.getXYPlot().getRangeAxis().getRange().getUpperBound();
            final Range range = new Range(0, upperBound + (upperBound * 0.2));
            chart.getXYPlot().getRangeAxis().setRange(range);
        }

        for (Marker marker : adapter.getMarkers()) {
            chart.getXYPlot().addDomainMarker(marker);
        }

        if (annotations != null) {
            for (XYAnnotation annotation : annotations) {
                if (annotation instanceof XYPointerAnnotation) {
                    ((XYPointerAnnotation) annotation).setFont(ANNOTATION_FONT);
                }
                chart.getXYPlot().addAnnotation(annotation);
            }
        }

        // Add any bands to the chart
        if (adapter instanceof TimeSeriesChart) {
            final TimeSeriesChart tsc = (TimeSeriesChart) adapter;
            for (int i = 0; i < tsc.getBands().size(); i++) {

                final Color c = tsc.getBandColors().get(i);
                final Color fill = tsc.getBandFillColors().get(i);
                final XYDifferenceRenderer renderer = new XYDifferenceRenderer(fill, fill, false);
                renderer.setSeriesPaint(0, c);
                renderer.setSeriesPaint(1, c);
                renderer.setSeriesStroke(0, LineStyle.THICK.getStroke());
                renderer.setSeriesStroke(1, LineStyle.THICK.getStroke());

                chart.getXYPlot().setDataset(i + 1, tsc.getBands().get(i));
                chart.getXYPlot().setRenderer(i + 1, renderer);
            }
        }

    } else if (adapter.getItems() instanceof CategoryDataset) {

        chart = ChartFactory.createBarChart(adapter.getTitle(), adapter.getXLabel(), adapter.getYLabel(),
                (CategoryDataset) adapter.getItems(), PlotOrientation.VERTICAL, true, false, false);
        chart.getCategoryPlot().getDomainAxis().setLabelFont(LABEL_FONT);
        chart.getCategoryPlot().getRangeAxis().setLabelFont(LABEL_FONT);
        chart.getCategoryPlot().getDomainAxis().setTickLabelFont(LABEL_FONT);
        chart.getCategoryPlot().getRangeAxis().setTickLabelFont(LABEL_FONT);

        if (adapter.isAlwaysScaleFromZero()) {
            final double upperBound = chart.getCategoryPlot().getRangeAxis().getRange().getUpperBound();
            final Range range = new Range(0, upperBound + (upperBound * 0.1));
            chart.getCategoryPlot().getRangeAxis().setRange(range);
        }

    } else {
        throw new UnsupportedOperationException("Unsupported chart type: " + adapter.getItems().getClass());
    }

    chart.getPlot().setNoDataMessage(NO_DATA_MESSAGE);

    return chart;
}

From source file:com.sonyericsson.jenkins.plugins.bfa.graphs.TimeSeriesChart.java

@Override
protected JFreeChart createGraph() {
    TimeTableXYDataset dataset = createDataset();
    ValueAxis xAxis = new DateAxis();
    xAxis.setLowerMargin(0.0);//from  w  w w .j a va  2 s  . c o  m
    xAxis.setUpperMargin(0.0);
    Calendar lowerBound = getLowerGraphBound();
    xAxis.setRange(lowerBound.getTimeInMillis(), Calendar.getInstance().getTimeInMillis());

    NumberAxis yAxis = new NumberAxis(Y_AXIS_LABEL);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    StackedXYBarRenderer renderer = new StackedXYBarRenderer();
    renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            String seriesKey = dataset.getSeriesKey(series).toString();
            StringBuilder sb = new StringBuilder();

            if (seriesKey.equals(GRAPH_OTHERS)) {
                long timeInMillis = dataset.getX(series, item).longValue();
                Date time = new Date(timeInMillis);

                TimePeriod period = null;
                if (intervalSize == Calendar.DATE) {
                    period = new Day(time);
                } else if (intervalSize == Calendar.HOUR_OF_DAY) {
                    period = new Hour(time);
                } else if (intervalSize == Calendar.MONTH) {
                    period = new Month(time);
                }
                List<FailureCauseTimeInterval> excludedDataList = excludedDataForPeriod.get(period);
                if (excludedDataList != null) {
                    Collections.sort(excludedDataList, new Comparator<FailureCauseTimeInterval>() {

                        @Override
                        public int compare(FailureCauseTimeInterval o1, FailureCauseTimeInterval o2) {
                            return o2.getNumber() - o1.getNumber();
                        }
                    });
                    for (FailureCauseTimeInterval excludedData : excludedDataList) {
                        sb.append(excludedData).append(" \n");
                    }
                }
            } else {
                int number = dataset.getY(series, item).intValue();
                sb.append(seriesKey).append(": ").append(number);
            }
            return sb.toString();
        }
    });

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    plot.setRangeAxis(yAxis);

    JFreeChart chart = new JFreeChart(graphTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    return chart;
}