List of usage examples for org.jfree.chart JFreeChart getSubtitleCount
public int getSubtitleCount()
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 va 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.eobjects.datacleaner.util.ChartUtils.java
public static void applyStyles(JFreeChart chart) { TextTitle title = chart.getTitle();/*from www . jav a 2 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(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 w ww. j a va2s .c o m } 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 .j a 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: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 . ja 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 ww .j a v a 2s. co 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.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 ww w . j a v a2 s . co m*/ // 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.opennms.netmgt.charts.ChartUtilsTest.java
@Test public void testGetBarChart() throws MarshalException, ValidationException, IOException, SQLException { JFreeChart barChart = ChartUtils.getBarChart("sample-bar-chart"); assertNotNull(barChart);/*w w w. ja va 2s . c o m*/ //SubTitle count includes "LegendTitle" assertEquals(2, barChart.getSubtitleCount()); }
From source file:net.sf.mzmine.chartbasics.chartthemes.EStandardChartTheme.java
@Override public void apply(JFreeChart chart) { // TODO Auto-generated method stub super.apply(chart); ////from w w w . j ava2 s. com chart.getXYPlot().setDomainGridlinesVisible(showXGrid); chart.getXYPlot().setRangeGridlinesVisible(showYGrid); // all axes for (int i = 0; i < chart.getXYPlot().getDomainAxisCount(); i++) { NumberAxis a = (NumberAxis) chart.getXYPlot().getDomainAxis(i); a.setTickMarkPaint(axisLinePaint); a.setAxisLinePaint(axisLinePaint); // visible? a.setVisible(showXAxis); } for (int i = 0; i < chart.getXYPlot().getRangeAxisCount(); i++) { NumberAxis a = (NumberAxis) chart.getXYPlot().getRangeAxis(i); a.setTickMarkPaint(axisLinePaint); a.setAxisLinePaint(axisLinePaint); // visible? a.setVisible(showYAxis); } // apply bg chart.setBackgroundPaint(this.getChartBackgroundPaint()); chart.getPlot().setBackgroundPaint(this.getPlotBackgroundPaint()); for (int i = 0; i < chart.getSubtitleCount(); i++) { // visible? chart.getSubtitle(i).setVisible(subtitleVisible); // if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass())) ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(this.getChartBackgroundPaint()); } if (chart.getLegend() != null) chart.getLegend().setBackgroundPaint(this.getChartBackgroundPaint()); // chart.setAntiAlias(isAntiAliased()); chart.getTitle().setVisible(isShowTitle()); chart.getPlot().setBackgroundAlpha(isNoBackground() ? 0 : 1); }
From source file:org.jfree.eastwood.ChartEngine.java
/** * Creates and returns a new <code>JFreeChart</code> instance that * reflects the specified parameters (which should be equivalent to * a parameter map returned by HttpServletRequest.getParameterMap() for * a valid URI for the Google Chart API. * * @param params the parameters (<code>null</code> not permitted). * @param font the font to use to draw titles, labels and legends. * * @return A chart corresponding to the specification in the supplied * parameters.// w ww .j a va 2s.co m */ public static JFreeChart buildChart(Map params, Font font) { if (params == null) { throw new IllegalArgumentException("Null 'params' argument."); } JFreeChart chart = null; // *** CHART TYPE ** String[] chartType = (String[]) params.get("cht"); int dataType = -1; // 0 = PieDataset; 1 = XYDataset; 2 = special // pie charts: 'p' and 'p3' if (chartType[0].equals("p")) { chart = createPieChart(); dataType = 0; } else if (chartType[0].equals("p3")) { chart = createPieChart3D(); dataType = 0; } // line chart: 'lc' else if (chartType[0].equals("lc")) { chart = createLineChart(); dataType = 1; } // sparkline: 'ls' else if (chartType[0].equals("ls")) { chart = createSparklineChart(); dataType = 1; } // xy chart: 'lxy' else if (chartType[0].equals("lxy")) { chart = createLineChart(); dataType = 3; } // bar charts: 'bhs', 'bhg', 'bhs' and 'bhg' else if (chartType[0].equals("bhs")) { chart = createStackedBarChart(PlotOrientation.HORIZONTAL); dataType = 2; } else if (chartType[0].equals("bhg")) { chart = createBarChart(PlotOrientation.HORIZONTAL); dataType = 2; } else if (chartType[0].equals("bvs")) { chart = createStackedBarChart(PlotOrientation.VERTICAL); dataType = 2; } else if (chartType[0].equals("bvg")) { chart = createBarChart(PlotOrientation.VERTICAL); dataType = 2; } else if (chartType[0].equals("bhs3")) { chart = createStackedBarChart3D(PlotOrientation.HORIZONTAL); dataType = 2; } else if (chartType[0].equals("bhg3")) { chart = createBarChart3D(PlotOrientation.HORIZONTAL); dataType = 2; } else if (chartType[0].equals("bvs3")) { chart = createStackedBarChart3D(PlotOrientation.VERTICAL); dataType = 2; } else if (chartType[0].equals("bvg3")) { chart = createBarChart3D(PlotOrientation.VERTICAL); dataType = 2; } // scatter chart: 's' else if (chartType[0].equals("s")) { chart = createScatterChart(); dataType = 4; } else if (chartType[0].equals("v")) { throw new RuntimeException("Venn diagrams not implemented."); // TODO: fix this. } else { throw new RuntimeException("Unknown chart type: " + chartType[0]); } chart.getPlot().setOutlineVisible(false); // *** CHART AXES *** List axes = new java.util.ArrayList(); String[] axisStr = (String[]) params.get("chxt"); if (axisStr != null) { if (chart.getPlot() instanceof XYPlot) { XYPlot plot = (XYPlot) chart.getPlot(); processAxisStr(plot, axisStr[0], axes); } else if (chart.getPlot() instanceof CategoryPlot) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); if (plot.getOrientation() == PlotOrientation.VERTICAL) { processAxisStrV(plot, axisStr[0], axes); } else { processAxisStrH(plot, axisStr[0], axes); } } } // *** AXIS RANGES *** String[] axisRangeStr = (String[]) params.get("chxr"); if (axisRangeStr != null) { String[] ranges = breakString(axisRangeStr[0], '|'); for (int i = 0; i < ranges.length; i++) { int comma1 = ranges[i].indexOf(','); int comma2 = ranges[i].indexOf(',', comma1 + 1); int axisIndex = Integer.parseInt(ranges[i].substring(0, comma1)); float lowerBound = Float.parseFloat(ranges[i].substring(comma1 + 1, comma2)); float upperBound = Float.parseFloat(ranges[i].substring(comma2 + 1)); Axis axis = (Axis) axes.get(axisIndex); if (axis instanceof GValueAxis) { GValueAxis gaxis = (GValueAxis) axis; gaxis.setLabelAxisStart(lowerBound); gaxis.setLabelAxisEnd(upperBound); } } } // *** AXIS LABELS *** String[] axisLabelStr = (String[]) params.get("chxl"); if (axisLabelStr != null) { Pattern p = Pattern.compile("\\d+:\\|"); Matcher m = p.matcher(axisLabelStr[0]); if (m.find()) { int keyStart = m.start(); int labelStart = m.end(); while (m.find(labelStart)) { String keyStr = axisLabelStr[0].substring(keyStart, labelStart - 2); int axisIndex = Integer.parseInt(keyStr); keyStart = m.start(); String labelStr = axisLabelStr[0].substring(labelStart, keyStart - 1); String[] labels = breakString(labelStr, '|'); GLabelledAxis axis = (GLabelledAxis) axes.get(axisIndex); axis.setTickLabels(Arrays.asList(labels)); labelStart = m.end(); } // process the final item String keyStr = axisLabelStr[0].substring(keyStart, labelStart - 2); String labelStr = axisLabelStr[0].substring(labelStart); int axisIndex = Integer.parseInt(keyStr); if (labelStr.endsWith("|")) { labelStr = labelStr.substring(0, labelStr.length() - 1); } String[] labels = breakString(labelStr, '|'); GLabelledAxis axis = (GLabelledAxis) axes.get(axisIndex); axis.setTickLabels(Arrays.asList(labels)); } else { throw new RuntimeException("No matching pattern!"); } } // ** EXPLICIT AXIS LABEL POSITIONS String[] axisPositionStr = (String[]) params.get("chxp"); if (axisPositionStr != null) { String[] positions = breakString(axisPositionStr[0], '|'); for (int i = 0; i < positions.length; i++) { int c1 = positions[i].indexOf(','); int axisIndex = Integer.parseInt(positions[i].substring(0, c1)); String remainingStr = positions[i].substring(c1 + 1); String[] valueStr = breakString(remainingStr, ','); List tickValues = new java.util.ArrayList(valueStr.length); Axis axis = (Axis) axes.get(axisIndex); if (axis instanceof GValueAxis) { GValueAxis gaxis = (GValueAxis) axes.get(axisIndex); for (int j = 0; j < valueStr.length; j++) { float pos = Float.parseFloat(valueStr[j]); tickValues.add(new Float(pos)); } gaxis.setTickLabelPositions(tickValues); } // FIXME: what about a CategoryAxis? } } // *** CHART TITLE *** String[] titleStr = (String[]) params.get("chtt"); if (titleStr != null) { // process the title String[] s = breakString(titleStr[0], '|'); for (int i = 0; i < s.length; i++) { TextTitle t = new TextTitle(s[i].replace('+', ' ')); t.setPaint(Color.darkGray); // Google seems to use 14pt fonts for titles and 12pt fonts for // all other text. Make sure this relationship remains. t.setFont(font.deriveFont(font.getSize2D() * 14f / 12f)); chart.addSubtitle(t); } // and the font and colour String[] fontStr = (String[]) params.get("chts"); if (fontStr != null) { int c1 = fontStr[0].indexOf(','); String colorStr = null; String fontSizeStr = null; if (c1 != -1) { colorStr = fontStr[0].substring(0, c1); fontSizeStr = fontStr[0].substring(c1 + 1); } else { colorStr = fontStr[0]; } Color color = parseColor(colorStr); int size = 12; if (fontSizeStr != null) { size = Integer.parseInt(fontSizeStr); } for (int i = 0; i < chart.getSubtitleCount(); i++) { Title t = chart.getSubtitle(i); if (t instanceof TextTitle) { TextTitle tt = (TextTitle) t; tt.setPaint(color); tt.setFont(font.deriveFont((float) size)); } } } } // *** CHART DATA *** String[] dataStr = (String[]) params.get("chd"); String scalingStr = null; if (dataStr.length > 0 && dataStr[0].startsWith("t:")) { // Only look at chds when text encoding is used String[] chds = (String[]) params.get("chds"); if (chds != null && chds.length > 0) { scalingStr = chds[0]; } } // we'll also process an optional second dataset that is provided as // an Eastwood extension...this isn't part of the Google Chart API String[] d2Str = (String[]) params.get("ewd2"); // 'p' and 'p3' - create PieDataset if (dataType == 0) { PieDataset dataset = DataUtilities.parsePieDataset(dataStr[0], scalingStr); PiePlot plot = (PiePlot) chart.getPlot(); plot.setDataset(dataset); // ignore d2Str as there is currently no need for a second pie // dataset. } // 'lc' - create XYDataset else if (dataType == 1) { XYPlot plot = (XYPlot) chart.getPlot(); XYDataset dataset = DataUtilities.parseXYDataset(dataStr[0], scalingStr); plot.setDataset(dataset); if (d2Str != null) { // an Eastwood extension XYDataset d2 = DataUtilities.parseXYDataset(d2Str[0], scalingStr); plot.setDataset(1, d2); } } // 'bhs', 'bhg', 'bvs', 'bvg' else if (dataType == 2) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryDataset dataset = DataUtilities.parseCategoryDataset(dataStr[0], scalingStr); plot.setDataset(dataset); if (d2Str != null) { // an Eastwood extension CategoryDataset d2 = DataUtilities.parseCategoryDataset(d2Str[0], scalingStr); plot.setDataset(1, d2); } } // 'lxy' else if (dataType == 3) { XYPlot plot = (XYPlot) chart.getPlot(); XYDataset dataset = DataUtilities.parseXYDataset2(dataStr[0], scalingStr); plot.setDataset(dataset); if (d2Str != null) { // an Eastwood extension XYDataset d2 = DataUtilities.parseXYDataset2(d2Str[0], scalingStr); plot.setDataset(1, d2); } } else if (dataType == 4) { XYPlot plot = (XYPlot) chart.getPlot(); XYSeriesCollection dataset = DataUtilities.parseScatterDataset(dataStr[0], scalingStr); if (dataset.getSeriesCount() > 1) { dataset.removeSeries(1); } plot.setDataset(dataset); if (d2Str != null) { // an Eastwood extension XYDataset d2 = DataUtilities.parseXYDataset2(d2Str[0], scalingStr); plot.setDataset(1, d2); } } if (chart.getPlot() instanceof XYPlot) { XYPlot plot = (XYPlot) chart.getPlot(); plot.getDomainAxis().setLabelFont(font); plot.getDomainAxis().setTickLabelFont(font); plot.getRangeAxis().setLabelFont(font); plot.getRangeAxis().setTickLabelFont(font); } else if (chart.getPlot() instanceof CategoryPlot) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.getDomainAxis().setLabelFont(font); plot.getDomainAxis().setTickLabelFont(font); plot.getRangeAxis().setLabelFont(font); plot.getRangeAxis().setTickLabelFont(font); } // *** CHART COLOURS *** String[] colorStr = (String[]) params.get("chco"); if (colorStr != null) { Color[] colors = parseColors(colorStr[0]); if (dataType == 0) { PiePlot plot = (PiePlot) chart.getPlot(); applyColorsToPiePlot(plot, colors); } else { AbstractRenderer renderer = null; if (chart.getPlot() instanceof CategoryPlot) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); renderer = (AbstractRenderer) plot.getRenderer(); renderer.setBasePaint(colors[0]); } else if (chart.getPlot() instanceof XYPlot) { XYPlot plot = (XYPlot) chart.getPlot(); renderer = (AbstractRenderer) plot.getRenderer(); renderer.setBasePaint(colors[colors.length - 1]); } for (int i = 0; i < colors.length; i++) { renderer.setSeriesPaint(i, colors[i]); } } } else { Plot plot = chart.getPlot(); if (plot instanceof PiePlot) { applyColorsToPiePlot((PiePlot) chart.getPlot(), new Color[] { new Color(255, 153, 0) }); } } // *** CHART LINE STYLES *** String[] lineStr = (String[]) params.get("chls"); if (lineStr != null && chart.getPlot() instanceof XYPlot) { Stroke[] strokes = parseLineStyles(lineStr[0]); XYPlot plot = (XYPlot) chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); for (int i = 0; i < strokes.length; i++) { renderer.setSeriesStroke(i, strokes[i]); } renderer.setBaseStroke(strokes[strokes.length - 1]); } // *** CHART GRID LINES if (dataType != 0) { String[] gridStr = (String[]) params.get("chg"); if (gridStr != null) { processGridLinesSpec(gridStr[0], chart); } } // *** CHART LABELS if (dataType == 0) { // pie chart String[] labelStr = (String[]) params.get("chl"); if (labelStr != null) { String[] s = breakString(labelStr[0], '|'); List labels = Arrays.asList(s); PiePlot plot = (PiePlot) chart.getPlot(); if (labels.size() > 0) { plot.setLabelGenerator(new GPieSectionLabelGenerator(labels)); plot.setLabelFont(font); plot.setLabelPaint(Color.darkGray); } } } String[] legendStr = (String[]) params.get("chdl"); if (legendStr != null) { // process the title String[] s = breakString(legendStr[0], '|'); List labels = Arrays.asList(s); if (labels.size() > 0) { Plot p = chart.getPlot(); if (p instanceof CategoryPlot) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setLegendItemLabelGenerator(new GSeriesLabelGenerator(labels)); renderer.setBaseSeriesVisibleInLegend(false); for (int i = 0; i < labels.size(); i++) { renderer.setSeriesVisibleInLegend(i, Boolean.TRUE); } } else if (p instanceof XYPlot) { XYPlot plot = (XYPlot) chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); renderer.setLegendItemLabelGenerator(new GSeriesLabelGenerator(labels)); renderer.setBaseSeriesVisibleInLegend(false); for (int i = 0; i < labels.size(); i++) { renderer.setSeriesVisibleInLegend(i, Boolean.TRUE); } } else if (p instanceof PiePlot) { PiePlot plot = (PiePlot) chart.getPlot(); plot.setLegendLabelGenerator(new GPieSectionLabelGenerator(labels)); } LegendTitle legend = new LegendTitle(chart.getPlot()); RectangleEdge pos = RectangleEdge.RIGHT; String[] chdlp = (String[]) params.get("chdlp"); if (chdlp != null) { if ("b".equals(chdlp[0])) { pos = RectangleEdge.BOTTOM; } else if ("t".equals(chdlp[0])) { pos = RectangleEdge.TOP; } else if ("l".equals(chdlp[0])) { pos = RectangleEdge.LEFT; } } legend.setPosition(pos); legend.setItemFont(font); legend.setItemPaint(Color.darkGray); chart.addSubtitle(legend); } } // *** CHART MARKERS *** String[] markerStr = (String[]) params.get("chm"); if (markerStr != null) { String[] markers = breakString(markerStr[0], '|'); for (int i = 0; i < markers.length; i++) { addMarker(markers[i], chart); } } // *** CHART FILL ***/ String[] fillStr = (String[]) params.get("chf"); if (fillStr != null) { // process the 1 or 2 fill specs int i = fillStr[0].indexOf('|'); if (i == -1) { processFillSpec(fillStr[0], chart); } else { String fs1 = fillStr[0].substring(0, i); String fs2 = fillStr[0].substring(i + 1); processFillSpec(fs1, chart); processFillSpec(fs2, chart); } } // process the 'ewtr' tag, if present processEWTR(params, chart); return chart; }