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

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

Introduction

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

Prototype

public void setMaximumDate(Date maximumDate) 

Source Link

Document

Sets the maximum date visible on the axis and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java

public static void customizeDateAxis(DateAxis axis, ChartParams params, String prefix) {
    customizeValueAxis(axis, params, prefix);

    if (params.get(prefix + ChartParams.DATE_AXIS_DATE_FORMAT_OVERRIDE_SUFFIX) != null) {
        axis.setDateFormatOverride(//from ww  w. j  ava2  s.c o m
                params.getDateFormat(prefix + ChartParams.DATE_AXIS_DATE_FORMAT_OVERRIDE_SUFFIX));
    }
    if (params.get(prefix + ChartParams.DATE_AXIS_UPPER_DATE_SUFFIX) != null) {
        axis.setMaximumDate(params.getDate(prefix + ChartParams.DATE_AXIS_UPPER_DATE_SUFFIX));
    }
    if (params.get(prefix + ChartParams.DATE_AXIS_LOWER_DATE_SUFFIX) != null) {
        axis.setMinimumDate(params.getDate(prefix + ChartParams.DATE_AXIS_LOWER_DATE_SUFFIX));
    }
    if (params.get(prefix + ChartParams.DATE_AXIS_DATE_TICK_MARK_POSITION_SUFFIX) != null) {
        axis.setTickMarkPosition(
                params.getDateTickMarkPosition(prefix + ChartParams.DATE_AXIS_DATE_TICK_MARK_POSITION_SUFFIX));
    }
    if (params.get(prefix + ChartParams.DATE_AXIS_DATE_TICK_UNIT_SUFFIX) != null) {
        if (axis.isAutoTickUnitSelection()) {
            axis.setAutoTickUnitSelection(false);
        }
        axis.setTickUnit(params.getDateTickUnit(prefix + ChartParams.DATE_AXIS_DATE_TICK_UNIT_SUFFIX));
    }
}

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";
    }//w  w  w .j a v a 2  s.  com
    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:msec.org.Tools.java

public static String generateDaysChart(String filename, ArrayList<OneDayValue> data, OneAttrDaysChart chart,
        String title, int duration) {
    if (data.size() == 0) {
        return "data size invalid";
    }//w  w  w  .j  av a  2 s.c  o  m

    int date = Integer.parseInt(data.get(0).getDate());
    GregorianCalendar startgc = new GregorianCalendar(date / 10000, date % 10000 / 100 - 1, date % 100);

    XYDataset xydataset = createDaysDataset(data, startgc, chart);
    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("MM/dd"));
        dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); //
        dateaxis.setLabelPaint(ChartColor.gray);
        dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        dateaxis.setTickLabelPaint(ChartColor.GRAY);

        dateaxis.setMinimumDate(startgc.getTime());
        GregorianCalendar endgc = (GregorianCalendar) startgc.clone();
        endgc.add(GregorianCalendar.DATE, duration);
        dateaxis.setMaximumDate(endgc.getTime());

        dateaxis.setTickMarksVisible(true);
        dateaxis.setTickMarkInsideLength(5);
        dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1));
        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.endeavour.mgmt.controller.servlet.CreateProjectPlan.java

private void createReportPage(Document aDocument, TaskSeries aTaskSeries, Date aStartDate, Date aEndDate,
        String aDescription) throws Exception {

    TaskSeriesCollection theDataset = new TaskSeriesCollection();
    theDataset.add(aTaskSeries);/*from w  w  w. j  av a 2s. c o m*/

    DateAxis theDateRange = new DateAxis(TIMELINE);
    theDateRange.setMinimumDate(aStartDate);
    theDateRange.setMaximumDate(aEndDate);

    JFreeChart theChart = ChartFactory.createGanttChart(aDescription, ARTIFACTS, null, theDataset, true, false,
            false);
    CategoryPlot theCategoryPlot = theChart.getCategoryPlot();
    theCategoryPlot.setRangeAxis(theDateRange);

    BufferedImage theChartImage = theChart.createBufferedImage(780, 520);
    ByteArrayOutputStream theOutputStream = new ByteArrayOutputStream();
    ImageIO.write(theChartImage, "png", theOutputStream);
    Image theDocumentImage = Image.getInstance(theOutputStream.toByteArray());
    aDocument.add(theDocumentImage);
}

