List of usage examples for org.jfree.chart.axis DateAxis setVerticalTickLabels
public void setVerticalTickLabels(boolean flag)
From source file:org.spf4j.perf.impl.chart.Charts.java
private static JFreeChart createJFreeChart(final String chartName, final String uom, final XYDataset timeseriescollection) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(chartName, "Time", uom, timeseriescollection, true, true, false);/*from w ww .j av a2s .c om*/ XYPlot xyplot = (XYPlot) jfreechart.getPlot(); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setVerticalTickLabels(true); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setUseFillPaint(true); xylineandshaperenderer.setLegendItemToolTipGenerator(new StandardXYSeriesLabelGenerator("Tooltip {0}")); return jfreechart; }
From source file:com.unicornlabs.kabouter.reporting.PowerReport.java
public static void GeneratePowerReport(Date startDate, Date endDate) { try {/*from www .j a v a 2 s . com*/ Historian theHistorian = (Historian) BusinessObjectManager.getBusinessObject(Historian.class.getName()); ArrayList<String> powerLogDeviceIds = theHistorian.getPowerLogDeviceIds(); Document document = new Document(PageSize.A4, 50, 50, 50, 50); File outputFile = new File("PowerReport.pdf"); outputFile.createNewFile(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile)); document.open(); document.add(new Paragraph("Power Report for " + startDate.toString() + " to " + endDate.toString())); document.newPage(); DecimalFormat df = new DecimalFormat("#.###"); for (String deviceId : powerLogDeviceIds) { ArrayList<Powerlog> powerlogs = theHistorian.getPowerlogs(deviceId, startDate, endDate); double total = 0; double max = 0; Date maxTime = startDate; double average = 0; XYSeries series = new XYSeries(deviceId); XYDataset dataset = new XYSeriesCollection(series); for (Powerlog log : powerlogs) { total += log.getPower(); if (log.getPower() > max) { max = log.getPower(); maxTime = log.getId().getLogtime(); } series.add(log.getId().getLogtime().getTime(), log.getPower()); } average = total / powerlogs.size(); document.add(new Paragraph("\nDevice: " + deviceId)); document.add(new Paragraph("Average Power Usage: " + df.format(average))); document.add(new Paragraph("Maximum Power Usage: " + df.format(max) + " at " + maxTime.toString())); document.add(new Paragraph("Total Power Usage: " + df.format(total))); //Create a custom date axis to display dates on the X axis DateAxis dateAxis = new DateAxis("Date"); //Make the labels vertical dateAxis.setVerticalTickLabels(true); //Create the power axis NumberAxis powerAxis = new NumberAxis("Power"); //Set both axes to auto range for their values powerAxis.setAutoRange(true); dateAxis.setAutoRange(true); //Create the tooltip generator StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator("{0}: {2}", new SimpleDateFormat("yyyy/MM/dd HH:mm"), NumberFormat.getInstance()); //Set the renderer StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES, ttg, null); //Create the plot XYPlot plot = new XYPlot(dataset, dateAxis, powerAxis, renderer); //Create the chart JFreeChart myChart = new JFreeChart(deviceId, JFreeChart.DEFAULT_TITLE_FONT, plot, true); PdfContentByte pcb = writer.getDirectContent(); PdfTemplate tp = pcb.createTemplate(480, 360); Graphics2D g2d = tp.createGraphics(480, 360, new DefaultFontMapper()); Rectangle2D r2d = new Rectangle2D.Double(0, 0, 480, 360); myChart.draw(g2d, r2d); g2d.dispose(); pcb.addTemplate(tp, 0, 0); document.newPage(); } document.close(); JOptionPane.showMessageDialog(null, "Report Generated."); Desktop.getDesktop().open(outputFile); } catch (FileNotFoundException fnfe) { JOptionPane.showMessageDialog(null, "Unable To Open File For Writing, Make Sure It Is Not Currently Open"); } catch (IOException ex) { Logger.getLogger(PowerReport.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(PowerReport.class.getName()).log(Level.SEVERE, null, ex); } }
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; }
From source file:org.jfree.chart.demo.TimePeriodValuesDemo1.java
public TimePeriodValuesDemo1(String s) { super(s);/*w ww .j av a2s . com*/ XYDataset xydataset = createDataset1(); XYBarRenderer xybarrenderer = new XYBarRenderer(); DateAxis dateaxis = new DateAxis("Date"); dateaxis.setVerticalTickLabels(true); dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1)); dateaxis.setDateFormatOverride(new SimpleDateFormat("hh:mm")); dateaxis.setLowerMargin(0.01D); dateaxis.setUpperMargin(0.01D); NumberAxis numberaxis = new NumberAxis("Value"); XYPlot xyplot = new XYPlot(xydataset, dateaxis, numberaxis, xybarrenderer); XYDataset xydataset1 = createDataset2(); StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer(3); standardxyitemrenderer.setBaseShapesFilled(true); xyplot.setDataset(1, xydataset1); xyplot.setRenderer(1, standardxyitemrenderer); JFreeChart jfreechart = new JFreeChart("Supply and Demand", xyplot); ChartPanel chartpanel = new ChartPanel(jfreechart); chartpanel.setPreferredSize(new Dimension(500, 270)); chartpanel.setMouseZoomable(true, false); setContentPane(chartpanel); }
From source file:org.jfree.chart.demo.TimePeriodValuesDemo.java
/** * A demonstration application showing how to.... * * @param title the frame title.//from w w w . j a v a2 s .co m */ public TimePeriodValuesDemo(final String title) { super(title); final XYDataset data1 = createDataset1(); final XYItemRenderer renderer1 = new XYBarRenderer(); final DateAxis domainAxis = new DateAxis("Date"); domainAxis.setVerticalTickLabels(true); domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.HOUR, 1)); domainAxis.setDateFormatOverride(new SimpleDateFormat("hh:mm")); domainAxis.setLowerMargin(0.01); domainAxis.setUpperMargin(0.01); final ValueAxis rangeAxis = new NumberAxis("Value"); final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1); final XYDataset data2 = createDataset2(); final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer( StandardXYItemRenderer.SHAPES_AND_LINES); renderer2.setShapesFilled(true); plot.setDataset(1, data2); plot.setRenderer(1, renderer2); final JFreeChart chart = new JFreeChart("Supply and Demand", plot); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); chartPanel.setMouseZoomable(true, false); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.TimeSeriesDemo3.java
/** * Creates a new chart.//from w w w. j a v a 2 s. co m * * @param dataset the dataset. * * @return The dataset. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series Demo 3", "Time", "Value", dataset, true, true, false); final XYPlot plot = chart.getXYPlot(); final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat("MMM-yyyy"))); axis.setVerticalTickLabels(true); final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setPlotShapes(true); renderer.setSeriesShapesFilled(0, Boolean.TRUE); renderer.setSeriesShapesFilled(1, Boolean.FALSE); return chart; }
From source file:msec.org.Tools.java
public static String generateFullDayChart(String filename, OneDayValue[] data, String title) { if (data[0].getValues().length != 1440) { return "data size invalid"; }// w w w. j a v a 2s .c o m if (data.length > 1) { if (data[1].getValues() == null || data[1].getValues().length != 1440) { return "data 1 invalid"; } } XYDataset xydataset = createDataset(data); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true); try { XYPlot xyplot = (XYPlot) jfreechart.getPlot(); // DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm")); dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); // dateaxis.setLabelPaint(ChartColor.gray); dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16)); dateaxis.setTickLabelPaint(ChartColor.GRAY); GregorianCalendar endgc = (GregorianCalendar) gc.clone(); endgc.add(GregorianCalendar.DATE, 1); dateaxis.setMaximumDate(endgc.getTime()); dateaxis.setTickMarksVisible(true); dateaxis.setTickMarkInsideLength(5); dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2)); dateaxis.setVerticalTickLabels(true); dateaxis.setLabel(""); // ValueAxis rangeAxis = xyplot.getRangeAxis();//? rangeAxis.setLabelFont(new Font("", Font.PLAIN, 16)); rangeAxis.setLabelPaint(ChartColor.gray); rangeAxis.setTickLabelFont(new Font("", Font.PLAIN, 16)); rangeAxis.setTickLabelPaint(ChartColor.gray); rangeAxis.setLowerBound(0); // jfreechart.getLegend().setItemFont(new Font("", Font.PLAIN, 12)); jfreechart.getLegend().setItemPaint(ChartColor.gray); jfreechart.getLegend().setBorder(0, 0, 0, 0);// // jfreechart.getTitle().setFont(new Font("", Font.PLAIN, 18));// jfreechart.getTitle().setPaint(ChartColor.gray); //? xyplot.setRangeGridlinePaint(ChartColor.GRAY); xyplot.setBackgroundPaint(ChartColor.WHITE); xyplot.setOutlinePaint(null);// int w = 500; int h = 300; // ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h); ChartUtilities.saveChartAsJPEG(new File(filename), 0.8f, jfreechart, w, h); return "success"; } catch (Exception e) { e.printStackTrace(); return e.getMessage(); } }
From source file:EHRAppointment.ChartPanelDraw.java
private JComboBox createDate() { // to change the vertical and horizontal data final JComboBox date = new JComboBox(); final String[] dateCmds = { "Horizontal Dates", "Vertical Dates" }; date.setModel(new DefaultComboBoxModel(dateCmds)); date.addActionListener(new ActionListener() { @Override/* w w w. ja va 2 s . c o m*/ public void actionPerformed(ActionEvent e) { JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); DateAxis domain = (DateAxis) plot.getDomainAxis(); if (dateCmds[0].equals(date.getSelectedItem())) { domain.setVerticalTickLabels(false); } else { domain.setVerticalTickLabels(true); } } }); return date; }
From source file:msec.org.Tools.java
public static String generateDaysChart(String filename, ArrayList<OneDayValue> data, OneAttrDaysChart chart, String title, int duration) { if (data.size() == 0) { return "data size invalid"; }// w w w. j a va2 s . com int date = Integer.parseInt(data.get(0).getDate()); GregorianCalendar startgc = new GregorianCalendar(date / 10000, date % 10000 / 100 - 1, date % 100); XYDataset xydataset = createDaysDataset(data, startgc, chart); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true); try { XYPlot xyplot = (XYPlot) jfreechart.getPlot(); // DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("MM/dd")); dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); // dateaxis.setLabelPaint(ChartColor.gray); dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16)); dateaxis.setTickLabelPaint(ChartColor.GRAY); dateaxis.setMinimumDate(startgc.getTime()); GregorianCalendar endgc = (GregorianCalendar) startgc.clone(); endgc.add(GregorianCalendar.DATE, duration); dateaxis.setMaximumDate(endgc.getTime()); dateaxis.setTickMarksVisible(true); dateaxis.setTickMarkInsideLength(5); dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1)); dateaxis.setVerticalTickLabels(true); dateaxis.setLabel(""); // ValueAxis rangeAxis = xyplot.getRangeAxis();//? rangeAxis.setLabelFont(new Font("", Font.PLAIN, 16)); rangeAxis.setLabelPaint(ChartColor.gray); rangeAxis.setTickLabelFont(new Font("", Font.PLAIN, 16)); rangeAxis.setTickLabelPaint(ChartColor.gray); rangeAxis.setLowerBound(0); // jfreechart.getLegend().setItemFont(new Font("", Font.PLAIN, 12)); jfreechart.getLegend().setItemPaint(ChartColor.gray); jfreechart.getLegend().setBorder(0, 0, 0, 0);// // jfreechart.getTitle().setFont(new Font("", Font.PLAIN, 18));// jfreechart.getTitle().setPaint(ChartColor.gray); //? xyplot.setRangeGridlinePaint(ChartColor.GRAY); xyplot.setBackgroundPaint(ChartColor.WHITE); xyplot.setOutlinePaint(null);// int w = 500; int h = 300; // ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h); ChartUtilities.saveChartAsJPEG(new File(filename), 0.8f, jfreechart, w, h); return "success"; } catch (Exception e) { e.printStackTrace(); return e.getMessage(); } }
From source file:org.n52.oxf.render.sos.TimeSeriesMapChartRenderer.java
/** * The resulting chart consists a TimeSeries for each FeatureOfInterest contained in the * observationCollection./*from ww w . j ava 2s . c o m*/ * * @param foiIdArray * the IDs of the FeaturesOfInterest whose Observations shall be rendered * @param observationCollection * @return */ protected XYPlot drawChart4FOI(String foiID, Map<ITimePosition, ObservedValueTuple> timeMap) { TimeSeriesCollection dataset = new TimeSeriesCollection(); TimeSeries timeSeries = new TimeSeries(foiID, Second.class); for (ITimePosition timePos : timeMap.keySet()) { Number value = (Number) timeMap.get(timePos).getValue(0); timeSeries.add( new Second(new Float(timePos.getSecond()).intValue(), timePos.getMinute(), timePos.getHour(), timePos.getDay(), timePos.getMonth(), new Long(timePos.getYear()).intValue()), value); } dataset.addSeries(timeSeries); dataset.setDomainIsPointsInTime(true); // // create Plot: // XYPlot plot = new XYPlot(); plot.setDataset(dataset); plot.setBackgroundPaint(Color.white); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); plot.setRenderer(renderer); DateAxis dateAxis = new DateAxis(); dateAxis.setTickMarkPosition(DateTickMarkPosition.START); dateAxis.setTickMarksVisible(true); dateAxis.setVerticalTickLabels(true); dateAxis.setDateFormatOverride(new SimpleDateFormat("dd'.'MM'.'")); plot.setDomainAxis(dateAxis); plot.setRangeAxis(new NumberAxis()); return plot; }