DateAxis dateAxis = new DateAxis(timeAxisTitle); DateTickUnit unit = null; unit = new DateTickUnit(DateTickUnit.MINUTE,15); DateFormat chartFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm"); dateAxis.setDateFormatOverride(chartFormatter); dateAxis.setTickUnit(unit); NumberAxis valueAxis = new NumberAxis(valueAxisTitle);
/** * Sets the tick unit for the axis. The auto-tick-unit-selection flag is * set to {@code false}, and registered listeners are notified that * the axis has been changed. * * @param unit the tick unit. * * @see #getTickUnit() * @see #setTickUnit(DateTickUnit, boolean, boolean) */ public void setTickUnit(DateTickUnit unit) { setTickUnit(unit, true, true); }
/** * Sets the tick unit for the axis. The auto-tick-unit-selection flag is * set to <code>false</code>, and registered listeners are notified that * the axis has been changed. * * @param unit the tick unit. * * @see #getTickUnit() * @see #setTickUnit(DateTickUnit, boolean, boolean) */ public void setTickUnit(DateTickUnit unit) { setTickUnit(unit, true, true); }
DateAxis xAxis = (DateAxis) plot.getDomainAxis(); xAxis.setTickUnit(new DateTickUnit( DateTickUnit.DAY, 1, new SimpleDateFormat("EEE", Locale.DE)));
axis.setTickUnit(new DateTickUnit(unit, count));
private static JFreeChart createChart() { CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Date/Time")); plot.setDomainPannable(true); plot.add(createSubplot1(createDataset1())); plot.add(createSubplot2(createDataset2())); // Get the horizontal Axis for the plot DateAxis axis = (DateAxis) plot.getDomainAxis(); // Change the unit tick to 5 hours axis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 5)); // Change the date format used to display tick values axis.setDateFormatOverride(new SimpleDateFormat("hh:mm")); JFreeChart chart = new JFreeChart("XYTaskDatasetDemo2", plot); chart.setBackgroundPaint(Color.white); ChartUtilities.applyCurrentTheme(chart); return chart; }
/** * Creates a date axis. A timeline is specified for the axis. This allows * special transformations to occur between a domain of values and the * values included in the axis. * * @see org.jfree.chart.axis.SegmentedTimeline * * @param label the axis label (<code>null</code> permitted). * @param zone the time zone. * @param locale the locale (<code>null</code> not permitted). * * @since 1.0.11 */ public DateAxis(String label, TimeZone zone, Locale locale) { super(label, DateAxis.createStandardDateTickUnits(zone, locale)); setTickUnit(DateAxis.DEFAULT_DATE_TICK_UNIT, false, false); setAutoRangeMinimumSize( DEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDS); setRange(DEFAULT_DATE_RANGE, false, false); this.dateFormatOverride = null; this.timeZone = zone; this.locale = locale; this.timeline = DEFAULT_TIMELINE; }
domainAxis.setAutoRange(true); domainAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); domainAxis.setTickUnit(new DateTickUnit(DateTickUnitType.SECOND, 1));
/** * Selects an appropriate tick size for the axis. The strategy is to * display as many ticks as possible (selected from a collection of * 'standard' tick units) without the labels overlapping. * * @param g2 the graphics device. * @param dataArea the area defined by the axes. * @param edge the axis location. */ protected void selectHorizontalAutoTickUnit(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { double zero = valueToJava2D(0.0, dataArea, edge); double tickLabelWidth = estimateMaximumTickLabelWidth(g2, getTickUnit()); // start with the current tick unit... TickUnitSource tickUnits = getStandardTickUnits(); TickUnit unit1 = tickUnits.getCeilingTickUnit(getTickUnit()); double x1 = valueToJava2D(unit1.getSize(), dataArea, edge); double unit1Width = Math.abs(x1 - zero); // then extrapolate... double guess = (tickLabelWidth / unit1Width) * unit1.getSize(); DateTickUnit unit2 = (DateTickUnit) tickUnits.getCeilingTickUnit(guess); double x2 = valueToJava2D(unit2.getSize(), dataArea, edge); double unit2Width = Math.abs(x2 - zero); tickLabelWidth = estimateMaximumTickLabelWidth(g2, unit2); if (tickLabelWidth > unit2Width) { unit2 = (DateTickUnit) tickUnits.getLargerTickUnit(unit2); } setTickUnit(unit2, false, false); }
unit2 = (DateTickUnit) tickUnits.getLargerTickUnit(unit2); setTickUnit(unit2, false, false);
finalUnit = (DateTickUnit) tickUnits.getLargerTickUnit(candidate2); setTickUnit(finalUnit, false, false);
finalUnit = (DateTickUnit) tickUnits.getLargerTickUnit(candidate2); setTickUnit(finalUnit, false, false);
axis.setDateFormatOverride(new SimpleDateFormat(dateFormatAxis)); if (dateTickUnit != null) { axis.setTickUnit(dateTickUnit);
domainAxis.setTickUnit (new DateTickUnit (DateTickUnit.DAY, 7, new SimpleDateFormat ("yyyy-MM-dd"))); domainAxis.setTickMarkPosition (DateTickMarkPosition.START); domainAxis.setVerticalTickLabels (true);
domainAxis.setTickUnit (new DateTickUnit (DateTickUnit.DAY, 7, new SimpleDateFormat ("yyyy-MM-dd"))); domainAxis.setTickMarkPosition (DateTickMarkPosition.START); domainAxis.setVerticalTickLabels (true);
dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MINUTE, 1)); dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
domainAxis.setTickUnit (new DateTickUnit (DateTickUnit.MONTH, 1, new SimpleDateFormat ("yyyy-MM"))); domainAxis.setTickMarkPosition (DateTickMarkPosition.START); domainAxis.setVerticalTickLabels (true);
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(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)); } }