From source file:org.squale.squaleweb.util.graph.HistoMaker.java

/**
 * This method create the JFreechart chart
 * /*from   w w w  .  j av a  2  s.  c  o  m*/
 * @param maxAxisToday Does the max for the date axis should be set to today ?
 * @return A JFreeChart chart
 */
public JFreeChart getChart(boolean maxAxisToday) {
    JFreeChart retChart = super.getChart();
    if (null == retChart) {
        retChart = ChartFactory.createTimeSeriesChart(mTitle, mXLabel, mYLabel, mDataSet, mShowLegend, false,
                false);
        XYPlot plot = retChart.getXYPlot();
        XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
        xylineandshaperenderer.setBaseShapesVisible(true);
        plot.setRenderer(xylineandshaperenderer);
        SimpleDateFormat sdf = new SimpleDateFormat(mDateFormat);
        DateAxis axis = (DateAxis) plot.getDomainAxis();
        if (maxAxisToday) {
            axis.setMaximumDate(new Date());
        }
        axis.setDateFormatOverride(sdf);
        ValueAxis yAxis = plot.getRangeAxis();
        yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        yAxis.setAutoRangeMinimumSize(2.0);
        super.setChart(retChart);
    }
    return retChart;
}

From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java

/**
 * Creates a chart of the actual view with a title.
 * @param title//from www  . j a  v a 2  s. c o m
 *            The title of the chart.
 */
protected final void makeChart(final String title) {
    DateTickUnit tick = null;
    switch (actualView) {
    case DAY:
        tick = new DateTickUnit(DateTickUnitType.HOUR, 1, new SimpleDateFormat("HH"));
        break;
    case WEEK:
        tick = new DateTickUnit(DateTickUnitType.DAY, 1, new SimpleDateFormat("E, dd.MM."));
        break;
    case MONTH:
        tick = new DateTickUnit(DateTickUnitType.DAY, 1, new SimpleDateFormat("d."));
        break;
    case YEAR:
        tick = new DateTickUnit(DateTickUnitType.MONTH, 1, new SimpleDateFormat("M"));
        break;
    default:
        break;
    }
    gui.pnlGraph.setChart(ChartFactory.createGanttChart(title, "", "", createDataset(), true, true, false));
    gui.pnlGraph.getChart().getTitle().setHorizontalAlignment(HorizontalAlignment.LEFT);
    gui.pnlGraph.getChart().getTitle().setMargin(5, 10, 5, 5);
    gui.pnlGraph.getChart().getCategoryPlot().getDomainAxis().setCategoryMargin(0.4);
    gui.pnlGraph.getChart().getCategoryPlot().getDomainAxis().setLowerMargin(0);
    gui.pnlGraph.getChart().getCategoryPlot().getDomainAxis().setUpperMargin(0);

    // chart.getCategoryPlot().getDomainAxis().getL

    gui.pnlGraph.getChart().getCategoryPlot().getDomainAxis()
            .setTickLabelFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));

    CategoryPlot plot = gui.pnlGraph.getChart().getCategoryPlot();
    DateAxis axis = (DateAxis) plot.getRangeAxis();
    axis.setMinimumDate(actualStart.getTime());
    axis.setMaximumDate(actualEnd.getTime());
    axis.setTickUnit(tick);

    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.green);
    renderer.setSeriesPaint(2, Color.red);
}

From source file:desmoj.extensions.grafic.util.Plotter.java

/**
 * configure domainAxis (label, timeZone, locale, tick labels)
 * of time-series chart/*w w w. j av  a 2s. c  o m*/
 * @param dateAxis
 */
