List of usage examples for org.jfree.chart LegendItemCollection getItemCount
public int getItemCount()
From source file:gov.nih.nci.caintegrator.ui.graphing.legend.LegendCreator.java
/** * creates and HTML legend and returns a string of HTML * @param lic - a jFreechart LegendItemCollection * @return/* ww w. j a v a 2 s .c o m*/ */ public static String buildLegend(LegendItemCollection lic, String legendTitle) { //TODO: take annotation link as a string param String html = new String(); Color p = null; html = "<fieldset style='display:table;width:600; border:1px solid gray; text-align:left; padding:5px;'>"; html += "<legend>Legend: " + legendTitle + "</legend>"; for (int i = 0; i < lic.getItemCount(); i++) { p = (Color) lic.get(i).getFillPaint(); //html += "<div style='margin:10px; padding:10px;border:1px solid red;'><label style='width:30px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;'> </label><b style='color: "+ c2hex(p)+"'>"+lic.get(i).getLabel()+"</b></div>\n"; html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: " + c2hex(p) + "; border:1px solid black;\"> </td><td><a style=\"text-decoration:none\" href=\"javascript:alert(\'some annotation for:" + lic.get(i).getLabel() + "\');\"><b style=\"color: " + c2hex(p) + "\">" + lic.get(i).getLabel() + "</b></a></td></tr></table>"; } html += "</fieldset>"; String js = ""; //js = "<script language=\"javascript\">document.getElementById('legend').innerHTML = \""+ html +" \"; </script>"; return html; }
From source file:gov.nih.nci.cma.web.graphing.LegendCreator.java
/** * creates and HTML legend and returns a string of HTML * @param lic - a jFreechart LegendItemCollection * @return//from w w w. j ava 2 s. c o m */ public static String buildLegend(LegendItemCollection lic, String legendTitle) { //TODO: take annotation link as a string param String html = new String(); Color p = null; //html = "<fieldset style='display:table;width:600; border:1px solid gray; text-align:left; padding:5px;'>"; //html += "<legend>Legend: "+ legendTitle+"</legend>"; for (int i = 0; i < lic.getItemCount(); i++) { p = (Color) lic.get(i).getFillPaint(); //html += "<div style='margin:10px; padding:10px;border:1px solid red;'><label style='width:30px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;'> </label><b style='color: "+ c2hex(p)+"'>"+lic.get(i).getLabel()+"</b></div>\n"; html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: " + c2hex(p) + "; border:1px solid black;\"> </td><td><a style=\"text-decoration:none\" " + "href=\"javascript:spawnAnnot('" + lic.get(i).getLabel() + "\');\"><b style=\"color: " + c2hex(p) + "\">" + lic.get(i).getLabel() + "</b></a></td></tr></table>"; //html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;\"> </td><td><a style=\"text-decoration:none\" href=\"javascript:alert(\'some annotation for:"+lic.get(i).getLabel()+"\');\"><b style=\"color: "+ c2hex(p)+"\">"+lic.get(i).getLabel()+"</b></a></td></tr></table>"; } //html += "</fieldset>"; //System.out.println(html); String js = ""; //js = "<script language=\"javascript\">document.getElementById('legend').innerHTML = \""+ html +" \"; </script>"; return html; }
From source file:gov.nih.nci.cma.web.graphing.LegendCreator.java
/** * creates and HTML legend and returns a string of HTML * @param lic - a jFreechart LegendItemCollection * @return/*from ww w. j ava2 s . c o m*/ */ public static String buildSmartLegend(String chipType, LegendItemCollection lic, String legendTitle) { //TODO: take annotation link as a string param String html = new String(); Color p = null; //html = "<fieldset style='display:table;width:600; border:1px solid gray; text-align:left; padding:5px;'>"; //html += "<legend>Legend: "+ legendTitle+"</legend>"; for (int i = 0; i < lic.getItemCount(); i++) { p = (Color) lic.get(i).getFillPaint(); //html += "<div style='margin:10px; padding:10px;border:1px solid red;'><label style='width:30px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;'> </label><b style='color: "+ c2hex(p)+"'>"+lic.get(i).getLabel()+"</b></div>\n"; // JB: GF [#21548] Issue for annotation query in GeneView // The LPG application that these probeset links redirect the user to, only support the HG-133 Chip. // So, when non-HG133 chips were selected for the GeneView search, those links probeset // links are NOT hyperlinked to the LPG site. if (chipType.equals("AFFY_HT_HG-U133A") || chipType.equals("AFFY_HGU133P2")) { html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: " + c2hex(p) + "; border:1px solid black;\"> </td><td><a style=\"text-decoration:none\" " + "href=\"javascript:spawnAnnot('" + lic.get(i).getLabel() + "\');\"><b style=\"color: " + c2hex(p) + "\">" + lic.get(i).getLabel() + "</b></a></td></tr></table>"; } else { html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: " + c2hex(p) + "; border:1px solid black;\"> </td><td><b style=\"color: " + c2hex(p) + "\">" + lic.get(i).getLabel() + "</b></td></tr></table>"; } //html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;\"> </td><td><a style=\"text-decoration:none\" href=\"javascript:alert(\'some annotation for:"+lic.get(i).getLabel()+"\');\"><b style=\"color: "+ c2hex(p)+"\">"+lic.get(i).getLabel()+"</b></a></td></tr></table>"; } //html += "</fieldset>"; //System.out.println(html); String js = ""; //js = "<script language=\"javascript\">document.getElementById('legend').innerHTML = \""+ html +" \"; </script>"; return html; }
From source file:gov.nih.nci.rembrandt.web.legend.LegendCreator.java
/** * creates and HTML legend and returns a string of HTML * @param lic - a jFreechart LegendItemCollection * @return//from w w w.j a va 2 s . c o m */ public static String buildLegend(LegendItemCollection lic, String legendTitle) { //TODO: take annotation link as a string param String html = new String(); Color p = null; html = "<fieldset style='display:table;width:600; border:1px solid gray; text-align:left; padding:5px;'>"; html += "<legend>Legend: " + legendTitle + "</legend>"; for (int i = 0; i < lic.getItemCount(); i++) { p = (Color) lic.get(i).getFillPaint(); //html += "<div style='margin:10px; padding:10px;border:1px solid red;'><label style='width:30px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;'> </label><b style='color: "+ c2hex(p)+"'>"+lic.get(i).getLabel()+"</b></div>\n"; html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: " + c2hex(p) + "; border:1px solid black;\"> </td><td><a style=\"text-decoration:none\" href=\"javascript:spawnAnnot('reporterFromGeneQS', '" + lic.get(i).getLabel() + "\');\"><b style=\"color: " + c2hex(p) + "\">" + lic.get(i).getLabel() + "</b></a></td></tr></table>"; //html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;\"> </td><td><a style=\"text-decoration:none\" href=\"javascript:alert(\'some annotation for:"+lic.get(i).getLabel()+"\');\"><b style=\"color: "+ c2hex(p)+"\">"+lic.get(i).getLabel()+"</b></a></td></tr></table>"; } html += "</fieldset>"; String js = ""; //js = "<script language=\"javascript\">document.getElementById('legend').innerHTML = \""+ html +" \"; </script>"; return html; }
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
/** * /*from w w w. j a v a2s .com*/ * 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:edu.emory.library.tast.database.graphs.GraphTypeXY.java
public JFreeChart createChart(Object[] data) { CategoryTableXYDataset dataset = new CategoryTableXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart(null, getSelectedIndependentVariable().getLabel(), TastResource.getText("components_charts_barvalue"), dataset, PlotOrientation.VERTICAL, true, true, false);/* ww w .ja va 2 s . c o m*/ Format formatter = getSelectedIndependentVariable().getFormat(); XYPlot plot = chart.getXYPlot(); if (formatter != null) ((NumberAxis) plot.getDomainAxis()).setNumberFormatOverride((NumberFormat) formatter); chart.setBackgroundPaint(Color.white); List allDataSeries = getDataSeries(); for (int j = 0; j < allDataSeries.size(); j++) { DataSeries dataSearies = (DataSeries) allDataSeries.get(j); String dataSeriesLabel = dataSearies.formatForDisplay(); for (int i = 0; i < data.length; i++) { Object[] row = (Object[]) data[i]; Number x = (Number) row[0]; Number y = (Number) row[j + 1]; if (x != null && y != null) dataset.add(x.doubleValue(), y.doubleValue(), dataSeriesLabel); } } LegendItemCollection legendItems = chart.getPlot().getLegendItems(); for (int i = 0; i < legendItems.getItemCount(); i++) { LegendItem legendItem = legendItems.get(i); DataSeries dataSearies = (DataSeries) allDataSeries.get(i); if (legendItem.getFillPaint() instanceof Color) { dataSearies.setColor(((Color) legendItem.getFillPaint())); } } return chart; }
From source file:edu.emory.library.tast.database.graphs.GraphTypeBar.java
public JFreeChart createChart(Object[] data) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = ChartFactory.createBarChart(null, getSelectedIndependentVariable().getLabel(), TastResource.getText("components_charts_barvalue"), dataset, PlotOrientation.VERTICAL, true, true, false);/*from w w w . ja v a 2s . co m*/ CategoryPlot plot = chart.getCategoryPlot(); plot.getDomainAxis().setMaximumCategoryLabelLines(5); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); chart.setBackgroundPaint(Color.white); Format formatter = getSelectedIndependentVariable().getFormat(); List allDataSeries = getDataSeries(); for (int j = 0; j < allDataSeries.size(); j++) { DataSeries dataSearies = (DataSeries) allDataSeries.get(j); String dataSeriesLabel = dataSearies.formatForDisplay(); for (int i = 0; i < data.length; i++) { Object[] row = (Object[]) data[i]; String cat = formatter == null ? row[0].toString() : formatter.format(row[0]); dataset.addValue((Number) row[j + 1], dataSeriesLabel, cat); } } LegendItemCollection legendItems = chart.getPlot().getLegendItems(); for (int i = 0; i < legendItems.getItemCount(); i++) { LegendItem legendItem = legendItems.get(i); DataSeries dataSearies = (DataSeries) allDataSeries.get(i); if (legendItem.getFillPaint() instanceof Color) { dataSearies.setColor(((Color) legendItem.getFillPaint())); } } return chart; }
From source file:com.haskins.cloudtrailviewer.sidebar.EventsChart.java
@Override public void update() { String source = customGroup.getSelection().getActionCommand(); String actionCommand = topGroup.getSelection().getActionCommand(); int periodPos = actionCommand.indexOf("."); String topStr = actionCommand.substring(periodPos + 1); int top = Integer.parseInt(topStr); List<Map.Entry<String, Integer>> chartEvents = ChartUtils.getTopEvents(eventDb.getEvents(), top, source); chartCards.removeAll();/*from www . jav a 2 s .c o m*/ String style = styleGroup.getSelection().getActionCommand(); String orientationCommand = orientationGroup.getSelection().getActionCommand(); PlotOrientation orientation = PlotOrientation.VERTICAL; if (orientationCommand.contains("horizontal")) { orientation = PlotOrientation.HORIZONTAL; } ChartPanel cp = ChartFactory.createChart(style, chartEvents, 320, 240, orientation); chartCards.add(cp, ""); chartCards.revalidate(); for (int i = defaultTableModel.getRowCount() - 1; i >= 0; i--) { defaultTableModel.removeRow(i); } LegendItemCollection legendItems = ((ChartPanel) chartCards.getComponent(0)).getChart().getPlot() .getLegendItems(); for (Map.Entry entry : chartEvents) { Color col = null; String key = (String) entry.getKey(); for (int i = 0; i < legendItems.getItemCount(); i++) { LegendItem item = legendItems.get(i); if (item.getLabel().equalsIgnoreCase(key)) { col = (Color) item.getFillPaint(); } } defaultTableModel.addRow(new Object[] { col, key, entry.getValue() }); } }
From source file:com.haskins.cloudtrailviewer.sidebar.AbstractChart.java
/** * updates the chart, changing the menus if needed and updating the contents * of the Key table./*from w w w. ja va2s . co m*/ * @param chartData */ void updateChart(List<Map.Entry<String, Integer>> chartData) { chartCards.removeAll(); for (int i = defaultTableModel.getRowCount() - 1; i >= 0; i--) { defaultTableModel.removeRow(i); } if (chartData != null && chartData.size() > 0) { String style = styleGroup.getSelection().getActionCommand(); String orientationCommand = orientationGroup.getSelection().getActionCommand(); PlotOrientation orientation = PlotOrientation.VERTICAL; if (orientationCommand.contains("horizontal")) { orientation = PlotOrientation.HORIZONTAL; } ChartPanel cp = ChartFactory.createChart(style, chartData, 320, 240, orientation); chartCards.add(cp, ""); chartCards.revalidate(); LegendItemCollection legendItems = ((ChartPanel) chartCards.getComponent(0)).getChart().getPlot() .getLegendItems(); for (Map.Entry entry : chartData) { Color col = null; String key = (String) entry.getKey(); for (int i = 0; i < legendItems.getItemCount(); i++) { LegendItem item = legendItems.get(i); if (item.getLabel().equalsIgnoreCase(key)) { col = (Color) item.getFillPaint(); } } if (key.contains(":i-")) { int posColon = key.indexOf(':'); key = key.substring(posColon + 1); } defaultTableModel.addRow(new Object[] { col, key, entry.getValue() }); } } }
From source file:com.haskins.cloudtrailviewer.sidebar.EventsStats.java
private void updateChart() { String source = sourceGroup.getSelection().getActionCommand(); String actionCommand = topGroup.getSelection().getActionCommand(); int periodPos = actionCommand.indexOf("."); String topStr = actionCommand.substring(periodPos + 1); int top = Integer.parseInt(topStr); List<Map.Entry<String, Integer>> chartEvents = ChartUtils.getTopEvents(eventDb.getEvents(), top, source); chartCards.removeAll();/*from w ww .j av a2 s .co m*/ String style = styleGroup.getSelection().getActionCommand(); String orientationCommand = orientationGroup.getSelection().getActionCommand(); PlotOrientation orientation = PlotOrientation.VERTICAL; if (orientationCommand.contains("horizontal")) { orientation = PlotOrientation.HORIZONTAL; } ChartPanel cp = ChartFactory.createChart(style, chartEvents, 320, 240, orientation); chartCards.add(cp, ""); chartCards.revalidate(); for (int i = defaultTableModel.getRowCount() - 1; i >= 0; i--) { defaultTableModel.removeRow(i); } LegendItemCollection legendItems = ((ChartPanel) chartCards.getComponent(0)).getChart().getPlot() .getLegendItems(); for (Map.Entry entry : chartEvents) { Color col = null; String key = (String) entry.getKey(); for (int i = 0; i < legendItems.getItemCount(); i++) { LegendItem item = legendItems.get(i); if (item.getLabel().equalsIgnoreCase(key)) { col = (Color) item.getFillPaint(); } } defaultTableModel.addRow(new Object[] { col, key, entry.getValue() }); } }