List of usage examples for org.jfree.chart.axis NumberAxis setNumberFormatOverride
public void setNumberFormatOverride(NumberFormat formatter)
From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java
private void updateRSI(int days, boolean show) { if (this.priceVolumeChart == null) { this.priceVolumeChart = this.createPriceVolumeChart(this.priceDataset, this.volumeDataset); }// w ww . ja va 2s . c o m if (this.candlestickChart == null) { this.candlestickChart = this.createCandlestickChart(this.priceOHLCDataset); } final TAEx taEx = TAEx.newInstance(TA.RSI, new Integer(days)); if (show) { if (price_volume_ta_map.containsKey(taEx) == false) { final XYDataset dataset = org.yccheok.jstock.charting.TechnicalAnalysis.createRSI(this.chartDatas, getRSIKey(days), days); NumberAxis rangeAxis1 = new NumberAxis(GUIBundle.getString("ChartJDialog_RSI")); rangeAxis1.setAutoRangeIncludesZero(false); // override default rangeAxis1.setLowerMargin(0.40); // to leave room for volume bars DecimalFormat format = new DecimalFormat("0"); rangeAxis1.setNumberFormatOverride(format); final ValueAxis timeAxis = new DateAxis(GUIBundle.getString("ChartJDialog_Date")); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); XYPlot plot = new XYPlot(dataset, timeAxis, rangeAxis1, null); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00#"))); plot.setRenderer(0, renderer1); price_volume_ta_map.put(taEx, plot); } if (candlestick_ta_map.containsKey(taEx) == false) { try { /* Not sure why. I cannot make priceVolumeChart and candlestickChart sharing the same * plot. If not, this will inhibit incorrect zooming behavior. */ candlestick_ta_map.put(taEx, (XYPlot) price_volume_ta_map.get(taEx).clone()); } catch (CloneNotSupportedException ex) { log.error(null, ex); } } if (this.activeTAExs.contains(taEx) == false) { // Avoid duplication. final XYPlot price_volume_ta = price_volume_ta_map.get(taEx); final XYPlot candlestick_ta = candlestick_ta_map.get(taEx); final CombinedDomainXYPlot cplot0 = (CombinedDomainXYPlot) this.priceVolumeChart.getPlot(); final CombinedDomainXYPlot cplot1 = (CombinedDomainXYPlot) this.candlestickChart.getPlot(); if (price_volume_ta != null) cplot0.add(price_volume_ta, 1); // weight is 1. if (candlestick_ta != null) cplot1.add(candlestick_ta, 1); // weight is 1. org.yccheok.jstock.charting.Utils.applyChartThemeEx(this.priceVolumeChart); org.yccheok.jstock.charting.Utils.applyChartThemeEx(this.candlestickChart); } } else { final CombinedDomainXYPlot cplot0 = (CombinedDomainXYPlot) this.priceVolumeChart.getPlot(); final CombinedDomainXYPlot cplot1 = (CombinedDomainXYPlot) this.candlestickChart.getPlot(); final XYPlot price_volume_ta = price_volume_ta_map.get(taEx); final XYPlot candlestick_ta = candlestick_ta_map.get(taEx); if (price_volume_ta != null) cplot0.remove(price_volume_ta); if (candlestick_ta != null) cplot1.remove(candlestick_ta); } if (show && this.activeTAExs.contains(taEx) == false) { this.activeTAExs.add(taEx); JStock.instance().getChartJDialogOptions().add(taEx); } else if (!show) { this.activeTAExs.remove(taEx); JStock.instance().getChartJDialogOptions().remove(taEx); } }
From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java
private void updateCCI(int days, boolean show) { if (this.priceVolumeChart == null) { this.priceVolumeChart = this.createPriceVolumeChart(this.priceDataset, this.volumeDataset); }//from w ww. ja v a 2 s. c o m if (this.candlestickChart == null) { this.candlestickChart = this.createCandlestickChart(this.priceOHLCDataset); } final TAEx taEx = TAEx.newInstance(TA.CCI, new Integer(days)); if (show) { if (price_volume_ta_map.containsKey(taEx) == false) { final XYDataset dataset = org.yccheok.jstock.charting.TechnicalAnalysis.createCCI(this.chartDatas, getCCIKey(days), days); NumberAxis rangeAxis1 = new NumberAxis(GUIBundle.getString("ChartJDialog_CCI")); rangeAxis1.setAutoRangeIncludesZero(false); // override default rangeAxis1.setLowerMargin(0.40); // to leave room for volume bars DecimalFormat format = new DecimalFormat("0"); rangeAxis1.setNumberFormatOverride(format); final ValueAxis timeAxis = new DateAxis(GUIBundle.getString("ChartJDialog_Date")); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); XYPlot plot = new XYPlot(dataset, timeAxis, rangeAxis1, null); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00#"))); plot.setRenderer(0, renderer1); org.yccheok.jstock.charting.Utils.setPriceSeriesPaint(renderer1); price_volume_ta_map.put(taEx, plot); } if (candlestick_ta_map.containsKey(taEx) == false) { try { /* Not sure why. I cannot make priceVolumeChart and candlestickChart sharing the same * plot. If not, this will inhibit incorrect zooming behavior. */ candlestick_ta_map.put(taEx, (XYPlot) price_volume_ta_map.get(taEx).clone()); } catch (CloneNotSupportedException ex) { log.error(null, ex); } } if (this.activeTAExs.contains(taEx) == false) { // Avoid duplication. final XYPlot price_volume_ta = price_volume_ta_map.get(taEx); final XYPlot candlestick_ta = candlestick_ta_map.get(taEx); final CombinedDomainXYPlot cplot0 = (CombinedDomainXYPlot) this.priceVolumeChart.getPlot(); final CombinedDomainXYPlot cplot1 = (CombinedDomainXYPlot) this.candlestickChart.getPlot(); if (price_volume_ta != null) cplot0.add(price_volume_ta, 1); // weight is 1. if (candlestick_ta != null) cplot1.add(candlestick_ta, 1); // weight is 1. org.yccheok.jstock.charting.Utils.applyChartThemeEx(this.priceVolumeChart); org.yccheok.jstock.charting.Utils.applyChartThemeEx(this.candlestickChart); } } else { final CombinedDomainXYPlot cplot0 = (CombinedDomainXYPlot) this.priceVolumeChart.getPlot(); final CombinedDomainXYPlot cplot1 = (CombinedDomainXYPlot) this.candlestickChart.getPlot(); final XYPlot price_volume_ta = price_volume_ta_map.get(taEx); final XYPlot candlestick_ta = candlestick_ta_map.get(taEx); if (price_volume_ta != null) cplot0.remove(price_volume_ta); if (candlestick_ta != null) cplot1.remove(candlestick_ta); } if (show && this.activeTAExs.contains(taEx) == false) { this.activeTAExs.add(taEx); JStock.instance().getChartJDialogOptions().add(taEx); } else if (!show) { this.activeTAExs.remove(taEx); JStock.instance().getChartJDialogOptions().remove(taEx); } }
From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java
private void updateMACD(MACD.Period period, boolean show) { if (this.priceVolumeChart == null) { this.priceVolumeChart = this.createPriceVolumeChart(this.priceDataset, this.volumeDataset); }/*w ww . j av a2 s . com*/ if (this.candlestickChart == null) { this.candlestickChart = this.createCandlestickChart(this.priceOHLCDataset); } final TAEx taEx = TAEx.newInstance(TA.MACD, period); if (show) { if (price_volume_ta_map.containsKey(taEx) == false) { final MACD.ChartResult macdChartResult = org.yccheok.jstock.charting.TechnicalAnalysis .createMACD(this.chartDatas, getMACDKey(period), period); // MACD! NumberAxis rangeAxis1 = new NumberAxis(GUIBundle.getString("ChartJDialog_MACD")); rangeAxis1.setAutoRangeIncludesZero(false); // override default rangeAxis1.setLowerMargin(0.40); // to leave room for volume bars DecimalFormat format = new DecimalFormat("0.00#"); rangeAxis1.setNumberFormatOverride(format); final ValueAxis timeAxis = new DateAxis(GUIBundle.getString("ChartJDialog_Date")); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); XYPlot plot = new XYPlot(macdChartResult.outMACD, timeAxis, rangeAxis1, null); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00#"))); plot.setRenderer(0, renderer1); org.yccheok.jstock.charting.Utils.setPriceSeriesPaint(renderer1); // MACD SIGNAL! plot.setDataset(1, macdChartResult.outMACDSignal); XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00#"))); plot.setRenderer(1, renderer2); // VOLUME! //plot.setRangeAxis(1, rangeAxis1); plot.setDataset(2, macdChartResult.outMACDHist); //plot.mapDatasetToRangeAxis(1, 1); XYBarRenderer renderer3 = new XYBarRenderer(0.20); renderer3.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00"))); plot.setRenderer(2, renderer3); price_volume_ta_map.put(taEx, plot); } if (candlestick_ta_map.containsKey(taEx) == false) { try { /* Not sure why. I cannot make priceVolumeChart and candlestickChart sharing the same * plot. If not, this will inhibit incorrect zooming behavior. */ candlestick_ta_map.put(taEx, (XYPlot) price_volume_ta_map.get(taEx).clone()); } catch (CloneNotSupportedException ex) { log.error(null, ex); } } if (this.activeTAExs.contains(taEx) == false) { // Avoid duplication. final XYPlot price_volume_ta = price_volume_ta_map.get(taEx); final XYPlot candlestick_ta = candlestick_ta_map.get(taEx); final CombinedDomainXYPlot cplot0 = (CombinedDomainXYPlot) this.priceVolumeChart.getPlot(); final CombinedDomainXYPlot cplot1 = (CombinedDomainXYPlot) this.candlestickChart.getPlot(); if (price_volume_ta != null) cplot0.add(price_volume_ta, 1); // weight is 1. if (candlestick_ta != null) cplot1.add(candlestick_ta, 1); // weight is 1. org.yccheok.jstock.charting.Utils.applyChartThemeEx(this.priceVolumeChart); org.yccheok.jstock.charting.Utils.applyChartThemeEx(this.candlestickChart); } } else { final CombinedDomainXYPlot cplot0 = (CombinedDomainXYPlot) this.priceVolumeChart.getPlot(); final CombinedDomainXYPlot cplot1 = (CombinedDomainXYPlot) this.candlestickChart.getPlot(); final XYPlot price_volume_ta = price_volume_ta_map.get(taEx); final XYPlot candlestick_ta = candlestick_ta_map.get(taEx); if (price_volume_ta != null) cplot0.remove(price_volume_ta); if (candlestick_ta != null) cplot1.remove(candlestick_ta); } if (show && this.activeTAExs.contains(taEx) == false) { this.activeTAExs.add(taEx); JStock.instance().getChartJDialogOptions().add(taEx); } else if (!show) { this.activeTAExs.remove(taEx); JStock.instance().getChartJDialogOptions().remove(taEx); } }
From source file:gda.plots.SimplePlot.java
private void initAxis(NumberAxis axis, boolean autoRange, NumberFormat formatter) { axis.setAutoRange(autoRange);// ww w . j a va 2s. c o m axis.setLowerMargin(0.); axis.setUpperMargin(0.); axis.setAutoRangeIncludesZero(false); axis.setNumberFormatOverride(formatter); }