List of usage examples for org.jfree.chart.axis DateTickUnit DAY
int DAY
To view the source code for org.jfree.chart.axis DateTickUnit DAY.
Click Source Link
From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java
private TickUnits createTickUnits(Locale locale, TimeZone zone) { TickUnits units = new TickUnits(); // date formatters DateFormat f1 = new SimpleDateFormat("HH:mm:ss.SSS", locale); DateFormat f2 = new SimpleDateFormat("HH:mm:ss", locale); DateFormat f3 = DateFormat.getTimeInstance(DateFormat.SHORT, locale); DateFormat f4 = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); DateFormat f5 = new SimpleDateFormat("d-MMM", locale); DateFormat f6 = new SimpleDateFormat("MMM-yyyy", locale); DateFormat f7 = new SimpleDateFormat("yyyy", locale); // NOTE: timezone not needed on date formatters because dates have already been converted // to the appropriate timezone by the respective RegularTimePeriod (Minute, Hour, Day, etc) // see:// w ww.j a v a 2s . c om // http://www.jfree.org/jfreechart/api/gjdoc/org/jfree/data/time/Hour.html#Hour:Date:TimeZone // // If you do use a timezone on the formatters and the Jive TimeZone has been set to something // other than the system timezone, time specific charts will show incorrect values. /* f1.setTimeZone(zone); f2.setTimeZone(zone); f3.setTimeZone(zone); f4.setTimeZone(zone); f5.setTimeZone(zone); f6.setTimeZone(zone); f7.setTimeZone(zone); */ // milliseconds units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 1, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 5, DateTickUnit.MILLISECOND, 1, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 10, DateTickUnit.MILLISECOND, 1, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 25, DateTickUnit.MILLISECOND, 5, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 50, DateTickUnit.MILLISECOND, 10, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 100, DateTickUnit.MILLISECOND, 10, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 250, DateTickUnit.MILLISECOND, 10, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 500, DateTickUnit.MILLISECOND, 50, f1)); // seconds units.add(new DateTickUnit(DateTickUnit.SECOND, 1, DateTickUnit.MILLISECOND, 50, f2)); units.add(new DateTickUnit(DateTickUnit.SECOND, 5, DateTickUnit.SECOND, 1, f2)); units.add(new DateTickUnit(DateTickUnit.SECOND, 10, DateTickUnit.SECOND, 1, f2)); units.add(new DateTickUnit(DateTickUnit.SECOND, 30, DateTickUnit.SECOND, 5, f2)); // minutes units.add(new DateTickUnit(DateTickUnit.MINUTE, 1, DateTickUnit.SECOND, 5, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 2, DateTickUnit.SECOND, 10, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 5, DateTickUnit.MINUTE, 1, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 10, DateTickUnit.MINUTE, 1, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 15, DateTickUnit.MINUTE, 5, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 20, DateTickUnit.MINUTE, 5, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 30, DateTickUnit.MINUTE, 5, f3)); // hours units.add(new DateTickUnit(DateTickUnit.HOUR, 1, DateTickUnit.MINUTE, 5, f3)); units.add(new DateTickUnit(DateTickUnit.HOUR, 2, DateTickUnit.MINUTE, 10, f3)); units.add(new DateTickUnit(DateTickUnit.HOUR, 4, DateTickUnit.MINUTE, 30, f3)); units.add(new DateTickUnit(DateTickUnit.HOUR, 6, DateTickUnit.HOUR, 1, f3)); units.add(new DateTickUnit(DateTickUnit.HOUR, 12, DateTickUnit.HOUR, 1, f4)); // days units.add(new DateTickUnit(DateTickUnit.DAY, 1, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 2, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 7, DateTickUnit.DAY, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 15, DateTickUnit.DAY, 1, f5)); // months units.add(new DateTickUnit(DateTickUnit.MONTH, 1, DateTickUnit.DAY, 1, f6)); units.add(new DateTickUnit(DateTickUnit.MONTH, 2, DateTickUnit.DAY, 1, f6)); units.add(new DateTickUnit(DateTickUnit.MONTH, 3, DateTickUnit.MONTH, 1, f6)); units.add(new DateTickUnit(DateTickUnit.MONTH, 4, DateTickUnit.MONTH, 1, f6)); units.add(new DateTickUnit(DateTickUnit.MONTH, 6, DateTickUnit.MONTH, 1, f6)); // years units.add(new DateTickUnit(DateTickUnit.YEAR, 1, DateTickUnit.MONTH, 1, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 2, DateTickUnit.MONTH, 3, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 5, DateTickUnit.YEAR, 1, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 10, DateTickUnit.YEAR, 1, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 25, DateTickUnit.YEAR, 5, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 50, DateTickUnit.YEAR, 10, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 100, DateTickUnit.YEAR, 20, f7)); return units; }
From source file:figs.treeVisualization.gui.TimeAxisTree2DPanel.java
/** * Set up the PhyloDataAxis for our dates. * <P>/* www.java 2 s. co m*/ * If the leaf nodes change then <code>fetchLeafNodes</code> needs to be called before * this. * * TODO: UI fixes for rounding up and down the date so that they fall on the next unit */ private void calculateDateAxis() { // TODO: senstive to changes in the document if (fTopLeafDate == null || fBottomLeafDate == null) return; // TODO: throw exception // calculate our tickUnit and dateFormatOverride Date upperDate = this.fLeafDates.get(this.fTopLeafDate).getTime(); Date lowerDate = this.fLeafDates.get(this.fBottomLeafDate).getTime(); long dateDiff = upperDate.getTime() - lowerDate.getTime(); DateTickUnit dtu; SimpleDateFormat sdf; if (dateDiff > ONE_MS_YEAR * 2) { // TODO adjust tickUnitCount for very big year distances dtu = new DateTickUnit(DateTickUnit.YEAR, this.fTickUnitCount); sdf = new SimpleDateFormat("yyyy"); } else if (dateDiff <= ONE_MS_YEAR * 2 || dateDiff > ONE_MS_MONTH) { if (dateDiff > ONE_MS_YEAR) { dtu = new DateTickUnit(DateTickUnit.MONTH, this.fTickUnitCount * 2); } else { dtu = new DateTickUnit(DateTickUnit.MONTH, this.fTickUnitCount); } sdf = new SimpleDateFormat("MM/yyyy"); } else { dtu = new DateTickUnit(DateTickUnit.DAY, this.fTickUnitCount); sdf = new SimpleDateFormat("MM/dd/yyyy"); } fDateAxis.setTickUnit(dtu); fDateAxis.setDateFormatOverride(sdf); // TODO: tickMarkPosition fDateAxis.setTickMarkPosition(DateTickMarkPosition.START); // set the range fDateAxis.setRange(lowerDate, upperDate); }
From source file:org.kalypso.ogc.sensor.diagview.jfreechart.ObservationPlot.java
/** * Special tick units for kalypso/* ww w. j a va 2s . c o m*/ */ public static TickUnitSource createStandardDateTickUnits(final TimeZone zone) { if (zone == null) { throw new IllegalArgumentException("Null 'zone' argument."); //$NON-NLS-1$ } final TickUnits units = new TickUnits(); // date formatters // DateFormat f1 = new SimpleDateFormat("HH:mm:ss.SSS"); // DateFormat f2 = new SimpleDateFormat("HH:mm:ss"); // DateFormat f3 = new SimpleDateFormat("HH:mm"); // DateFormat f4 = new SimpleDateFormat("d-MMM, HH:mm"); // DateFormat f5 = new SimpleDateFormat("d-MMM"); // DateFormat f6 = new SimpleDateFormat("MMM-yyyy"); // DateFormat f7 = new SimpleDateFormat("yyyy"); final DateFormat f1 = new SimpleDateFormat("dd.MM HH:mm:ss.SSS"); //$NON-NLS-1$ final DateFormat f2 = new SimpleDateFormat("dd.MM HH:mm:ss"); //$NON-NLS-1$ final DateFormat f3 = new SimpleDateFormat("dd.MM HH:mm"); //$NON-NLS-1$ final DateFormat f4 = new SimpleDateFormat("dd.MM HH:mm"); //$NON-NLS-1$ final DateFormat f5 = new SimpleDateFormat("dd.MM"); //$NON-NLS-1$ final DateFormat f6 = new SimpleDateFormat("dd.MM.yy"); //$NON-NLS-1$ final DateFormat f7 = new SimpleDateFormat("yyyy"); //$NON-NLS-1$ f1.setTimeZone(zone); f2.setTimeZone(zone); f3.setTimeZone(zone); f4.setTimeZone(zone); f5.setTimeZone(zone); f6.setTimeZone(zone); f7.setTimeZone(zone); // milliseconds units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 1, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 5, DateTickUnit.MILLISECOND, 1, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 10, DateTickUnit.MILLISECOND, 1, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 25, DateTickUnit.MILLISECOND, 5, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 50, DateTickUnit.MILLISECOND, 10, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 100, DateTickUnit.MILLISECOND, 10, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 250, DateTickUnit.MILLISECOND, 10, f1)); units.add(new DateTickUnit(DateTickUnit.MILLISECOND, 500, DateTickUnit.MILLISECOND, 50, f1)); // seconds units.add(new DateTickUnit(DateTickUnit.SECOND, 1, DateTickUnit.MILLISECOND, 50, f2)); units.add(new DateTickUnit(DateTickUnit.SECOND, 5, DateTickUnit.SECOND, 1, f2)); units.add(new DateTickUnit(DateTickUnit.SECOND, 10, DateTickUnit.SECOND, 1, f2)); units.add(new DateTickUnit(DateTickUnit.SECOND, 30, DateTickUnit.SECOND, 5, f2)); // minutes units.add(new DateTickUnit(DateTickUnit.MINUTE, 1, DateTickUnit.SECOND, 5, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 2, DateTickUnit.SECOND, 10, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 5, DateTickUnit.MINUTE, 1, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 10, DateTickUnit.MINUTE, 1, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 15, DateTickUnit.MINUTE, 5, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 20, DateTickUnit.MINUTE, 5, f3)); units.add(new DateTickUnit(DateTickUnit.MINUTE, 30, DateTickUnit.MINUTE, 5, f3)); // hours units.add(new DateTickUnit(DateTickUnit.HOUR, 1, DateTickUnit.MINUTE, 5, f3)); units.add(new DateTickUnit(DateTickUnit.HOUR, 2, DateTickUnit.MINUTE, 10, f3)); units.add(new DateTickUnit(DateTickUnit.HOUR, 4, DateTickUnit.MINUTE, 30, f3)); units.add(new DateTickUnit(DateTickUnit.HOUR, 6, DateTickUnit.HOUR, 1, f3)); units.add(new DateTickUnit(DateTickUnit.HOUR, 12, DateTickUnit.HOUR, 1, f4)); // days units.add(new DateTickUnit(DateTickUnit.DAY, 1, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 2, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 3, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 4, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 5, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 6, DateTickUnit.HOUR, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 7, DateTickUnit.DAY, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 10, DateTickUnit.DAY, 1, f5)); units.add(new DateTickUnit(DateTickUnit.DAY, 15, DateTickUnit.DAY, 1, f5)); // months units.add(new DateTickUnit(DateTickUnit.MONTH, 1, DateTickUnit.DAY, 1, f6)); units.add(new DateTickUnit(DateTickUnit.MONTH, 2, DateTickUnit.DAY, 1, f6)); units.add(new DateTickUnit(DateTickUnit.MONTH, 3, DateTickUnit.MONTH, 1, f6)); units.add(new DateTickUnit(DateTickUnit.MONTH, 4, DateTickUnit.MONTH, 1, f6)); units.add(new DateTickUnit(DateTickUnit.MONTH, 6, DateTickUnit.MONTH, 1, f6)); // years units.add(new DateTickUnit(DateTickUnit.YEAR, 1, DateTickUnit.MONTH, 1, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 2, DateTickUnit.MONTH, 3, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 5, DateTickUnit.YEAR, 1, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 10, DateTickUnit.YEAR, 1, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 25, DateTickUnit.YEAR, 5, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 50, DateTickUnit.YEAR, 10, f7)); units.add(new DateTickUnit(DateTickUnit.YEAR, 100, DateTickUnit.YEAR, 20, f7)); return units; }
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 .j a v a 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.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpression.java
protected int getDateUnitAsInt(final Class domainTimePeriod) { if (Second.class.equals(domainTimePeriod)) { return DateTickUnit.SECOND; }//from ww w.jav a 2s.c om if (Minute.class.equals(domainTimePeriod)) { return DateTickUnit.MINUTE; } if (Hour.class.equals(domainTimePeriod)) { return DateTickUnit.HOUR; } if (Day.class.equals(domainTimePeriod)) { return DateTickUnit.DAY; } if (Month.class.equals(domainTimePeriod)) { return DateTickUnit.MONTH; } if (Year.class.equals(domainTimePeriod)) { return DateTickUnit.YEAR; } if (Second.class.equals(domainTimePeriod)) { return DateTickUnit.MILLISECOND; } return DateTickUnit.DAY; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYChartExpression.java
private int getDateUnitAsInt(final Class domainTimePeriod) { if (Second.class.equals(domainTimePeriod)) { return DateTickUnit.SECOND; }/*www . j a va 2 s . co m*/ if (Minute.class.equals(domainTimePeriod)) { return DateTickUnit.MINUTE; } if (Hour.class.equals(domainTimePeriod)) { return DateTickUnit.HOUR; } if (Day.class.equals(domainTimePeriod)) { return DateTickUnit.DAY; } if (Month.class.equals(domainTimePeriod)) { return DateTickUnit.MONTH; } if (Year.class.equals(domainTimePeriod)) { return DateTickUnit.YEAR; } if (Second.class.equals(domainTimePeriod)) { return DateTickUnit.MILLISECOND; } return DateTickUnit.DAY; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
private byte[] createWeeklyLoginChart(int width, int height) { IntervalXYDataset dataset1 = getWeeklyLoginsDataSet(); IntervalXYDataset dataset2 = getWeeklySiteUserDataSet(); if ((dataset1 == null) || (dataset2 == null)) { return generateNoDataChart(width, height); }/* w ww. j av a 2 s . c o m*/ // create plot ... XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesPaint(0, Color.RED); renderer1.setSeriesPaint(0, Color.BLUE); DateAxis domainAxis = new DateAxis(""); domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat("yyyy-MM-dd"))); domainAxis.setTickMarkPosition(DateTickMarkPosition.START); domainAxis.setVerticalTickLabels(true); domainAxis.setLowerMargin(0.01); domainAxis.setUpperMargin(0.01); NumberAxis rangeAxis = new NumberAxis("count"); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot plot1 = new XYPlot(dataset1, null, rangeAxis, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); // add a second dataset and renderer... XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesPaint(0, Color.GREEN); renderer2.setSeriesPaint(1, Color.BLACK); renderer2.setSeriesPaint(2, Color.CYAN); rangeAxis = new NumberAxis("count"); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot plot2 = new XYPlot(dataset2, null, rangeAxis, renderer2); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis); cplot.add(plot1, 3); cplot.add(plot2, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, cplot, false); LegendTitle legend = new LegendTitle(cplot); chart.addSubtitle(legend); // set background chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set anti alias chart.setAntiAlias(true); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
private byte[] createDailyLoginChart(int width, int height) { IntervalXYDataset dataset1 = getDailyLoginsDataSet(); IntervalXYDataset dataset2 = getDailySiteUserDataSet(); if ((dataset1 == null) || (dataset2 == null)) { return generateNoDataChart(width, height); }/*from w w w . j a v a 2 s.c o m*/ // create plot ... XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setSeriesPaint(0, Color.RED); renderer1.setSeriesPaint(1, Color.BLUE); renderer1.setSeriesPaint(2, Color.RED); renderer1.setSeriesPaint(3, Color.BLUE); renderer1.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); BasicStroke dashLineStroke = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0, new float[] { 4 }, 0); renderer1.setSeriesStroke(2, dashLineStroke); renderer1.setSeriesStroke(3, dashLineStroke); DateAxis domainAxis = new DateAxis(""); domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat("yyyy-MM-dd"))); domainAxis.setTickMarkPosition(DateTickMarkPosition.START); domainAxis.setVerticalTickLabels(true); domainAxis.setLowerMargin(0.01); domainAxis.setUpperMargin(0.01); NumberAxis rangeAxis = new NumberAxis("count"); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot plot1 = new XYPlot(dataset1, null, rangeAxis, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); // add a second dataset and renderer... XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesPaint(0, Color.GREEN); renderer2.setSeriesPaint(1, Color.BLACK); renderer2.setSeriesPaint(2, Color.CYAN); rangeAxis = new NumberAxis("count"); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot plot2 = new XYPlot(dataset2, null, rangeAxis, renderer2); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis); cplot.add(plot1, 3); cplot.add(plot2, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, cplot, false); LegendTitle legend = new LegendTitle(cplot); chart.addSubtitle(legend); // set background chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set anti alias chart.setAntiAlias(true); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
/** * *//*from w w w .j a v a2 s. co m*/ protected JFreeChart createXYBarChart() throws JRException { IntervalXYDataset tmpDataset = (IntervalXYDataset) getDataset(); boolean isDate = true; if (getChart().getDataset().getDatasetType() == JRChartDataset.XY_DATASET) { isDate = false; } ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createXYBarChart( (String) evaluateExpression(getChart().getTitleExpression()), (String) evaluateExpression(((JRBarPlot) getPlot()).getCategoryAxisLabelExpression()), isDate, (String) evaluateExpression(((JRBarPlot) getPlot()).getValueAxisLabelExpression()), tmpDataset, getPlot().getOrientation(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); XYPlot xyPlot = (XYPlot) jfreeChart.getPlot(); //plot.setNoDataMessage("No data to display"); // ((XYPlot)plot.getDomainAxis()).setTickMarksVisible( // ((JRBarPlot)getPlot()).isShowTickMarks() // ); // ((CategoryAxis)plot.getDomainAxis()).setTickLabelsVisible( // ((JRBarPlot)getPlot()).isShowTickLabels() // ); // ((NumberAxis)plot.getRangeAxis()).setTickMarksVisible( // ((JRBarPlot)getPlot()).isShowTickMarks() // ); // ((NumberAxis)plot.getRangeAxis()).setTickLabelsVisible( // ((JRBarPlot)getPlot()).isShowTickLabels() // ); XYBarRenderer itemRenderer = (XYBarRenderer) xyPlot.getRenderer(); itemRenderer.setBaseItemLabelGenerator((XYItemLabelGenerator) getLabelGenerator()); itemRenderer.setShadowVisible(false); JRBarPlot barPlot = (JRBarPlot) getPlot(); boolean isShowLabels = barPlot.getShowLabels() == null ? false : barPlot.getShowLabels().booleanValue(); itemRenderer.setBaseItemLabelsVisible(isShowLabels); // Handle the axis formating for the category axis configureAxis(xyPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(), barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(), barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(), barPlot.getCategoryAxisVerticalTickLabels(), barPlot.getOwnCategoryAxisLineColor(), getDomainAxisSettings(), DateTickUnit.DAY, (Comparable) evaluateExpression(barPlot.getDomainAxisMinValueExpression()), (Comparable) evaluateExpression(barPlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(xyPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(), barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(), barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(), barPlot.getValueAxisVerticalTickLabels(), barPlot.getOwnValueAxisLineColor(), getRangeAxisSettings(), DateTickUnit.DAY, (Comparable) evaluateExpression(barPlot.getRangeAxisMinValueExpression()), (Comparable) evaluateExpression(barPlot.getRangeAxisMaxValueExpression())); return jfreeChart; }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
protected JFreeChart createTimeSeriesChart() throws JRException { String timeAxisLabel = (String) evaluateExpression( ((JRTimeSeriesPlot) getPlot()).getTimeAxisLabelExpression()); String valueAxisLabel = (String) evaluateExpression( ((JRTimeSeriesPlot) getPlot()).getValueAxisLabelExpression()); ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createTimeSeriesChart( (String) evaluateExpression(getChart().getTitleExpression()), timeAxisLabel, valueAxisLabel, (TimeSeriesCollection) getDataset(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); XYPlot xyPlot = (XYPlot) jfreeChart.getPlot(); JRTimeSeriesPlot timeSeriesPlot = (JRTimeSeriesPlot) getPlot(); XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer) xyPlot.getRenderer(); boolean isShowShapes = timeSeriesPlot.getShowShapes() == null ? true : timeSeriesPlot.getShowShapes().booleanValue(); boolean isShowLines = timeSeriesPlot.getShowLines() == null ? true : timeSeriesPlot.getShowLines().booleanValue(); lineRenderer.setBaseLinesVisible(isShowLines); lineRenderer.setBaseShapesVisible(isShowShapes); // Handle the axis formating for the category axis configureAxis(xyPlot.getDomainAxis(), timeSeriesPlot.getTimeAxisLabelFont(), timeSeriesPlot.getTimeAxisLabelColor(), timeSeriesPlot.getTimeAxisTickLabelFont(), timeSeriesPlot.getTimeAxisTickLabelColor(), timeSeriesPlot.getTimeAxisTickLabelMask(), timeSeriesPlot.getTimeAxisVerticalTickLabels(), timeSeriesPlot.getOwnTimeAxisLineColor(), getDomainAxisSettings(), DateTickUnit.DAY, (Comparable) evaluateExpression(timeSeriesPlot.getDomainAxisMinValueExpression()), (Comparable) evaluateExpression(timeSeriesPlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(xyPlot.getRangeAxis(), timeSeriesPlot.getValueAxisLabelFont(), timeSeriesPlot.getValueAxisLabelColor(), timeSeriesPlot.getValueAxisTickLabelFont(), timeSeriesPlot.getValueAxisTickLabelColor(), timeSeriesPlot.getValueAxisTickLabelMask(), timeSeriesPlot.getValueAxisVerticalTickLabels(), timeSeriesPlot.getOwnValueAxisLineColor(), getRangeAxisSettings(), DateTickUnit.DAY, (Comparable) evaluateExpression(timeSeriesPlot.getRangeAxisMinValueExpression()), (Comparable) evaluateExpression(timeSeriesPlot.getRangeAxisMaxValueExpression())); return jfreeChart; }