List of usage examples for org.jfree.chart JFreeChart getSubtitle
public Title getSubtitle(int index)
From source file:org.eobjects.datacleaner.util.ChartUtils.java
public static void applyStyles(JFreeChart chart) { TextTitle title = chart.getTitle();// w w w . j a v a2 s. c o m if (title != null) { title.setFont(WidgetUtils.FONT_HEADER1); title.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST); } for (int i = 0; i < chart.getSubtitleCount(); i++) { Title subtitle = chart.getSubtitle(i); if (subtitle instanceof TextTitle) { ((TextTitle) subtitle).setFont(WidgetUtils.FONT_NORMAL); } } LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setItemFont(WidgetUtils.FONT_SMALL); } // transparent background chart.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST); chart.setBorderVisible(false); final Plot plot = chart.getPlot(); plot.setInsets(new RectangleInsets(UnitType.ABSOLUTE, 0d, 0d, 0d, 0d)); plot.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST); plot.setOutlinePaint(WidgetUtils.BG_COLOR_BRIGHTEST); plot.setOutlineVisible(true); if (plot instanceof PiePlot) { // tweaks for pie charts final PiePlot piePlot = (PiePlot) plot; piePlot.setBaseSectionOutlinePaint(WidgetUtils.BG_COLOR_DARK); piePlot.setBaseSectionOutlineStroke(normalStroke); piePlot.setLabelFont(WidgetUtils.FONT_SMALL); piePlot.setLabelBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHT); piePlot.setLabelOutlineStroke(normalStroke); piePlot.setLabelPaint(WidgetUtils.BG_COLOR_DARK); piePlot.setSectionOutlinesVisible(false); piePlot.setLabelLinkStyle(PieLabelLinkStyle.QUAD_CURVE); } else if (plot instanceof CategoryPlot) { // tweaks for bar charts final CategoryPlot categoryPlot = (CategoryPlot) plot; int columnCount = categoryPlot.getDataset().getColumnCount(); if (columnCount > 1) { categoryPlot.setDomainGridlinesVisible(true); } else { categoryPlot.setDomainGridlinesVisible(false); } categoryPlot.setDomainGridlinePaint(WidgetUtils.BG_COLOR_DARK); categoryPlot.setDomainGridlinePosition(CategoryAnchor.END); categoryPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL); categoryPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL); categoryPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL); categoryPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL); categoryPlot.setDrawingSupplier(new DCDrawingSupplier()); final CategoryItemRenderer renderer = categoryPlot.getRenderer(); renderer.setBaseOutlinePaint(WidgetUtils.BG_COLOR_DARK); renderer.setBaseOutlineStroke(wideStroke); if (renderer instanceof BarRenderer) { BarRenderer barRenderer = (BarRenderer) renderer; barRenderer.setShadowPaint(WidgetUtils.BG_COLOR_BRIGHT); barRenderer.setBarPainter(new StandardBarPainter()); } } else if (plot instanceof XYPlot) { // tweaks for line charts final XYPlot xyPlot = (XYPlot) plot; xyPlot.setDrawingSupplier(new DCDrawingSupplier()); xyPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL); xyPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL); xyPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL); xyPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL); final XYItemRenderer renderer = xyPlot.getRenderer(); final int seriesCount = xyPlot.getSeriesCount(); for (int i = 0; i < seriesCount; i++) { renderer.setSeriesStroke(i, wideStroke); } } }
From source file:org.fhcrc.cpl.viewer.gui.SpectrumChartFactory.java
public static ChartPanel CreateChartPanel(XYDataset dataset, Color[] colors) { XYPlot xy = createXYPlot(dataset, colors); JFreeChart chart = new JFreeChart(xy); ChartPanel chartPanel = new SpectrumChartPanel(chart); chartPanel.setDisplayToolTips(true); chartPanel.setMouseZoomable(true);// w w w . j a v a 2 s.c o m // Remove the autogenerated subtitle if (chart.getSubtitleCount() == 1) chart.removeSubtitle(chart.getSubtitle(chart.getSubtitleCount() - 1)); return chartPanel; }
From source file:org.fhcrc.cpl.viewer.gui.SpectrumChartFactory.java
public static ChartPanel CreateChartPanel(java.util.List datasets, Color[] colors) { if (datasets.size() == 1) return CreateChartPanel((XYSeriesCollection) datasets.get(0), colors); CombinedDomainXYPlot combined = new CombinedDomainXYPlot(); for (Iterator it = datasets.iterator(); it.hasNext();) { XYSeriesCollection series = (XYSeriesCollection) it.next(); XYPlot xy = createXYPlot(series, colors); combined.add(xy);//from ww w. j av a2 s . com } NumberAxis axisDomain = new NumberAxis(); axisDomain.setAutoRangeIncludesZero(false); // axisDomain.setRange(400.0, 1600.0); combined.setDomainAxis(axisDomain); JFreeChart chart = new JFreeChart(combined); ChartPanel chartPanel = new SpectrumChartPanel(chart); chartPanel.setDisplayToolTips(true); chartPanel.setMouseZoomable(true); // Remove the autogenerated subtitle if (chart.getSubtitleCount() == 1) chart.removeSubtitle(chart.getSubtitle(chart.getSubtitleCount() - 1)); return chartPanel; }
From source file:org.datacleaner.util.ChartUtils.java
public static void applyStyles(JFreeChart chart) { TextTitle title = chart.getTitle();//from w w w .ja v a 2s . c o m if (title != null) { title.setFont(WidgetUtils.FONT_HEADER1); title.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST); } for (int i = 0; i < chart.getSubtitleCount(); i++) { Title subtitle = chart.getSubtitle(i); if (subtitle instanceof TextTitle) { ((TextTitle) subtitle).setFont(WidgetUtils.FONT_NORMAL); } } LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setItemFont(WidgetUtils.FONT_SMALL); } // transparent background chart.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST); chart.setBorderVisible(false); final Plot plot = chart.getPlot(); plot.setInsets(new RectangleInsets(UnitType.ABSOLUTE, 0d, 0d, 0d, 0d)); plot.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST); plot.setOutlinePaint(WidgetUtils.BG_COLOR_BRIGHTEST); plot.setOutlineVisible(true); if (plot instanceof PiePlot) { // tweaks for pie charts final PiePlot piePlot = (PiePlot) plot; piePlot.setBaseSectionOutlinePaint(WidgetUtils.BG_COLOR_DARK); piePlot.setBaseSectionOutlineStroke(STROKE_NORMAL); piePlot.setLabelFont(WidgetUtils.FONT_SMALL); piePlot.setLabelBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHT); piePlot.setLabelOutlineStroke(STROKE_NORMAL); piePlot.setLabelPaint(WidgetUtils.BG_COLOR_DARK); piePlot.setSectionOutlinesVisible(false); piePlot.setLabelLinkStyle(PieLabelLinkStyle.QUAD_CURVE); piePlot.setDrawingSupplier(new DCDrawingSupplier()); } else if (plot instanceof CategoryPlot) { // tweaks for bar charts final CategoryPlot categoryPlot = (CategoryPlot) plot; int columnCount = categoryPlot.getDataset().getColumnCount(); if (columnCount > 1) { categoryPlot.setDomainGridlinesVisible(true); } else { categoryPlot.setDomainGridlinesVisible(false); } categoryPlot.setDomainGridlinePaint(WidgetUtils.BG_COLOR_DARK); categoryPlot.setDomainGridlinePosition(CategoryAnchor.END); categoryPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL); categoryPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL); categoryPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL); categoryPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL); categoryPlot.setDrawingSupplier(new DCDrawingSupplier()); final CategoryItemRenderer renderer = categoryPlot.getRenderer(); renderer.setBaseOutlinePaint(WidgetUtils.BG_COLOR_DARK); renderer.setBaseOutlineStroke(STROKE_WIDE); if (renderer instanceof BarRenderer) { BarRenderer barRenderer = (BarRenderer) renderer; barRenderer.setShadowPaint(WidgetUtils.BG_COLOR_BRIGHT); barRenderer.setBarPainter(new StandardBarPainter()); } } else if (plot instanceof XYPlot) { // tweaks for line charts final XYPlot xyPlot = (XYPlot) plot; xyPlot.setDrawingSupplier(new DCDrawingSupplier()); xyPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL); xyPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL); xyPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL); xyPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL); final XYItemRenderer renderer = xyPlot.getRenderer(); final int seriesCount = xyPlot.getSeriesCount(); for (int i = 0; i < seriesCount; i++) { renderer.setSeriesStroke(i, STROKE_WIDE); } } }
From source file:org.gumtree.vis.awt.PlotFactory.java
public static Hist2DPanel createHist2DPanel(IXYZDataset dataset) { JFreeChart chart = createXYBlockChart(dataset); Hist2DPanel panel = new Hist2DPanel(chart); panel.setHorizontalAxisTrace(true);/* w w w .j a v a 2 s.c o m*/ panel.setVerticalAxisTrace(true); panel.setDoubleBuffered(true); panel.setFillZoomRectangle(true); panel.setZoomAroundAnchor(true); panel.setZoomInFactor(StaticValues.defaultZoomInFactor); panel.setZoomOutFactor(StaticValues.defaultZoomOutFactor); panel.addMouseListener((PaintScaleLegend2D) chart.getSubtitle(0)); panel.addMouseMotionListener((PaintScaleLegend2D) chart.getSubtitle(0)); dataset.addChangeListener(panel); return panel; }
From source file:net.sf.mzmine.chartbasics.graphicsexport.ChartExportUtil.java
/** * This method is used to save all image formats. it uses the specific methods for each file * format/*from w w w . j a v a 2 s .co m*/ * * @param chart * @param sett * @param chartRenderingInfo */ private static void writeChartToImage(JFreeChart chart, GraphicsExportParameters sett, ChartRenderingInfo info) throws Exception { // Background color Paint saved = chart.getBackgroundPaint(); chart.setBackgroundPaint(sett.getColorWithAlpha()); chart.setBackgroundImageAlpha((float) sett.getTransparency()); if (chart.getLegend() != null) chart.getLegend().setBackgroundPaint(sett.getColorWithAlpha()); // legends and stuff for (int i = 0; i < chart.getSubtitleCount(); i++) if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass())) ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(sett.getColorWithAlpha()); // apply bg chart.getPlot().setBackgroundPaint(sett.getColorWithAlpha()); // create folder File f = sett.getFullpath(); if (!f.exists()) { if (f.getParentFile() != null) f.getParentFile().mkdirs(); // f.createNewFile(); } Dimension size = sett.getPixelSize(); // Format switch (sett.getFormat()) { case "PDF": writeChartToPDF(chart, size.width, size.height, f); break; case "PNG": writeChartToPNG(chart, info, size.width, size.height, f, (int) sett.getDPI()); break; case "JPG": writeChartToJPEG(chart, info, size.width, size.height, f, (int) sett.getDPI()); break; case "EPS": writeChartToEPS(chart, size.width, size.height, f); break; case "SVG": writeChartToSVG(chart, size.width, size.height, f); break; case "EMF": writeChartToEMF(chart, size.width, size.height, f); break; } // chart.setBackgroundPaint(saved); chart.setBackgroundImageAlpha(255); if (chart.getLegend() != null) chart.getLegend().setBackgroundPaint(saved); // legends and stuff for (int i = 0; i < chart.getSubtitleCount(); i++) if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass())) ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(saved); // apply bg chart.getPlot().setBackgroundPaint(saved); }
From source file:net.sf.mzmine.chartbasics.graphicsexport.ChartExportUtil.java
public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width, int height, File fileName, int resolution) throws IOException { // Background color Paint saved = chart.getBackgroundPaint(); if (((Color) saved).getAlpha() == 0) { chart.setBackgroundPaint(Color.WHITE); chart.setBackgroundImageAlpha(255); if (chart.getLegend() != null) chart.getLegend().setBackgroundPaint(Color.WHITE); // legends and stuff for (int i = 0; i < chart.getSubtitleCount(); i++) if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass())) ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE); // apply bg chart.getPlot().setBackgroundPaint(Color.WHITE); }/* w w w . j ava 2s . c o m*/ // if (resolution == 72) writeChartToJPEG(chart, width, height, fileName); else { OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName)); try { BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height, resolution, BufferedImage.TYPE_INT_RGB); EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f); } finally { out.close(); } } }
From source file:org.apache.qpid.disttest.charting.chartbuilder.ChartProductionTest.java
private void assertChartTitlesAndWriteToFile(ChartBuilder builder) { JFreeChart chart = builder.buildChart(_chartingDefinition); assertEquals(TEST_CHARTTITLE, chart.getTitle().getText()); assertEquals(TEST_CHARTSUBTITLE, ((ShortTextTitle) chart.getSubtitle(1)).getText()); assertEquals(TEST_SERIESLEGEND, chart.getPlot().getLegendItems().get(0).getLabel()); if (chart.getPlot() instanceof XYPlot) { assertEquals(1, chart.getXYPlot().getDatasetCount()); } else {//from w w w . j a v a2 s.c o m assertEquals(1, chart.getCategoryPlot().getDatasetCount()); } _writer.writeChartToFileSystem(chart, _chartingDefinition); }
From source file:org.yccheok.jstock.gui.charting.DynamicChart.java
/** Creates new form DynamicChart */ public DynamicChart() { this.price = new TimeSeries("Price"); // Sets the maximumItemAge attribute, which specifies the maximum age of data items in the series // (in terms of the RegularTimePeriod type used by this series). Whenever a new data value is // added, any data items that are older than the limit specified by maximumItemAge are automatically // discarded/*from w ww. j a va 2 s.c om*/ // Maximum 2 hours. this.price.setMaximumItemAge(2 * 60 * 60); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(this.price); JFreeChart freeChart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, true, false); freeChart.setAntiAlias(true); while (freeChart.getSubtitleCount() > 0) { freeChart.removeSubtitle(freeChart.getSubtitle(0)); } // Due to limited spacing, we remove all information regarding x and y axis // as well. XYPlot plot = freeChart.getXYPlot(); plot.getRangeAxis().setVisible(false); plot.getDomainAxis().setVisible(false); XYItemRenderer renderer1 = plot.getRenderer(); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("h:mm:ss a"), new DecimalFormat("0.00#"))); org.yccheok.jstock.charting.Utils.applyChartTheme(freeChart); // Disable zoom. chartPanel = new ChartPanel(freeChart, true, true, true, false, true); chartPanel.setMouseZoomable(false); }
From source file:org.apache.qpid.disttest.charting.chartbuilder.BaseChartBuilderTest.java
public void testBuildChart() { BaseChartBuilder chartBuilder = new ChartBuilder(_seriesBuilder, _strokeAndPaintApplier, _datasetHolder) { @Override/*from w w w . j a v a 2 s .co m*/ protected JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) { assertEquals(CHART_TITLE, title); assertEquals(X_TITLE, xAxisTitle); assertEquals(Y_TITLE, yAxisTitle); return _jFreeChart; } }; JFreeChart chart = chartBuilder.buildChart(_chartingDefinition); assertEquals(BaseChartBuilder.BLUE_GRADIENT, chart.getBackgroundPaint()); assertEquals("The *second* subtitle of the generated chart should have the text from the chart definition", CHART_SUB_TITLE, ((TextTitle) chart.getSubtitle(1)).getText()); verify(_seriesPainter).applySeriesAppearance(_jFreeChart, _seriesDefinitions, _strokeAndPaintApplier); }