List of usage examples for org.jfree.chart.axis DateTickUnit DateTickUnit
public DateTickUnit(int unit, int count, int rollUnit, int rollCount, DateFormat formatter)
From source file:org.jfree.chart.demo.SegmentedHighLowChartDemo.java
/** * A demonstration application showing a high-low-open-close chart using a * segmented or non-segmented axis./*ww w. j av a 2 s. co m*/ * * @param title the frame title. * @param useSegmentedAxis use a segmented axis for this demo? * @param timelineType Type of timeline to use: 1=Monday through Friday, 2=Intraday */ public SegmentedHighLowChartDemo(final String title, final boolean useSegmentedAxis, final int timelineType) { super(title); System.out.println("\nMaking SegmentedHighLowChartDemo(" + title + ")"); // create a Calendar object with today's date at midnight final Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); // create a timeline for the demo SegmentedTimeline timeline = null; switch (timelineType) { case 1: timeline = SegmentedTimeline.newMondayThroughFridayTimeline(); break; case 2: timeline = SegmentedTimeline.newFifteenMinuteTimeline(); final Calendar cal2 = (Calendar) cal.clone(); cal2.add(Calendar.YEAR, 1); // add 1 year of baseTimeline's excluded segments (Saturdays and Sundays) as // exceptions of the intraday timeline timeline.addBaseTimelineExclusions(cal.getTime().getTime(), cal2.getTime().getTime()); break; default: System.out.println("Invalid timelineType."); System.exit(1); } // create a data set that has data for trading days (Monday through Friday). final DefaultHighLowDataset dataset = DemoDatasetFactory.createSegmentedHighLowDataset(timeline, cal.getTime()); final JFreeChart chart; if (useSegmentedAxis) { chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, timeline, true); } else { chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, true); } final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis(); axis.setAutoRange(true); final TickUnits units = new TickUnits(); units.add(new DateTickUnit(DateTickUnit.DAY, 1, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM"))); units.add(new DateTickUnit(DateTickUnit.DAY, 2, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM"))); units.add(new DateTickUnit(DateTickUnit.DAY, 7, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM"))); units.add(new DateTickUnit(DateTickUnit.DAY, 15, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM"))); units.add(new DateTickUnit(DateTickUnit.DAY, 30, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM"))); axis.setStandardTickUnits(units); final NumberAxis vaxis = (NumberAxis) chart.getXYPlot().getRangeAxis(); vaxis.setAutoRangeIncludesZero(false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.XYDrawableAnnotationDemo1.java
private static TickUnitSource createStandardDateTickUnits() { TickUnits tickunits = new TickUnits(); SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy"); tickunits.add(new DateTickUnit(DateTickUnitType.YEAR, 1, DateTickUnitType.YEAR, 1, simpledateformat)); tickunits.add(new DateTickUnit(DateTickUnitType.YEAR, 2, DateTickUnitType.YEAR, 1, simpledateformat)); tickunits.add(new DateTickUnit(DateTickUnitType.YEAR, 5, DateTickUnitType.YEAR, 5, simpledateformat)); return tickunits; }
From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java
private static TickUnitSource createStandardDateTickUnits() { TickUnits units = new TickUnits(); DateFormat df = new SimpleDateFormat("yyyy"); units.add(new DateTickUnit(DateTickUnitType.YEAR, 1, DateTickUnitType.YEAR, 1, df)); units.add(new DateTickUnit(DateTickUnitType.YEAR, 2, DateTickUnitType.YEAR, 1, df)); units.add(new DateTickUnit(DateTickUnitType.YEAR, 5, DateTickUnitType.YEAR, 5, df)); return units; }
From source file:OAT.ui.util.UiUtil.java
public static TickUnits createSimpleTimeTickUnits() { TickUnits tickUnits = new TickUnits(); SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm"); SimpleDateFormat weekDayFormatter = new SimpleDateFormat("EEE"); SimpleDateFormat dayFormatter = new SimpleDateFormat("dd-mm"); SimpleDateFormat monthFormatter = new SimpleDateFormat("MMM-yy"); SimpleDateFormat yearFormatter = new SimpleDateFormat("yyyy"); //tickUnits.add(new DateTickUnit(DateTickUnitType.MINUTE, 30, DateTickUnitType.SECOND, 1, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 1, DateTickUnitType.SECOND, 1, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 2, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 4, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 6, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 12, timeFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 1, DateTickUnitType.HOUR, 1, weekDayFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 2, weekDayFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 7, dayFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 15, dayFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 1, DateTickUnitType.DAY, 1, monthFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 3, monthFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 6, monthFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 1, DateTickUnitType.MONTH, 1, yearFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 2, yearFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 5, yearFormatter)); tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 10, yearFormatter)); return tickUnits; }