List of usage examples for org.jfree.chart.axis DateAxis setInverted
public void setInverted(boolean flag)
From source file:org.jfree.chart.demo.XYBlockChartDemo2.java
private static JFreeChart createChart(XYZDataset xyzdataset) { DateAxis dateaxis = new DateAxis("Date"); dateaxis.setLowerMargin(0.0D);/*from ww w .j a va2s.c om*/ dateaxis.setUpperMargin(0.0D); dateaxis.setInverted(true); NumberAxis numberaxis = new NumberAxis("Hour"); numberaxis.setUpperMargin(0.0D); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYBlockRenderer xyblockrenderer = new XYBlockRenderer(); xyblockrenderer.setBlockWidth(86400000D); xyblockrenderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT); LookupPaintScale lookuppaintscale = new LookupPaintScale(0.5D, 4.5D, Color.white); lookuppaintscale.add(0.5D, Color.red); lookuppaintscale.add(1.5D, Color.green); lookuppaintscale.add(2.5D, Color.blue); lookuppaintscale.add(3.5D, Color.yellow); xyblockrenderer.setPaintScale(lookuppaintscale); XYPlot xyplot = new XYPlot(xyzdataset, dateaxis, numberaxis, xyblockrenderer); xyplot.setOrientation(PlotOrientation.HORIZONTAL); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo2", xyplot); jfreechart.removeLegend(); jfreechart.setBackgroundPaint(Color.white); SymbolAxis symbolaxis = new SymbolAxis(null, new String[] { "", "Unavailable", "Free", "Group 1", "Group 2" }); symbolaxis.setRange(0.5D, 4.5D); symbolaxis.setPlot(new PiePlot()); symbolaxis.setGridBandsVisible(false); PaintScaleLegend paintscalelegend = new PaintScaleLegend(lookuppaintscale, symbolaxis); paintscalelegend.setMargin(new RectangleInsets(3D, 10D, 3D, 10D)); paintscalelegend.setPosition(RectangleEdge.BOTTOM); paintscalelegend.setAxisOffset(5D); jfreechart.addSubtitle(paintscalelegend); return jfreechart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.blockcharts.TimeBlockChart.java
@Override public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); super.createChart(datasets); DefaultXYZDataset dataset = (DefaultXYZDataset) datasets.getDatasets().get("1"); DateAxis xAxis = new DateAxis(yLabel); xAxis.setLowerMargin(0.0);//from w w w . ja va 2 s . c o m xAxis.setUpperMargin(0.0); xAxis.setInverted(false); xAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy")); if (dateAutoRange) { xAxis.setAutoRange(true); } else { DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 1, formatter); xAxis.setTickUnit(unit); } if (dateMin != null && dateMax != null) { xAxis.setRange(dateMin, addDay(dateMax)); } else { xAxis.setRange(minDateFound, addDay(maxDateFound)); } // Calendar c=new GregorianCalendar(); // c.set(9 + 2000, Calendar.JANUARY, 1); // java.util.Date minima=c.getTime(); // Calendar c1=new GregorianCalendar(); // c1.set(9 + 2000, Calendar.FEBRUARY, 1); // java.util.Date massima=c1.getTime(); NumberAxis yAxis = new NumberAxis(xLabel); yAxis.setUpperMargin(0.0); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setRange(hourMin, hourMax); XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setBlockWidth(BLOCK_HEIGHT); // one block for each minute! renderer.setBlockHeight(0.017); //renderer.setBlockWidth(1); renderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT); // MyXYItemLabelGenerator my=new MyXYItemLabelGenerator(); // renderer.setItemLabelsVisible(null); // renderer.setSeriesItemLabelGenerator(0, my); // renderer.setSeriesItemLabelsVisible(0, true); // XYTextAnnotation annotation1 = new XYTextAnnotation( // "P_",1.2309372E12, 14.3); // XYTextAnnotation annotation2 = new XYTextAnnotation( // "P_",1.2308508E12, 16.3); for (Iterator iterator = annotations.keySet().iterator(); iterator.hasNext();) { String annotationCode = (String) iterator.next(); AnnotationBlock annotationBlock = annotations.get(annotationCode); XYTextAnnotation xyAnnotation = new XYTextAnnotation(annotationBlock.getAnnotation(), annotationBlock.getXPosition() + ANNOTATION_HEIGHT, annotationBlock.getYPosition()); if (styleAnnotation != null) { xyAnnotation.setFont(new Font(styleAnnotation.getFontName(), Font.BOLD, styleAnnotation.getSize())); xyAnnotation.setPaint(styleAnnotation.getColor()); } else { xyAnnotation.setFont(new Font("Nome", Font.BOLD, 8)); xyAnnotation.setPaint(Color.BLACK); } xyAnnotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); renderer.addAnnotation(xyAnnotation); } logger.debug("Annotation set"); LookupPaintScale paintScale = new LookupPaintScale(0.5, ranges.size() + 0.5, color); String[] labels = new String[ranges.size() + 1]; labels[0] = ""; // ******************** SCALE **************************** for (Iterator iterator = ranges.iterator(); iterator.hasNext();) { RangeBlocks range = (RangeBlocks) iterator.next(); Integer index = patternRangeIndex.get(range.getPattern()); Color color = range.getColor(); if (color != null) { //Paint colorTransparent=new Color(color.getRed(), color.getGreen(), color.getBlue(), 50); Paint colorTransparent = null; if (addTransparency == true) { colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue(), 50); } else { colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue()); } paintScale.add(index + 0.5, colorTransparent); } //String insertLabel=" "+range.getLabel(); String insertLabel = range.getLabel(); labels[index + 1] = insertLabel; } renderer.setPaintScale(paintScale); SymbolAxis scaleAxis = new SymbolAxis(null, labels); scaleAxis.setRange(0.5, ranges.size() + 0.5); scaleAxis.setPlot(new PiePlot()); scaleAxis.setGridBandsVisible(false); org.jfree.chart.title.PaintScaleLegend psl = new PaintScaleLegend(paintScale, scaleAxis); psl.setMargin(new RectangleInsets(3, 10, 3, 10)); psl.setPosition(RectangleEdge.BOTTOM); psl.setAxisOffset(5.0); // ******************** END SCALE **************************** logger.debug("Scale Painted"); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.HORIZONTAL); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); logger.debug("Plot set"); JFreeChart chart = new JFreeChart(name, plot); if (styleTitle != null) { TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); } chart.removeLegend(); chart.setBackgroundPaint(Color.white); chart.addSubtitle(psl); logger.debug("OUT"); return chart; }
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 ww. ja v a 2s .c o 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)); } } }