public JPanel createChart( Date from, Date to, StockInfo stock1, StockInfo stock2, Color color1, Color color2, StockPriceType priceType) { LOG.info( "Generating chart for tickers:" + stock1.getTickerSymbol() + " & " + stock2.getTickerSymbol()); String chartTitle = df.format(from) + " to " + df.format(to) + " " + priceType; XYDataset dataset1 = createDataset(stock1, priceType); XYDataset dataset2 = createDataset(stock2, priceType); JFreeChart chart = ChartFactory.createTimeSeriesChart( chartTitle, DOMAIN_AXIS_TITLE, stock1.getTickerSymbol() + RANGE_AXIS_SUFFIX, dataset1, true, true, false); XYPlot plot = chart.getXYPlot(); NumberAxis axis2 = new NumberAxis(stock2.getTickerSymbol() + RANGE_AXIS_SUFFIX); Font tickLabelFont = axis2.getTickLabelFont().deriveFont(11.0F); Font labelFont = axis2.getLabelFont().deriveFont(15.0F).deriveFont(Font.BOLD); axis2.setTickLabelFont(tickLabelFont); axis2.setLabelFont(labelFont); axis2.setAutoRangeIncludesZero(false); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); StandardXYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, color1); renderer.setBaseShapesVisible(true); renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); plot.setRenderer(renderer); StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, color2); renderer2.setBaseShapesVisible(true); renderer2.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); plot.setRenderer(1, renderer2); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(df); ChartPanel chartPanel = new ChartPanel(chart); return chartPanel; }
/** * Updates the plot properties to match the properties defined on the panel. * * @param plot The plot. */ public void updatePlotProperties(Plot plot) { // set the plot properties... plot.setOutlinePaint(getOutlinePaint()); plot.setOutlineStroke(getOutlineStroke()); plot.setBackgroundPaint(getBackgroundPaint()); plot.setInsets(getPlotInsets()); // then the axis properties... if (this.domainAxisPropertyPanel != null) { Axis domainAxis = null; if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; domainAxis = p.getDomainAxis(); } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; domainAxis = p.getDomainAxis(); } if (domainAxis != null) { this.domainAxisPropertyPanel.setAxisProperties(domainAxis); } } if (this.rangeAxisPropertyPanel != null) { Axis rangeAxis = null; if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; rangeAxis = p.getRangeAxis(); } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; rangeAxis = p.getRangeAxis(); } else if (plot instanceof PolarPlot) { PolarPlot p = (PolarPlot) plot; rangeAxis = p.getAxis(); } if (rangeAxis != null) { this.rangeAxisPropertyPanel.setAxisProperties(rangeAxis); } } if (this.plotOrientation != null) { if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; p.setOrientation(this.plotOrientation); } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; p.setOrientation(this.plotOrientation); } } if (this.drawLines != null) { if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; CategoryItemRenderer r = p.getRenderer(); if (r instanceof LineAndShapeRenderer) { ((LineAndShapeRenderer) r).setLinesVisible(this.drawLines.booleanValue()); } } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; XYItemRenderer r = p.getRenderer(); if (r instanceof StandardXYItemRenderer) { ((StandardXYItemRenderer) r).setPlotLines(this.drawLines.booleanValue()); } } } if (this.drawShapes != null) { if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; CategoryItemRenderer r = p.getRenderer(); if (r instanceof LineAndShapeRenderer) { ((LineAndShapeRenderer) r).setShapesVisible(this.drawShapes.booleanValue()); } } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; XYItemRenderer r = p.getRenderer(); if (r instanceof StandardXYItemRenderer) { ((StandardXYItemRenderer) r).setBaseShapesVisible(this.drawShapes.booleanValue()); } } } // dmo: added this panel for colorbar control. (start dmo additions) if (this.colorBarAxisPropertyPanel != null) { ColorBar colorBar = null; if (plot instanceof ContourPlot) { ContourPlot p = (ContourPlot) plot; colorBar = p.getColorBar(); } if (colorBar != null) { this.colorBarAxisPropertyPanel.setAxisProperties(colorBar); } } // dmo: (end dmo additions) }