private void configureDomainAxis(DateAxis dateAxis) {
    if (this.begin != null)
        dateAxis.setMinimumDate(this.begin);
    if (this.end != null)
        dateAxis.setMaximumDate(this.end);
    dateAxis.setTimeZone(this.timeZone);

    Date dateMin = dateAxis.getMinimumDate();
    Date dateMax = dateAxis.getMaximumDate();
    //DateFormat formatter = new SimpleDateFormat("d.MM.yyyy HH:mm:ss.SSS");;
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM, locale);
    String label = "Time: " + formatter.format(dateMin) + " .. " + formatter.format(dateMax);
    formatter = new SimpleDateFormat("z");
    label += " " + formatter.format(dateMax);
    dateAxis.setLabel(label);

    TimeInstant max = new TimeInstant(dateMax);
    TimeInstant min = new TimeInstant(dateMin);
    TimeSpan diff = TimeOperations.diff(max, min);

    if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.DAYS)))
        formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
    else if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.HOURS)))
        formatter = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
    else if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.MINUTES)))
        formatter = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
    else
        formatter = new SimpleDateFormat("HH:mm:ss.SSS");
    dateAxis.setDateFormatOverride(formatter);
    dateAxis.setVerticalTickLabels(true);
}

From source file:grafix.graficos.ConstrutorGrafico.java

private void configurarEixoHorizontal(DateAxis domainAxis) {
    if (janela.getIntervaloExibicao().isEspacoPrevisao()) {
        Day ultimoDia = janela.getAcao().getData(janela.getAcao().getNumeroRegistros() - 1,
                Controle.getConfiguracoesUsuario().isExibeSomenteDiasUteis());
        Day ultimoDiaPrevisao = (Day) ultimoDia.next();
        for (int i = 0; i < Controle.getConfiguracoesGrafix().getEspacoPrevisao() - 1; i++) {
            ultimoDiaPrevisao = (Day) ultimoDiaPrevisao.next();
        }//w  w  w  .j  a  v  a  2  s.  c om
        domainAxis.setMaximumDate(ultimoDiaPrevisao.getSerialDate().toDate());
    }
}

From source file:org.xwiki.rendering.internal.macro.chart.source.AxisConfigurator.java

/**
 * Set the limits of a date axis.//from   w  w w .  java2 s .  com
 *
 * @param axis The axis.
 * @param index The index of the axis.
 * @throws MacroExecutionException if the parameters could not be parsed as dates.
 */
private void setDateLimits(DateAxis axis, int index) throws MacroExecutionException {
    try {
        if (axisLowerLimit[index] != null) {
            Date date = localeConfiguration.getDateFormat().parse(StringUtils.trim(axisLowerLimit[index]));
            axis.setMinimumDate(date);
        }
        if (axisUpperLimit[index] != null) {
            Date date = localeConfiguration.getDateFormat().parse(StringUtils.trim(axisUpperLimit[index]));
            axis.setMaximumDate(date);
        }
    } catch (ParseException e) {
        throw new MacroExecutionException("Invalid date in axis bound.", e);
    }
}

From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeTimeChartData.java

private TimeChartDataSet addTimeSeries(TimeChartDataSet dataset) throws InvalidArgument {
    if (dataset == null) {
        dataset = makeDataSet(1);/*from  w  ww. j a va 2s  .c  o  m*/
    }

    if (chart == null) {
        chart = ChartFactory.createTimeSeriesChart(title, "Time", quantity, dataset, true, false, false);
        XYPlot xyPlot = (XYPlot) chart.getPlot();

        DateAxis axis = (DateAxis) xyPlot.getDomainAxis();
        //axis.setRange(period.getStart(), period.getEnd());
        //axis.setLowerMargin(0.0);
        //axis.setUpperMargin(0.0);

        if (period instanceof CalendarFieldSplitPeriod) {
            TickUnits u = getUnits((CalendarFieldSplitPeriod) period);
            if (u != null) {
                axis.setStandardTickUnits(u);
            }
        }
        axis.setMinimumDate(period.getStart());
        axis.setMaximumDate(period.getEnd());
        LegendTitle leg = chart.getLegend();
        leg.setSortOrder(SortOrder.DESCENDING);
        leg.setPosition(RectangleEdge.RIGHT);
    } else {
        XYPlot xyPlot = (XYPlot) chart.getPlot();
        xyPlot.setDataset(ndatasets, dataset);
    }
    dataset.setDatasetId(ndatasets);
    ndatasets++;
    plots.add(dataset);
    return dataset;
}