List of usage examples for org.jfree.chart.axis SegmentedTimeline newMondayThroughFridayTimeline
public static SegmentedTimeline newMondayThroughFridayTimeline()
From source file:com.charts.IntradayChart.java
public IntradayChart(YStockQuote currentStock) { TimeSeries series = new TimeSeries(currentStock.get_name()); ArrayList<String> fiveDayData = currentStock.get_one_day_data(); int length = fiveDayData.size(); for (int i = 17; i < length; i++) { String[] data = fiveDayData.get(i).split(","); Date time = new Date((long) Integer.parseInt(data[0]) * 1000); DateFormat df = new SimpleDateFormat("MM-dd-yyyy-h-m"); series.addOrUpdate(new Minute(time), Double.parseDouble(data[1])); }/* w ww . ja v a2 s .co m*/ TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createTimeSeriesChart( currentStock.get_name() + "(" + currentStock.get_symbol() + ")" + " Intraday", "Date", "Price", dataset, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); xAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); xAxis.setDateFormatOverride(new SimpleDateFormat("h:m a")); xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //xAxis.setVerticalTickLabels(true); chartPanel = new ChartPanel(chart); chart.setBackgroundPaint(chartPanel.getBackground()); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); chartPanel.setVisible(true); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:com.charts.ThreeMonthChart.java
public ThreeMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);/* w w w.ja v a 2 s .co m*/ rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y")); xAxis.setAutoTickUnitSelection(true); xAxis.setAutoRange(true); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:com.charts.SixMonthChart.java
public SixMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);/* ww w. java 2 s .c o m*/ rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y")); xAxis.setAutoTickUnitSelection(true); xAxis.setAutoRange(true); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:com.charts.OneMonthChart.java
public OneMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);/* w w w. j a v a 2 s .co m*/ rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setVerticalTickLabels(true); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM-dd")); xAxis.setAutoTickUnitSelection(false); xAxis.setAutoRange(false); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
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./*from w w w .ja v a2s . c o 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.sunzoft.sunstock.StockMain.java
protected JFreeChart createChart() { // 2Chart[??] XYDataset dataset = initChartData(); JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataset); XYPlot xyplot = (XYPlot) chart.getPlot(); //addIndexChart(xyplot); ChartUtils.setAntiAlias(chart);// ChartUtils.setTimeSeriesStyle(xyplot, false, true); ChartUtils.setLegendEmptyBorder(chart); // X??/* w w w.j av a2 s .c o m*/ DateAxis domainAxis = (DateAxis) xyplot.getDomainAxis(); domainAxis.setAutoTickUnitSelection(false); domainAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); DateTickUnit dateTickUnit; if (dataset.getItemCount(0) < 30) dateTickUnit = new DateTickUnit(DateTickUnitType.DAY, 5, new SimpleDateFormat("yyyy-MM-dd")); // ?? else if (dataset.getItemCount(0) < 100) dateTickUnit = new DateTickUnit(DateTickUnitType.DAY, 10, new SimpleDateFormat("yyyy-MM-dd")); // ?? else if (dataset.getItemCount(0) < 200) dateTickUnit = new DateTickUnit(DateTickUnitType.MONTH, 1, new SimpleDateFormat("yyyy/MM")); // ?? else if (dataset.getItemCount(0) < 500) dateTickUnit = new DateTickUnit(DateTickUnitType.MONTH, 3, new SimpleDateFormat("yyyy/MM")); // ?? else if (dataset.getItemCount(0) < 1000) dateTickUnit = new DateTickUnit(DateTickUnitType.MONTH, 6, new SimpleDateFormat("yyyy/MM")); // ?? else dateTickUnit = new DateTickUnit(DateTickUnitType.YEAR, 1, new SimpleDateFormat("yyyy")); // ?? // ?? domainAxis.setTickUnit(dateTickUnit); return chart; }
From source file:ch.agent.crnickl.demo.stox.Chart.java
private JFreeChart makeChart() throws KeyedException { if (chartSeries.size() == 0) throw new IllegalStateException("addChartSeries() not called"); if (range == null) { for (ChartSeries s : chartSeries) { if (range == null) range = s.getTimeSeries().getRange(); else// w w w .j a va 2 s.c om range = range.union(s.getTimeSeries().getRange()); } } // use number axis for dates, with special formatter DateAxis dateAxis = new DateAxis(); dateAxis.setDateFormatOverride(new CustomDateFormat("M/d/y")); if (range.getTimeDomain().getLabel().equals("workweek")) dateAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); // combined plot with shared date axis CombinedDomainXYPlot plot = new CombinedDomainXYPlot(dateAxis); for (ChartSeries s : chartSeries) { makeSubPlot(plot, s); } // make the chart, remove the legend, set the title JFreeChart chart = new JFreeChart(plot); if (!withLegend) chart.removeLegend(); chart.setBackgroundPaint(Color.white); chart.setTitle(new TextTitle(title)); return chart; }
From source file:org.activequant.util.charting.Chart.java
/** * helper method to indicate a monday to friday timeline. *///from w w w . j a va2 s . com public void setSuppressWeekends() { SegmentedTimeline timeline = SegmentedTimeline.newMondayThroughFridayTimeline(); final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis(); axis.setAutoRange(true); axis.setTimeline(timeline); }
From source file:ch.algotrader.client.chart.ChartTab.java
private void initAxis() { DateAxis domainAxis = (DateAxis) getPlot().getDomainAxis(); // configure the Date Axis (if startTime & endTime is set) if (this.chartDefinition.getStartTime() != null && this.chartDefinition.getEndTime() != null && !this.chartDefinition.getStartTime().equals(this.chartDefinition.getEndTime())) { // creat the SegmentedTimeline long startTime = this.chartDefinition.getStartTime().getTime(); long endTime = this.chartDefinition.getEndTime().getTime(); if (endTime == -3600000) { // adjust 00:00 endTime += 86400000;//from www. j ava2 s. c om } long segmentSize = 60 * 1000; // minute int segmentsIncluded = (int) (endTime - startTime) / (60 * 1000); int segmentsExcluded = 24 * 60 - segmentsIncluded; SegmentedTimeline timeline = new SegmentedTimeline(segmentSize, segmentsIncluded, segmentsExcluded); Date fromDate = domainAxis.getMinimumDate(); Date toDate = domainAxis.getMaximumDate(); long fromTime = fromDate.getTime(); long toTime = toDate.getTime(); // get year/month/day from fromTime and hour/minute from diagrm.startTime Date truncatedDate = DateUtils.truncate(fromDate, Calendar.DAY_OF_MONTH); Calendar truncatedCalendar = DateUtils.toCalendar(truncatedDate); Calendar startCalendar = DateUtils.toCalendar(this.chartDefinition.getStartTime()); truncatedCalendar.set(Calendar.HOUR_OF_DAY, startCalendar.get(Calendar.HOUR_OF_DAY)); truncatedCalendar.set(Calendar.MINUTE, startCalendar.get(Calendar.MINUTE)); timeline.setStartTime(truncatedCalendar.getTimeInMillis()); timeline.setBaseTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); timeline.addBaseTimelineExclusions(fromTime, toTime); timeline.setAdjustForDaylightSaving(true); domainAxis.setTimeline(timeline); } // make sure the markers are within the rangeAxis ValueAxis rangeAxis = getPlot().getRangeAxis(); for (Marker marker : this.markers.values()) { if (marker instanceof ValueMarker) { ValueMarker valueMarker = (ValueMarker) marker; if (marker.getAlpha() > 0 && valueMarker.getValue() != 0.0) { if (valueMarker.getValue() < rangeAxis.getLowerBound()) { rangeAxis.setLowerBound(valueMarker.getValue()); marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); } if (valueMarker.getValue() > rangeAxis.getUpperBound()) { rangeAxis.setUpperBound(valueMarker.getValue()); marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); } } } else { IntervalMarker intervalMarker = (IntervalMarker) marker; if (marker.getAlpha() > 0 && intervalMarker.getStartValue() != 0.0) { if (intervalMarker.getStartValue() < rangeAxis.getLowerBound()) { rangeAxis.setLowerBound(intervalMarker.getStartValue()); marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); } if (intervalMarker.getEndValue() > rangeAxis.getUpperBound()) { rangeAxis.setUpperBound(intervalMarker.getEndValue()); marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); } } } } }