List of usage examples for org.jfree.chart.title LegendTitle getSources
public LegendItemSource[] getSources()
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
/** * //from ww w . java 2s. co m * if it contians CJK, set Font to "Arial Unicode MS".Or else, the Font is "Tahoma". * * @param chart */ private static void setLegendFont(JFreeChart chart) { Font font; LegendTitle legend = chart.getLegend(); if (legend != null) { font = new Font("Tahoma", Font.PLAIN, BASE_LEGEND_LABEL_SIZE);//$NON-NLS-1$ // get legend label to judge if it contains CJK. LegendItemSource[] sources = legend.getSources(); Set<String> itemLabels = new HashSet<String>(); for (LegendItemSource source : sources) { LegendItemCollection legendItems = source.getLegendItems(); for (int i = 0; i < legendItems.getItemCount(); i++) { String label = legendItems.get(i).getLabel(); if (label != null) { itemLabels.add(label); } } } if (isContainCJKCharacter(itemLabels.toArray())) { font = getCJKFont(Font.PLAIN, BASE_LEGEND_LABEL_SIZE); } legend.setItemFont(font); } }
From source file:com.hmsinc.epicenter.webapp.chart.ChartService.java
/** * @param chart/*from ww w . ja v a 2 s .c o m*/ * @return */ private static void configureTitleAndLegend(final JFreeChart chart, final AbstractChart adapter) { final TextTitle title = chart.getTitle(); if (title != null) { title.setFont(new Font("Arial", Font.BOLD, 12)); // title.setBackgroundPaint(Color.CYAN); title.setTextAlignment(HorizontalAlignment.LEFT); title.setHorizontalAlignment(HorizontalAlignment.CENTER); title.setMargin(0, 4, 5, 6); } if (chart.getLegend() != null) { chart.removeLegend(); final LegendTitle legend = new LegendTitle(chart.getPlot(), new SNColumnArrangement(0, 0), new ColumnArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, 0)); legend.setItemFont(LEGEND_FONT); legend.setPosition(RectangleEdge.BOTTOM); legend.setHorizontalAlignment(HorizontalAlignment.CENTER); legend.setBackgroundPaint(Color.WHITE); legend.setFrame(new LineBorder()); legend.setMargin(0, 4, 5, 6); chart.addLegend(legend); // Now we'll try to remove any duplicate items from the legend.. final Map<String, Integer> keys = new HashMap<String, Integer>(); final LegendItemCollection items = new LegendItemCollection(); for (LegendItemSource source : legend.getSources()) { for (int i = 0; i < source.getLegendItems().getItemCount(); i++) { final LegendItem item = source.getLegendItems().get(i); if (!keys.containsKey(item.getLabel())) { keys.put(item.getLabel(), i); items.add(item); } } } legend.setSources(new LegendItemSource[] { new LegendItemSource() { /* * (non-Javadoc) * * @see org.jfree.chart.LegendItemSource#getLegendItems() */ public LegendItemCollection getLegendItems() { return items; } } }); } }
From source file:unalcol.termites.boxplots.ECALMessages.java
private LegendTitle modifyLegend(JFreeChart chart, CategoryPlot plot) { LegendTitle legend = chart.getLegend(); chart.removeLegend();//from w ww . ja va 2s . c om LegendItemSource[] items = legend.getSources(); for (LegendItemSource item : items) { //LegendItemCollection collection = items[i].getLegendItems(); LegendItemCollection collection = plot.getLegendItems(); for (Iterator iter = collection.iterator(); iter.hasNext();) { LegendItem element = (LegendItem) iter.next(); System.out.println(" ## #" + element.getLabel()); } } return legend; }
From source file:gov.nih.nci.cma.web.graphing.GEPlot.java
public String generateBWLog2IntensityChart(String xAxisLabel, String yAxisLabel, HttpSession session, PrintWriter pw, boolean isCoinPlot) { String bwFilename = ""; //PlotSize ps = PlotSize.MEDIUM; JFreeChart bwChart = null;/*from w ww. j a v a 2 s . c om*/ try { //IMAGE Size Control CategoryAxis xAxis = new CategoryAxis(xAxisLabel); xAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(true); BoxAndWhiskerCoinPlotRenderer bwRenderer = null; CategoryPlot bwPlot = null; if (isCoinPlot) { Map<String, List<Double>> groupMap = rawDataMap.get(reporterName); DefaultBoxAndWhiskerCategoryDataset smallBwdataset = new DefaultBoxAndWhiskerCategoryDataset(); int row = 0; int column = 0; HashMap<String, List> caIntegatorCoinList = new HashMap<String, List>(); for (String group : groupList) { smallBwdataset.add(groupMap.get(group), reporterName, group); caIntegatorCoinList.put(row + "_" + column++, groupMap.get(group)); } bwRenderer = new BoxAndWhiskerCoinPlotRenderer(caIntegatorCoinList); bwRenderer.setDisplayAllOutliers(true); bwRenderer.setDisplayCoinCloud(true); bwRenderer.setDisplayMean(false); bwRenderer.setFillBox(false); bwRenderer.setPlotColor(null); bwPlot = new CategoryPlot(smallBwdataset, xAxis, yAxis, bwRenderer); if (groupList.size() < 6) imgW = 200; } else { bwRenderer = new BoxAndWhiskerCoinPlotRenderer(); bwRenderer.setDisplayAllOutliers(true); bwRenderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset dataset, int series, int item) { String tt = ""; NumberFormat formatter = new DecimalFormat(".####"); String key = ""; //String s = formatter.format(-1234.567); // -001235 if (dataset instanceof DefaultBoxAndWhiskerCategoryDataset) { DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset) dataset; try { String med = formatter.format(ds.getMedianValue(series, item)); tt += "Median: " + med + "<br/>"; tt += "Mean: " + formatter.format(ds.getMeanValue(series, item)) + "<br/>"; tt += "Q1: " + formatter.format(ds.getQ1Value(series, item)) + "<br/>"; tt += "Q3: " + formatter.format(ds.getQ3Value(series, item)) + "<br/>"; tt += "Max: " + formatter.format( FaroutOutlierBoxAndWhiskerCalculator.getMaxFaroutOutlier(ds, series, item)) + "<br/>"; tt += "Min: " + formatter.format( FaroutOutlierBoxAndWhiskerCalculator.getMinFaroutOutlier(ds, series, item)) + "<br/>"; tt += "<br/><br/>Please click on the box and whisker to view a plot for this reporter.<br/>"; key = ds.getRowKeys().get(series).toString(); } catch (Exception e) { } } String returnString = "onclick=\"popCoin('" + geneSymbol + "','" + key + "');\" | "; return returnString + tt; } }); bwRenderer.setFillBox(false); bwPlot = new CategoryPlot(bwdataset, xAxis, yAxis, bwRenderer); } bwChart = new JFreeChart(bwPlot); bwChart.setBackgroundPaint(java.awt.Color.white); LegendTitle title = bwChart.getLegend(); LegendItemSource[] sources = title.getSources(); legendItemCollection = sources[0].getLegendItems(); bwChart.removeLegend(); // Write the chart image to the temporary directory ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); // BW if (bwChart != null) { //int bwwidth = new BigDecimal(1.5).multiply(new BigDecimal(imgW)).intValue(); bwFilename = ServletUtilities.saveChartAsPNG(bwChart, imgW, 400, info, session); CustomOverlibToolTipTagFragmentGenerator ttip = new CustomOverlibToolTipTagFragmentGenerator(); ttip.setExtra(" href='javascript:void(0);' "); //must have href for area tags to have cursor:pointer ChartUtilities.writeImageMap(pw, bwFilename, info, ttip, new StandardURLTagFragmentGenerator()); info.clear(); // lose the first one info = new ChartRenderingInfo(new StandardEntityCollection()); } //END BW pw.flush(); } catch (Exception e) { System.out.println("Exception - " + e.toString()); e.printStackTrace(System.out); } // return filename; //charts.put("errorBars", log2Filename); //charts.put("noErrorBars", rawFilename); //charts.put("bwFilename", bwFilename); //charts.put("legend", legendHtml); //charts.put("size", ps.toString()); return bwFilename; }