List of usage examples for org.jfree.chart.axis DateTickUnit DateTickUnit
public DateTickUnit(int unit, int count, DateFormat formatter)
From source file:jgnash.ui.report.compiled.MonthlyAccountBalanceChart.java
private JFreeChart createVerticalXYBarChart(Account a) { DateFormat df = new SimpleDateFormat("MM/yy"); TimeSeriesCollection data = createTimeSeriesCollection(a); DateAxis dateAxis = new DateAxis(rb.getString("Column.Date")); dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, df)); dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); // if (a.getTransactionCount() > 0) { Date start = DateUtils.asDate(DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate())); Date end = DateUtils.asDate(DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate())); dateAxis.setRange(start, end);/* w w w .j ava 2s . co m*/ // } NumberAxis valueAxis = new NumberAxis(rb.getString("Column.Balance")); StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator("{1}, {2}", df, NumberFormat.getNumberInstance()); XYBarRenderer renderer = new XYBarRenderer(0.2); renderer.setBaseToolTipGenerator(tooltipGenerator); XYPlot plot = new XYPlot(data, dateAxis, valueAxis, renderer); String title = rb.getString("Title.AccountBalance") + " - " + a.getPathName(); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(null); return chart; }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java
/** * Creates a chart of the actual view with a title. * @param title//w ww. jav a 2 s .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:jgnash.ui.report.compiled.MonthlyAccountBalanceChartCompare.java
private JFreeChart createVerticalXYBarChart(final Account a, final Account a2) { DateFormat df = new SimpleDateFormat("MM/yy"); TimeSeriesCollection data = createTimeSeriesCollection(a, a2); DateAxis dateAxis = new DateAxis(rb.getString("Column.Date")); dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, df)); dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); // if (a.getTransactionCount() > 0) { Date start = DateUtils.asDate(DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate())); Date end = DateUtils.asDate(DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate())); dateAxis.setRange(start, end);/*from w w w.j av a 2s . c om*/ // } NumberAxis valueAxis = new NumberAxis( rb.getString("Column.Balance") + "-" + a.getCurrencyNode().getSymbol()); StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator("{1}, {2}", df, NumberFormat.getNumberInstance()); ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer(0.2, false); renderer.setBaseToolTipGenerator(tooltipGenerator); XYPlot plot = new XYPlot(data, dateAxis, valueAxis, renderer); String title; if (jcb_compare.isSelected()) { title = a.getPathName() + " vs " + a2.getPathName(); } else { title = rb.getString("Title.AccountBalance") + " - " + a.getPathName(); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(null); return chart; }
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 ww . j a v a 2s. c om 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:sk.uniza.fri.pds.spotreba.energie.gui.MainGui.java
private void showSpendingStatisticsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showSpendingStatisticsActionPerformed final SpendingStatisticsParameters params = new SpendingStatisticsParameters(); int option = showUniversalInputDialog(params, "Vvoj spotreby"); if (option == JOptionPane.OK_OPTION) { new SwingWorker<List, RuntimeException>() { @Override/*from ww w. j a v a 2s . co m*/ protected List doInBackground() throws Exception { try { return SeHistoriaService.getInstance().getSpendingStatistics(params); } catch (RuntimeException e) { publish(e); return null; } } @Override protected void done() { try { List<KrokSpotreby> spendingStatistics = get(); if (spendingStatistics != null) { final TimeSeries series = new TimeSeries(""); final String title = "Vvoj spotreby"; for (KrokSpotreby krok : spendingStatistics) { series.add(new Month(krok.getDatumOd()), krok.getSpotreba()); } final IntervalXYDataset dataset = (IntervalXYDataset) new TimeSeriesCollection(series); JFreeChart chart = ChartFactory.createXYBarChart(title, // title "", // x-axis label true, // date axis? "", // y-axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // create legend? true, // generate tooltips? false // generate URLs? ); // Set date axis style DateAxis axis = (DateAxis) ((XYPlot) chart.getPlot()).getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("yyyy")); DateFormat formatter = new SimpleDateFormat("yyyy"); DateTickUnit unit = new DateTickUnit(DateTickUnitType.YEAR, 1, formatter); axis.setTickUnit(unit); JOptionPane.showMessageDialog(null, new ChartPanel(chart)); } } catch (InterruptedException | ExecutionException ex) { Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex); } } @Override protected void process(List<RuntimeException> chunks) { if (chunks.size() > 0) { showException("Chyba", chunks.get(0)); } } }.execute(); } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaLineChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final XYPlot plot = chart.getXYPlot(); if (isSharedRangeAxis() == false) { final ValueAxis linesAxis = plot.getRangeAxis(1); if (linesAxis instanceof NumberAxis) { final NumberAxis numberAxis = (NumberAxis) linesAxis; numberAxis.setAutoRangeIncludesZero(isLineAxisIncludesZero()); numberAxis.setAutoRangeStickyZero(isLineAxisStickyZero()); if (getLinePeriodCount() > 0) { if (getLineTicksLabelFormat() != null) { final FastDecimalFormat formatter = new FastDecimalFormat(getLineTicksLabelFormat(), getResourceBundleFactory().getLocale()); numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount())); }//from ww w.j a v a 2 s. c o m } else { if (getLineTicksLabelFormat() != null) { final DecimalFormat formatter = new DecimalFormat(getLineTicksLabelFormat(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setNumberFormatOverride(formatter); } } } else if (linesAxis instanceof DateAxis) { final DateAxis numberAxis = (DateAxis) linesAxis; if (getLinePeriodCount() > 0 && getLineTimePeriod() != null) { if (getLineTicksLabelFormat() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getLineTicksLabelFormat(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount())); } } else if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setDateFormatOverride(formatter); } } if (linesAxis != null) { final Font labelFont = Font.decode(getLabelFont()); linesAxis.setLabelFont(labelFont); linesAxis.setTickLabelFont(labelFont); if (getLineTitleFont() != null) { linesAxis.setLabelFont(getLineTitleFont()); } if (getLineTickFont() != null) { linesAxis.setTickLabelFont(getLineTickFont()); } final int level = getRuntime().getProcessingContext().getCompatibilityLevel(); if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) { final double lineRangeMinimumVal = lineRangeMinimum == null ? 0 : lineRangeMinimum; final double lineRangeMaximumVal = lineRangeMaximum == null ? 0 : lineRangeMaximum; if (lineRangeMinimum != null) { linesAxis.setLowerBound(getLineRangeMinimum()); } if (lineRangeMaximum != null) { linesAxis.setUpperBound(getRangeMaximum()); } if (lineRangeMinimumVal == 0 && lineRangeMaximumVal == 1) { linesAxis.setLowerBound(0); linesAxis.setUpperBound(1); linesAxis.setAutoRange(true); } } else { if (lineRangeMinimum != null) { linesAxis.setLowerBound(lineRangeMinimum); } if (lineRangeMaximum != null) { linesAxis.setUpperBound(lineRangeMaximum); } linesAxis.setAutoRange(isLineAxisAutoRange()); } } } final XYLineAndShapeRenderer linesRenderer = (XYLineAndShapeRenderer) plot.getRenderer(1); if (linesRenderer != null) { //set stroke with line width linesRenderer.setStroke(translateLineStyle(getLineWidth(), getLineStyle())); //hide shapes on line linesRenderer.setShapesVisible(isMarkersVisible()); linesRenderer.setBaseShapesFilled(isMarkersVisible()); //set colors for each line for (int i = 0; i < lineSeriesColor.size(); i++) { final String s = (String) lineSeriesColor.get(i); linesRenderer.setSeriesPaint(i, parseColorFromString(s)); } } }
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:/*from www . ja 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:org.pentaho.plugin.jfreereport.reportcharts.BarLineChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final CategoryPlot plot = chart.getCategoryPlot(); if (isSharedRangeAxis() == false) { final ValueAxis linesAxis = plot.getRangeAxis(1); if (linesAxis instanceof NumberAxis) { final NumberAxis numberAxis = (NumberAxis) linesAxis; numberAxis.setAutoRangeIncludesZero(isLineAxisIncludesZero()); numberAxis.setAutoRangeStickyZero(isLineAxisStickyZero()); if (getLinePeriodCount() > 0) { if (getLineTicksLabelFormat() != null) { final FastDecimalFormat formatter = new FastDecimalFormat(getLineTicksLabelFormat(), getResourceBundleFactory().getLocale()); numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount())); }//from w ww . ja v a 2 s. co m } else { if (getLineTicksLabelFormat() != null) { final DecimalFormat formatter = new DecimalFormat(getLineTicksLabelFormat(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setNumberFormatOverride(formatter); } } } else if (linesAxis instanceof DateAxis) { final DateAxis numberAxis = (DateAxis) linesAxis; if (getLinePeriodCount() > 0 && getLineTimePeriod() != null) { if (getLineTicksLabelFormat() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getLineTicksLabelFormat(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount())); } } else if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setDateFormatOverride(formatter); } } if (linesAxis != null) { final Font labelFont = Font.decode(getLabelFont()); linesAxis.setLabelFont(labelFont); linesAxis.setTickLabelFont(labelFont); if (getLineTitleFont() != null) { linesAxis.setLabelFont(getLineTitleFont()); } if (getLineTickFont() != null) { linesAxis.setTickLabelFont(getLineTickFont()); } final int level = getRuntime().getProcessingContext().getCompatibilityLevel(); if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) { if (getRangeMinimum() != 0) { linesAxis.setLowerBound(getLineRangeMinimum()); } if (getRangeMaximum() != 1) { linesAxis.setUpperBound(getLineRangeMaximum()); } if (getLineRangeMinimum() == 0 && getLineRangeMaximum() == 1) { linesAxis.setLowerBound(0); linesAxis.setUpperBound(1); linesAxis.setAutoRange(true); } } else { linesAxis.setLowerBound(getLineRangeMinimum()); linesAxis.setUpperBound(getLineRangeMaximum()); linesAxis.setAutoRange(isLineAxisAutoRange()); } } } final LineAndShapeRenderer linesRenderer = (LineAndShapeRenderer) plot.getRenderer(1); if (linesRenderer != null) { //set stroke with line width linesRenderer.setStroke(translateLineStyle(lineWidth, lineStyle)); //hide shapes on line linesRenderer.setShapesVisible(isMarkersVisible()); linesRenderer.setBaseShapesFilled(isMarkersVisible()); //set colors for each line for (int i = 0; i < lineSeriesColor.size(); i++) { final String s = (String) lineSeriesColor.get(i); linesRenderer.setSeriesPaint(i, parseColorFromString(s)); } } }
From source file:com.freedomotic.jfrontend.extras.GraphPanel.java
private void createChart(UsageDataFrame points, String title) { series = new TimeSeries(title); for (UsageData d : points.getData()) { Date resultdate = d.getDateTime(); Millisecond ms_read = new Millisecond(resultdate); int poweredValue = -1; if (d.getObjBehavior().equalsIgnoreCase("powered")) { poweredValue = d.getObjValue().equalsIgnoreCase("true") ? 1 : 0; } else if (d.getObjBehavior().equalsIgnoreCase("brigthness")) { try { poweredValue = Integer.parseInt(d.getObjValue()); } catch (NumberFormatException ex) { poweredValue = -1;/*from w w w . ja v a2 s. co m*/ } } series.addOrUpdate(ms_read, poweredValue); } XYDataset xyDataset = new TimeSeriesCollection(series); chart = ChartFactory.createTimeSeriesChart("Chart", "TIME", "VALUE", xyDataset, true, // legend true, // tooltips false // urls ); chart.setAntiAlias(true); // Set plot styles XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); // Set series line styles plot.setRenderer(new XYStepRenderer()); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setShapesVisible(true); renderer.setShapesFilled(true); } // Set date axis style DateAxis axis = (DateAxis) plot.getDomainAxis(); String formatString = "MM-dd HH"; DateTickUnitType dtut = DateTickUnitType.HOUR; if (jComboGranularity.getSelectedItem().equals("Year")) { formatString = "yyyy"; dtut = DateTickUnitType.YEAR; } else if (jComboGranularity.getSelectedItem().equals("Month")) { axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM")); dtut = DateTickUnitType.MONTH; } else if (jComboGranularity.getSelectedItem().equals("Day")) { axis.setDateFormatOverride(new SimpleDateFormat("MM-dd")); dtut = DateTickUnitType.DAY; } else if (jComboGranularity.getSelectedItem().equals("Minute")) { formatString = "MM-dd HH:mm"; dtut = DateTickUnitType.MINUTE; } else if (jComboGranularity.getSelectedItem().equals("Second")) { formatString = "HH:mm:SS"; dtut = DateTickUnitType.SECOND; } DateFormat formatter = new SimpleDateFormat(formatString); DateTickUnit unit = new DateTickUnit(dtut, 1, formatter); axis.setTickUnit(unit); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(800, 500)); graphPanel.removeAll(); graphPanel.add(chartPanel); }
From source file:de.fau.amos.ChartRenderer.java
/** * Creates Chart with Bars (JFreeChart object) from TimeSeriesCollection. Is used when granularity is set to days, months or years. * Adjusts display of the chart, not the values itself. * /*w w w .jav a 2 s. c o m*/ * @param collection TimeSeriesCollection that should be used as basis of chart. * @param timeGranularity Selected granularity. Value is similar to granularity contained in TimeSeriesCollection "collection". * @param time first element of time that is displayed. Is used for caption text and axis text. * @param unit Unit of displayed values (kWh or kWh/TNF). * @return Returns finished JFreeChart object. */ private JFreeChart createTimeBarChart(TimeSeriesCollection collection, String timeGranularity, String time, String unit) { String xAxisLabel = null; // Modification of X-Axis Label (depending on the granularity) int month; String monthString = null; switch (timeGranularity) { //for Case "0" see method "createTimeLineChart" case "1": month = Integer.parseInt(time.substring(5, 7)); monthString = new DateFormatSymbols(Locale.US).getMonths()[month - 1]; xAxisLabel = "" + monthString + " " + time.substring(0, 4); break; case "2": xAxisLabel = time.substring(0, 4); break; case "3": xAxisLabel = "Years"; break; default: xAxisLabel = "Timespan"; } JFreeChart barChart = ChartFactory.createXYBarChart("Bar Chart", // title xAxisLabel, // x-axis label true, // date axis? // "Energy Consumption "+("1".equals(unit)?"[kWh]":("2".equals(unit)?"[kWh/TNF]":("3".equals(unit)?"[TNF]":""))), // y-axis label ("1".equals(unit) ? "Energy Consumption [kWh]" : ("2".equals(unit) ? "Energy Consumption [kWh/TNF]" : ("3".equals(unit) ? "Produced Pieces [TNF]" : ""))), collection, // data PlotOrientation.VERTICAL, // orientation true, // create legend? true, // generate tooltips? false // generate URLs? ); //graphical modifications for BarChart barChart.setBackgroundPaint(Color.white); XYPlot plot = barChart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); //Axis modification: Set Axis X-Value directly below the bars DateAxis dateAxis = (DateAxis) plot.getDomainAxis(); dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Axis modification: Remove Values from x-Axis that belong to former/later time element (Month/Day) dateAxis.setLowerMargin(0.01); dateAxis.setUpperMargin(0.01); //Axis modification: Axis values (depending on timeGranularity) if (timeGranularity.equals("1")) { dateAxis.setTickUnit( new DateTickUnit(DateTickUnitType.DAY, 2, new SimpleDateFormat(" dd. ", Locale.US))); } if (timeGranularity.equals("2")) { dateAxis.setTickUnit( new DateTickUnit(DateTickUnitType.MONTH, 1, new SimpleDateFormat(" MMM ", Locale.US))); } if (timeGranularity.equals("3")) { dateAxis.setTickUnit( new DateTickUnit(DateTickUnitType.YEAR, 1, new SimpleDateFormat(" yyyy ", Locale.US))); } ClusteredXYBarRenderer clusteredxybarrenderer = new ClusteredXYBarRenderer(0.25, false); clusteredxybarrenderer.setShadowVisible(false); clusteredxybarrenderer.setBarPainter(new StandardXYBarPainter()); plot.setRenderer(clusteredxybarrenderer); return barChart; }