List of usage examples for org.jfree.chart.axis DateTickUnit DateTickUnit
public DateTickUnit(int unit, int count)
From source file:org.operamasks.faces.render.graph.ChartRenderer.java
private void setDateAxisStyles(DateAxis axis, UIAxis comp) { UIDataSeries data = ((UIChart) comp.getParent()).getDataSeries(); if (!(data instanceof UITimeSeries)) return;/*from w w w.j a va 2s.co m*/ UITimeSeries ts = (UITimeSeries) data; axis.setInverted(comp.isInverted()); Object lowerBound = comp.getLowerBound(); Object upperBound = comp.getUpperBound(); Double lowerMargin = comp.getLowerMargin(); Double upperMargin = comp.getUpperMargin(); if (lowerBound != null) axis.setLowerBound(getTimePeriodValue(ts, lowerBound)); if (upperBound != null) axis.setUpperBound(getTimePeriodValue(ts, upperBound)); if (lowerMargin != null) axis.setLowerMargin(lowerMargin); if (upperMargin != null) axis.setUpperMargin(upperMargin); Double tickStep = comp.getTickStep(); String tickFormat = comp.getTickLabelFormat(); int dateTickUnit = 0; int dateTickStep = 0; if (tickStep != null) { dateTickStep = tickStep.intValue(); TimePeriodType tp = comp.getTickUnit(); if (tp == null) { tp = ts.getTimePeriod(); } switch (tp) { case Year: dateTickUnit = DateTickUnit.YEAR; break; case Quarter: dateTickUnit = DateTickUnit.MONTH; dateTickStep *= 4; break; case Month: dateTickUnit = DateTickUnit.MONTH; break; case Week: dateTickUnit = DateTickUnit.DAY; dateTickStep *= 7; break; case Day: dateTickUnit = DateTickUnit.DAY; break; case Hour: dateTickUnit = DateTickUnit.HOUR; break; case Minute: dateTickUnit = DateTickUnit.MINUTE; break; case Second: dateTickUnit = DateTickUnit.SECOND; break; case Millisecond: dateTickUnit = DateTickUnit.MILLISECOND; break; default: throw new AssertionError(); } } if ((tickStep != null && tickStep > 0) || tickFormat != null) { if (tickFormat == null) { axis.setTickUnit(new DateTickUnit(dateTickUnit, dateTickStep)); } else if (tickStep == null) { DateFormat format = new SimpleDateFormat(tickFormat); axis.setDateFormatOverride(format); } else { DateFormat format = new SimpleDateFormat(tickFormat); axis.setTickUnit(new DateTickUnit(dateTickUnit, dateTickStep, format)); } } }
From source file:org.jfree.chart.demo.XYBoxAnnotationDemo1.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Breakdowns", "Production Date", "Hours of Operation", xydataset, true, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylineandshaperenderer.setSeriesShape(0, new Rectangle(2, 2)); xylineandshaperenderer.setSeriesShape(1, new Rectangle(2, 2)); xylineandshaperenderer.setBaseLinesVisible(false); xylineandshaperenderer.setBaseShapesFilled(true); xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseToolTipGenerator(null); xylineandshaperenderer.setSeriesPaint(0, Color.blue); xylineandshaperenderer.setSeriesPaint(1, Color.red); xyplot.setDomainGridlineStroke(new BasicStroke(1.0F)); xyplot.setRangeGridlineStroke(new BasicStroke(1.0F)); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setTickUnit(new NumberTickUnit(50000D)); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1)); dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM.yy")); dateaxis.setVerticalTickLabels(true); Color color = new Color(255, 0, 0, 60); Color color1 = new Color(0, 255, 0, 60); XYBoxAnnotation xyboxannotation = new XYBoxAnnotation((new Day(1, 1, 2004)).getMiddleMillisecond(), 0.0D, (new Day(31, 1, 2004)).getMiddleMillisecond(), 50000D, new BasicStroke(0.0F), color, color); xyboxannotation.setToolTipText("Value: 2.9"); xylineandshaperenderer.addAnnotation(xyboxannotation); xyboxannotation = new XYBoxAnnotation((new Day(1, 2, 2004)).getMiddleMillisecond(), 0.0D, (new Day(29, 2, 2004)).getMiddleMillisecond(), 50000D, new BasicStroke(0.0F), color, color); xyboxannotation.setToolTipText("Value: 2.5"); xylineandshaperenderer.addAnnotation(xyboxannotation); xyboxannotation = new XYBoxAnnotation((new Day(1, 5, 2004)).getMiddleMillisecond(), 50000D, (new Day(31, 5, 2004)).getMiddleMillisecond(), 100000D, new BasicStroke(0.0F), color, color); xyboxannotation.setToolTipText("Value: 1.8"); xylineandshaperenderer.addAnnotation(xyboxannotation); xyboxannotation = new XYBoxAnnotation((new Day(1, 6, 2005)).getMiddleMillisecond(), 0.0D, (new Day(30, 6, 2005)).getMiddleMillisecond(), 50000D, new BasicStroke(0.0F), color1, color1); xyboxannotation.setToolTipText("Value: 3.7"); xylineandshaperenderer.addAnnotation(xyboxannotation); return jfreechart; }