private static JFreeChart createChart(TableXYDataset tablexydataset) { DateAxis dateaxis = new DateAxis("Date"); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); dateaxis.setLowerMargin(0.01D); dateaxis.setUpperMargin(0.01D); NumberAxis numberaxis = new NumberAxis("Count"); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setUpperMargin(0.10000000000000001D); StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.14999999999999999D); stackedxybarrenderer.setDrawBarOutline(false); stackedxybarrenderer.setBaseItemLabelsVisible(true); stackedxybarrenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); stackedxybarrenderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER)); stackedxybarrenderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator( "{0} : {1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0"))); XYPlot xyplot = new XYPlot(tablexydataset, dateaxis, numberaxis, stackedxybarrenderer); JFreeChart jfreechart = new JFreeChart("Holes-In-One / Double Eagles", xyplot); jfreechart.removeLegend(); jfreechart.addSubtitle(new TextTitle("PGA Tour, 1983 to 2003")); TextTitle texttitle = new TextTitle( "http://www.golfdigest.com/majors/masters/index.ssf?/majors/masters/gw20040402albatross.html", new Font("Dialog", 0, 8)); jfreechart.addSubtitle(texttitle); jfreechart.setTextAntiAlias(RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); LegendTitle legendtitle = new LegendTitle(xyplot); legendtitle.setBackgroundPaint(Color.white); legendtitle.setFrame(new BlockBorder()); legendtitle.setPosition(RectangleEdge.BOTTOM); jfreechart.addSubtitle(legendtitle); return jfreechart; }
private static JFreeChart createChart() { DateAxis dateaxis = new DateAxis("Date"); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); NumberAxis numberaxis = new NumberAxis("Value"); IntervalXYDataset intervalxydataset = createDataset1(); XYBarRenderer xybarrenderer = new XYBarRenderer(0.20000000000000001D); xybarrenderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator( "{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); XYPlot xyplot = new XYPlot(intervalxydataset, dateaxis, numberaxis, xybarrenderer); NumberAxis numberaxis1 = new NumberAxis("Value 2"); xyplot.setRangeAxis(1, numberaxis1); XYDataset xydataset = createDataset2A(); StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer(); standardxyitemrenderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator( "{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); xyplot.setDataset(1, xydataset); xyplot.setRenderer(1, standardxyitemrenderer); XYDataset xydataset1 = createDataset2B(); xyplot.setDataset(2, xydataset1); xyplot.setRenderer(2, new StandardXYItemRenderer()); xyplot.mapDatasetToRangeAxis(2, 1); xyplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); xyplot.setOrientation(PlotOrientation.VERTICAL); JFreeChart jfreechart = new JFreeChart("Overlaid XYPlot Demo 2", JFreeChart.DEFAULT_TITLE_FONT, xyplot, true); ChartUtilities.applyCurrentTheme(jfreechart); return jfreechart; }
/** Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DateAxis a1 = new DateAxis("Test"); DateAxis a2 = new DateAxis("Test"); assertTrue(a1.equals(a2)); assertFalse(a1.equals(null)); assertFalse(a1.equals("Some non-DateAxis object")); a1 = new DateAxis("Test", TimeZone.getTimeZone("PST"), Locale.US); assertFalse(a1.equals(a2)); a2 = new DateAxis("Test", TimeZone.getTimeZone("PST"), Locale.US); assertTrue(a1.equals(a2)); a1 = new DateAxis("Test", TimeZone.getTimeZone("PST"), Locale.FRANCE); assertFalse(a1.equals(a2)); a2 = new DateAxis("Test", TimeZone.getTimeZone("PST"), Locale.FRANCE); assertTrue(a1.equals(a2)); // tickUnit a1.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7)); assertFalse(a1.equals(a2)); a2.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7)); assertTrue(a1.equals(a2)); // dateFormatOverride a1.setDateFormatOverride(new SimpleDateFormat("yyyy")); assertFalse(a1.equals(a2)); a2.setDateFormatOverride(new SimpleDateFormat("yyyy")); assertTrue(a1.equals(a2)); // tickMarkPosition a1.setTickMarkPosition(DateTickMarkPosition.END); assertFalse(a1.equals(a2)); a2.setTickMarkPosition(DateTickMarkPosition.END); assertTrue(a1.equals(a2)); // timeline a1.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); assertFalse(a1.equals(a2)); a2.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); assertTrue(a1.equals(a2)); }
/** A test to reproduce bug 2201869. */ @Test public void testBug2201869() { TimeZone tz = TimeZone.getTimeZone("GMT"); GregorianCalendar c = new GregorianCalendar(tz, Locale.UK); DateAxis axis = new DateAxis("Date", tz, Locale.UK); SimpleDateFormat sdf = new SimpleDateFormat("d-MMM-yyyy", Locale.UK); sdf.setCalendar(c); axis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1, sdf)); Day d1 = new Day(1, 3, 2008); d1.peg(c); Day d2 = new Day(30, 6, 2008); d2.peg(c); axis.setRange(d1.getStart(), d2.getEnd()); BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, 200, 100); axis.setTickMarkPosition(DateTickMarkPosition.END); List ticks = axis.refreshTicks(g2, new AxisState(), area, RectangleEdge.BOTTOM); assertEquals(3, ticks.size()); DateTick t1 = (DateTick) ticks.get(0); assertEquals("31-Mar-2008", t1.getText()); DateTick t2 = (DateTick) ticks.get(1); assertEquals("30-Apr-2008", t2.getText()); DateTick t3 = (DateTick) ticks.get(2); assertEquals("31-May-2008", t3.getText()); // now repeat for a vertical axis ticks = axis.refreshTicks(g2, new AxisState(), area, RectangleEdge.LEFT); assertEquals(3, ticks.size()); t1 = (DateTick) ticks.get(0); assertEquals("31-Mar-2008", t1.getText()); t2 = (DateTick) ticks.get(1); assertEquals("30-Apr-2008", t2.getText()); t3 = (DateTick) ticks.get(2); assertEquals("31-May-2008", t3.getText()); }