List of usage examples for org.jfree.chart.axis DateTickUnitType HOUR
DateTickUnitType HOUR
To view the source code for org.jfree.chart.axis DateTickUnitType HOUR.
Click Source Link
From source file:org.jfree.chart.demo.TimePeriodValuesDemo1.java
public TimePeriodValuesDemo1(String s) { super(s);/*from w w w .jav a 2 s . c o 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: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);//from w w w . ja v a2 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. ja 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:com.bdb.weather.display.day.DayXYPlotPane.java
private void createChartElements() { ///*from www . j a va 2s. c o m*/ // Set up the Domain Axis (X) // plot = new XYPlot(); dateAxis = new DateAxis("Time"); dateAxis.setAutoRange(false); dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1, new SimpleDateFormat("h a"))); dateAxis.setVerticalTickLabels(true); plot.setDomainAxis(dateAxis); plot.setRangeAxis(leftAxis); plot.setDataset(0, datasetLeft); if (rightAxis != null) { plot.setRangeAxis(1, rightAxis); plot.mapDatasetToRangeAxis(1, 1); plot.setDataset(1, datasetRight); } plot.setNoDataMessage("There is no data for the specified day"); // // Set up the renderer to generate tool tips, not show shapes // XYLineAndShapeRenderer renderer = new XYLine3DRenderer(); renderer.setBaseShapesVisible(false); renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); //renderer.setDefaultEntityRadius(1); plot.setRenderer(0, renderer); renderer = new XYLine3DRenderer(); renderer.setBaseShapesVisible(false); renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); //renderer.setDefaultEntityRadius(1); plot.setRenderer(1, renderer); // // Setup the cross hairs that are displayed when the user clicks on the plot // plot.setRangeCrosshairLockedOnData(true); plot.setRangeCrosshairVisible(true); plot.setDomainCrosshairLockedOnData(true); plot.setDomainCrosshairVisible(true); // // Create the chart that contains the plot and the panel that contains the chart // chart = new JFreeChart(plot); ChartFactory.getChartTheme().apply(chart); chartViewer = new ChartViewer(chart); chartViewer.setMaxHeight(500); chartViewer.setMaxWidth(800); // // Add the Day/Night indicator option to the chart panels context menu // ContextMenu menu = chartViewer.getContextMenu(); displayMenu = new Menu("Display"); dayNightItem = new CheckMenuItem("Day/Night Indicators"); dayNightItem.setSelected(true); displayMenu.getItems().add(dayNightItem); dayNightItem.setOnAction(this); menu.getItems().add(displayMenu); }
From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeTimeChartData.java
private TickUnits getUnits(CalendarFieldSplitPeriod period) { int field = period.getField(); boolean good_match = false; for (DateTickUnitType unit : new DateTickUnitType[] { DateTickUnitType.SECOND, DateTickUnitType.MINUTE, DateTickUnitType.HOUR, DateTickUnitType.DAY, DateTickUnitType.MONTH, DateTickUnitType.YEAR }) { if (field == unit.getCalendarField()) { TickUnits units = new TickUnits(); int count = period.getCount(); int nsplit = period.getNsplit(); if (count == 1 && nsplit == 1) { return null; // let jfree work it out. }/*from w w w.j ava 2 s. c o m*/ if (nsplit > 50) { return null; // period unit is too small } // include all multiples that are exact factors of count for (int i = 1; i <= count; i++) { if (count % i == 0) { units.add(new DateTickUnit(unit, i)); if (i > 1 && (count / i) < 8) { good_match = true; } } } // now larger multiples of count that factor nsplit for (int i = 2; i < nsplit && i < 50; i++) { if (nsplit % i == 0) { units.add(new DateTickUnit(unit, i * count)); if (i > 1 && (nsplit / i) < 8) { good_match = true; } } } if (good_match) { return units; } return null; } } return null; }
From source file:MWC.GUI.JFreeChart.DateAxisEditor.java
public static TickUnits createStandardDateTickUnitsAsTickUnits() { final TickUnits units = new TickUnits(); // milliseconds units.add(new OptimisedDateTickUnit(DateTickUnitType.MILLISECOND, 500, new RNFormatter("HH:mm:ss.SSS"))); // seconds/*from w ww .j ava2 s . c o m*/ units.add(new OptimisedDateTickUnit(DateTickUnitType.SECOND, 1, new RNFormatter("HH:mm:ss"))); units.add(new OptimisedDateTickUnit(DateTickUnitType.SECOND, 5, new RNFormatter("HH:mm:ss"))); units.add(new OptimisedDateTickUnit(DateTickUnitType.SECOND, 10, new RNFormatter("HH:mm:ss"))); units.add(new OptimisedDateTickUnit(DateTickUnitType.SECOND, 30, new RNFormatter("HH:mm:ss"))); // minutes units.add(new OptimisedDateTickUnit(DateTickUnitType.MINUTE, 1, new RNFormatter("HH:mm"))); units.add(new OptimisedDateTickUnit(DateTickUnitType.MINUTE, 2, new RNFormatter("HH:mm"))); units.add(new OptimisedDateTickUnit(DateTickUnitType.MINUTE, 5, new RNFormatter("HH:mm"))); units.add(new OptimisedDateTickUnit(DateTickUnitType.MINUTE, 10, new RNFormatter("HH:mm"))); units.add(new OptimisedDateTickUnit(DateTickUnitType.MINUTE, 15, new RNFormatter("HH:mm"))); units.add(new OptimisedDateTickUnit(DateTickUnitType.MINUTE, 20, new RNFormatter("HH:mm"))); units.add(new OptimisedDateTickUnit(DateTickUnitType.MINUTE, 30, new RNFormatter("HH:mm"))); // hours units.add(new OptimisedDateTickUnit(DateTickUnitType.HOUR, 1, new RNFormatter("HH:mm"))); units.add(new OptimisedDateTickUnit(DateTickUnitType.HOUR, 2, new RNFormatter("HH:mm"))); units.add(new OptimisedDateTickUnit(DateTickUnitType.HOUR, 4, new RNFormatter("HH:mm"))); units.add(new OptimisedDateTickUnit(DateTickUnitType.HOUR, 6, new RNFormatter("ddHHmm"))); units.add(new OptimisedDateTickUnit(DateTickUnitType.HOUR, 12, new RNFormatter("ddHHmm"))); // days units.add(new OptimisedDateTickUnit(DateTickUnitType.DAY, 1, new RNFormatter("d-MMM"))); return units; }
From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeTimeChartData.java
private TickUnits getUnits() { TickUnits units = new TickUnits(); units.add(new DateTickUnit(DateTickUnitType.SECOND, 1)); units.add(new DateTickUnit(DateTickUnitType.MINUTE, 1)); units.add(new DateTickUnit(DateTickUnitType.MINUTE, 10)); units.add(new DateTickUnit(DateTickUnitType.MINUTE, 15)); units.add(new DateTickUnit(DateTickUnitType.HOUR, 1)); units.add(new DateTickUnit(DateTickUnitType.HOUR, 12)); units.add(new DateTickUnit(DateTickUnitType.DAY, 1)); units.add(new DateTickUnit(DateTickUnitType.DAY, 7)); units.add(new DateTickUnit(DateTickUnitType.MONTH, 1)); units.add(new DateTickUnit(DateTickUnitType.MONTH, 3)); units.add(new DateTickUnit(DateTickUnitType.MONTH, 6)); units.add(new DateTickUnit(DateTickUnitType.YEAR, 1)); units.add(new DateTickUnit(DateTickUnitType.YEAR, 10)); return units; }
From source file:MWC.GUI.JFreeChart.DateAxisEditor.java
/** * Returns a collection of standard date tick units. This collection will be * used by default, but you are free to create your own collection if you want * to (see the setStandardTickUnits(...) method inherited from the ValueAxis * class)./* ww w .j a va2 s .c o m*/ * * @return a collection of standard date tick units. */ public static ArrayList<MWCDateTickUnitWrapper> createStandardDateTickUnitsAsArrayList() { final ArrayList<MWCDateTickUnitWrapper> units = new ArrayList<MWCDateTickUnitWrapper>(); units.add(MWCDateTickUnitWrapper.getAutoScale()); // ////////////////////////////////////////////////////// // milliseconds units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MILLISECOND, 500, "HH:mm:ss.SSS")); // seconds units.add(new MWCDateTickUnitWrapper(DateTickUnitType.SECOND, 1, "HH:mm:ss")); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.SECOND, 5, "HH:mm:ss")); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.SECOND, 10, "HH:mm:ss")); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.SECOND, 30, "HH:mm:ss")); // minutes units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 1, "HH:mm")); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 2, "HH:mm")); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 5, "HH:mm")); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 10, "HH:mm")); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 15, "HH:mm")); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 20, "HH:mm")); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 30, "HH:mm")); // hours units.add(new MWCDateTickUnitWrapper(DateTickUnitType.HOUR, 1, "HH:mm")); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.HOUR, 2, "HH:mm")); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.HOUR, 4, "HH:mm")); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.HOUR, 6, "ddHHmm")); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.HOUR, 12, "ddHHmm")); // days units.add(new MWCDateTickUnitWrapper(DateTickUnitType.DAY, 1, "d-MMM")); // ///////////////////////////////////////////////////// // // milliseconds // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MILLISECOND, // 500, "HH:mm:ss.SSS")); // // // seconds // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.SECOND, 1, // "HH:mm:ss")); // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.SECOND, 5, // "HH:mm:ss")); // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.SECOND, 10, // "HH:mm:ss")); // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.SECOND, 30, // "HH:mm:ss")); // // // minutes // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 1, // "HH:mm")); // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 2, // "HH:mm")); // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 5, // "HH:mm")); // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 10, // "HH:mm")); // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 15, // "HH:mm")); // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 20, // "HH:mm")); // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.MINUTE, 30, // "HH:mm")); // // // hours // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.HOUR, 1, // "HH:mm")); // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.HOUR, 2, // "HH:mm")); // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.HOUR, 4, // "HH:mm")); // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.HOUR, 6, // "HH:mm")); // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.HOUR, 12, // "d-MMM, HH:mm")); // // // days // units.add(new MWCDateTickUnitWrapper(DateTickUnitType.DAY, 1, // "d-MMM")); // absolute seconds units.add(new MWCDateTickUnitWrapper(DateTickUnitType.SECOND, 1, RELATIVE_DTG_FORMAT)); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.SECOND, 5, RELATIVE_DTG_FORMAT)); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.SECOND, 10, RELATIVE_DTG_FORMAT)); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.SECOND, 30, RELATIVE_DTG_FORMAT)); units.add(new MWCDateTickUnitWrapper(DateTickUnitType.SECOND, 60, RELATIVE_DTG_FORMAT)); return units; }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java
/** * Creates a chart of the actual view with a title. * @param title/*from ww w . jav a 2s.co 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:OAT.ui.util.UiUtil.java
public static TickUnits createSimpleTimeTickUnits() { TickUnits tickUnits = new TickUnits(); SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm"); SimpleDateFormat weekDayFormatter = new SimpleDateFormat("EEE"); SimpleDateFormat dayFormatter = new SimpleDateFormat("dd-mm"); SimpleDateFormat monthFormatter = new SimpleDateFormat("MMM-yy"); SimpleDateFormat yearFormatter = new SimpleDateFormat("yyyy"); //tickUnits.add(new DateTickUnit(DateTickUnitType.MINUTE, 30, DateTickUnitType.SECOND, 1, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 1, DateTickUnitType.SECOND, 1, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 2, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 4, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 6, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 12, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 1, DateTickUnitType.HOUR, 1, weekDayFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 2, weekDayFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 7, dayFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 15, dayFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 1, DateTickUnitType.DAY, 1, monthFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 3, monthFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 6, monthFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 1, DateTickUnitType.MONTH, 1, yearFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 2, yearFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 5, yearFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 10, yearFormatter)); return tickUnits; }