List of usage examples for org.jfree.chart.axis DateAxis setTickUnit
public void setTickUnit(DateTickUnit unit)
From source file:net.sf.jsfcomp.chartcreator.utils.ChartAxisUtils.java
public static ValueAxis createDateAxis(JFreeChart chart, ChartAxisData chartAxisData) { DateAxis dateAxis = new DateAxis(chartAxisData.getLabel()); if (chartAxisData.getFormat() != null) dateAxis.setDateFormatOverride(new SimpleDateFormat(chartAxisData.getFormat())); dateAxis.setTickUnit(DateAxis.DEFAULT_DATE_TICK_UNIT); return dateAxis; }
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:scrum.server.common.BurndownChart.java
private static JFreeChart createSprintBurndownChart(List<BurndownSnapshot> snapshots, Date firstDay, Date lastDay, Date originallyLastDay, WeekdaySelector freeDays, int dateMarkTickUnit, float widthPerDay) { DefaultXYDataset data = createSprintBurndownChartDataset(snapshots, firstDay, lastDay, originallyLastDay, freeDays);/*from w w w . j a va 2 s . co m*/ double tick = 1.0; double max = BurndownChart.getMaximum(data); while (max / tick > 25) { tick *= 2; if (max / tick <= 25) break; tick *= 2.5; if (max / tick <= 25) break; tick *= 2; } double valueLabelTickUnit = tick; double upperBoundary = Math.min(max * 1.1f, max + 3); if (!Sys.isHeadless()) LOG.warn("GraphicsEnvironment is not headless"); JFreeChart chart = ChartFactory.createXYLineChart("", "", "", data, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.WHITE); XYPlot plot = chart.getXYPlot(); // plot.setInsets(new RectangleInsets(0, 0, 0, 0)); plot.setAxisOffset(RectangleInsets.ZERO_INSETS); // plot.setOutlineVisible(false); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setDomainGridlinePaint(Color.lightGray); // plot.setRangeCrosshairPaint(Color.lightGray); // plot.setRangeMinorGridlinePaint(Color.lightGray); // plot.setDomainCrosshairPaint(Color.blue); // plot.setDomainMinorGridlinePaint(Color.green); // plot.setDomainTickBandPaint(Color.green); XYItemRenderer renderer = plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(2f)); renderer.setSeriesPaint(0, COLOR_PAST_LINE); renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer.setSeriesPaint(1, COLOR_PROJECTION_LINE); renderer.setSeriesStroke(1, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { 3f }, 0)); renderer.setSeriesPaint(2, COLOR_OPTIMUM_LINE); renderer.setSeriesStroke(2, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); DateAxis domainAxis1 = new DateAxis(); String dateFormat = "d."; widthPerDay -= 5; if (widthPerDay > 40) { dateFormat = "EE " + dateFormat; } if (widthPerDay > 10) { float spaces = widthPerDay / 2.7f; dateFormat = Str.multiply(" ", (int) spaces) + dateFormat; } domainAxis1.setDateFormatOverride(new SimpleDateFormat(dateFormat, Locale.US)); domainAxis1.setTickUnit(new DateTickUnit(DateTickUnit.DAY, dateMarkTickUnit)); domainAxis1.setAxisLineVisible(false); Range range = new Range(firstDay.toMillis(), lastDay.nextDay().toMillis()); domainAxis1.setRange(range); DateAxis domainAxis2 = new DateAxis(); domainAxis2.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1)); domainAxis2.setTickMarksVisible(false); domainAxis2.setTickLabelsVisible(false); domainAxis2.setRange(range); plot.setDomainAxis(0, domainAxis2); plot.setDomainAxis(1, domainAxis1); plot.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setNumberFormatOverride(NumberFormat.getIntegerInstance()); rangeAxis.setTickUnit(new NumberTickUnit(valueLabelTickUnit)); rangeAxis.setLowerBound(0); rangeAxis.setUpperBound(upperBoundary); plot.setRangeAxis(rangeAxis); return chart; }
From source file:org.jfree.chart.demo.TimePeriodValuesDemo1.java
public TimePeriodValuesDemo1(String s) { super(s);/*from www . j a v a2 s . co m*/ 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.TimeSeriesDemo3.java
/** * Creates a new chart.// w w w. j ava2s. c o 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"; }/*from www . j a v a 2 s.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:org.jfree.chart.demo.TimePeriodValuesDemo.java
/** * A demonstration application showing how to.... * * @param title the frame title./*from w w w . j a va 2 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: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"; }//from www. j a va 2s .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:jgnash.ui.report.compiled.RunningAccountBalanceChart.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); LocalDate start = DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate()); LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate()); dateAxis.setRange(DateUtils.asDate(start), DateUtils.asDate(end)); 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.EndMonthBalance") + " - " + a.getPathName(); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(null);/*w w w.jav a 2 s. co m*/ return chart; }
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 ww .j a v a2 s .c o 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; }