danccar 0 Denunciar post Postado Novembro 19, 2004 Ola, alguem sabe como criar um titulo com n linhas usando o jfreechart? Tentei colocar \n ou tag BR do html mas nao funciona... a string de titulo nao quebra.... no metodo de fabrica tentei usar o chart.setSubTitle(lista) ... passando uma lista de subtitulos... mas tb nao funcionou... COMO FAZER..? * Outra duvida...e´ como colocar uma nota(um text informativo) dentro do grafico... se alguem puder me ajudar... ficarei muito grato... meu codigo esta aqui... 1) classe 1 q vai no banco... package br.com.stefanini.cobilling.relatorios.contestado.chart;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.LinkedHashMap;import java.util.Map;import br.com.stefanini.cobilling.relatorios.JReportContestadoServlet;import br.com.stefanini.framework.util.date.DateUtil;import br.com.stefanini.util.jasperreport.BaseChartBar;public final class ChartConstestacaoCDRPeriodo extends BaseChartBar{ private String dataDe; private String dataAte; private String modalidade; private String campoData; private String usuarios; private String operadoras; private String tituloCompleto; /** * @param dataDe * @param dataAte * @param campoData * @param operadoras */ public ChartConstestacaoCDRPeriodo(Map parameters) { super("Dias", "Quantidade de Contestações","CDRS Contestados por Período"); //construtor do ChartBar - Label X, Label Y, Title this.dataDe = parameters.get("PDATA_DE").toString(); this.dataAte = parameters.get("PDATA_ATE").toString(); this.campoData = parameters.get("PCAMPO_DATA").toString(); this.operadoras = parameters.get("POPERADORA").toString(); super.setLegend(false);[b]//AQUI O BR OU \n nao funciona depois do + o daria um <ENTER>à cada linha...[/b] // ----- \U000D this.tituloCompleto = " CDRs Contestados por data. " + [b]\n[/b] parameters.get("PPERIODO").toString() + " Operadora : " + parameters.get("NOME_OPERADORA").toString(); this.setTitle(this.tituloCompleto); } public Map getDataSet() { //Map ht = new Hashtable(); Map ht = new LinkedHashMap(); Connection conn = null; ResultSet rs = null; try { conn = JReportContestadoServlet.getConnection(); Statement stm = conn.createStatement( ); String query = "SELECT C." + campoData + ", COUNT(C." + campoData + ") AS QTDCON " + "FROM CDR_CONTESTADO AS C " + "WHERE C.COD_EMPRESA_CONTRATADA in (" + operadoras + ") AND " + "(" + campoData + " BETWEEN '" + dataDe + "'\n" + " AND '" + dataAte + "') \n" + "GROUP BY " + campoData + " ORDER BY " + campoData; //System.out.println("query: \n" + query); rs = stm.executeQuery(query); while (rs.next()) { ht.put(DateUtil.dateToStr(rs.getObject(1)) + " " , rs.getObject(2)); } return ht; } catch (Exception e) { e.printStackTrace(); } finally { try { if (rs != null) rs.close(); } catch (SQLException e1) {} } return null; } private Object DateFormat(Object object) { return null; }}classe pai .... q gera o grafico/** * @author alisson gomes, bruno braga */package br.com.stefanini.util.jasperreport;import java.awt.image.BufferedImage;import java.util.ArrayList;import java.util.Arrays;import java.util.Date;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import java.util.SortedMap;import org.jfree.chart.ChartFactory;import org.jfree.chart.JFreeChart;import org.jfree.chart.axis.CategoryAxis;import org.jfree.chart.plot.CategoryPlot;import org.jfree.chart.plot.PlotOrientation;import org.jfree.data.DefaultCategoryDataset;import org.jfree.data.XYDataset;import org.jfree.data.XYSeries;import org.jfree.data.XYSeriesCollection; public abstract class BaseChartBar extends BaseChart { private boolean overrideDate = true; private String dateFormatOverride = "dd/MM/yyyy"; private boolean verticalTickLabels = true; private String serie = ""; private PlotOrientation plotOrientation; private boolean legend; private boolean tooltips; private boolean urls; private String labelX; private String labelY; private boolean sorted; public String[] titulos = {"Título 1", "Título 2" , "Título 3"}; public ArrayList alista = new ArrayList(Arrays.asList(titulos)); public BaseChartBar(String labelX, String labelY, String title) { if (title == null || title.equals("")) super.setTitle("Titulo"); else super.setTitle(title); if (labelX == null || labelX.equals("")) this.labelX = "Rotulo do Eixo-X "; else this.labelX = labelX; if (labelY == null || labelY.equals("")) this.labelY = "Rotulo do Eixo-Y "; else this.labelY = labelY; plotOrientation = PlotOrientation.VERTICAL; this.legend = true; this.tooltips = true; this.urls = false; this.sorted = true; } public JFreeChart createChart(String title, int height, int width) { DefaultCategoryDataset barDataSet = new DefaultCategoryDataset(); if (height > 0) super.setHeight(height); else super.setHeight(550); if (width > 0 ) super.setWidth(width); else super.setWidth(750); if (title != null && !title.equals("")) super.setTitle(title); else super.setTitle("Título"); // Preenchendo o DefaultPieDataSet this.fillChart(barDataSet); // Cria um Chart com o DataSet JFreeChart chart = ChartFactory.createBarChart3D(super.getTitle(), this.labelX, this.labelY, barDataSet, this.plotOrientation, this.legend, this.tooltips, this.urls); this.changePropertyChart(chart); return chart; } private void changePropertyChart (JFreeChart chart) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryAxis axis = plot.getDomainAxis(); axis.setVerticalCategoryLabels(this.verticalTickLabels);/* Plot plot = chart.getPlot(); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setVerticalTickLabels(this.verticalTickLabels); if (this.overrideDate) { axis.setDateFormatOverride(new SimpleDateFormat(this.dateFormatOverride)); } */ /* XYPlot plot = (XYPlot)chart.getPlot(); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setVerticalTickLabels(this.verticalTickLabels); if (this.overrideDate) { axis.setDateFormatOverride(new SimpleDateFormat(this.dateFormatOverride)); } */ } public BufferedImage createChartImage(String title, int height, int width) { DefaultCategoryDataset barDataSet = new DefaultCategoryDataset(); if (height > 0) super.setHeight(height); else super.setHeight(550); if (width > 0 ) super.setWidth(width); else super.setWidth(750); if (title != null && !title.equals("")) super.setTitle(title); else super.setTitle("Título"); // Preenchendo o DefaultCategoryDataSet this.fillChart(barDataSet); // Cria um Chart com o DataSet JFreeChart chart = ChartFactory.createBarChart3D(super.getTitle(), this.labelX, this.labelY, barDataSet, this.plotOrientation, this.legend, this.tooltips, this.urls); // gambi: [b] // aqui esta a parte q tentei e nao funciona ......[/b] //aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa //chart.setSubtitles(alista); List l = new ArrayList(); l.add("Titulo 1111111111111"); l.add("Titulo 2222222222222"); l.add("Titulo 3333333333333"); chart.setSubtitles(l); //aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa this.changePropertyChart(chart); // Cria uma imagem e retorna ela pro JasperReport return chart.createBufferedImage(super.getWidth(), super.getHeight()); } protected void fillChart(DefaultCategoryDataset barDataSet) { Iterator it = null; Set set = null; Map dataSet; dataSet = getDataSet(); set = dataSet.keySet(); it = set.iterator(); while (it.hasNext()) { Object key = null, value = null; key = it.next(); value = dataSet.get(key); if (value instanceof SortedMap || value instanceof Map ) { Iterator subIt = null; Set subSet = null; Map m = (Map) dataSet.get(key); subSet = m.keySet(); subIt = subSet.iterator(); while (subIt.hasNext() ) { Object subValue = null; //,subKey = null; String subKey = null; subKey = (String)subIt.next(); subValue = m.get(subKey); if (subValue instanceof Integer) if (key instanceof Date) barDataSet.addValue((Integer) subValue, (Date)key, subKey); else barDataSet.addValue((Integer) subValue, (String)key, subKey); else if (subValue instanceof Float) if (key instanceof Date) barDataSet.addValue((Float) subValue, (Date)key, subKey); else barDataSet.addValue((Float) subValue, (String)key, subKey); else if (subValue instanceof Double) if (key instanceof Date) barDataSet.addValue((Double) subValue, (Date)key, subKey); else barDataSet.addValue((Double) subValue, (String)key, subKey); else if (subValue instanceof Long) if (key instanceof Date) barDataSet.addValue((Long) subValue, (Date)key, subKey); else barDataSet.addValue((Long) subValue, (String)key, subKey); else { if (key instanceof Date) barDataSet.addValue(new Double(subValue.toString()), (Date)key, subKey); else barDataSet.addValue(new Double(subValue.toString()), (String)key, subKey); } } } else { // TODO: Melhorar isso aqui tah um côco! if (value instanceof Integer) { if (key instanceof Date) barDataSet.addValue((Integer)value, this.serie, (Date)key); else barDataSet.addValue((Integer)value, this.serie, (String)key); } else if (value instanceof Float) { if (key instanceof Date) barDataSet.addValue((Float)value, this.serie, (Date)key); else barDataSet.addValue((Float)value, this.serie, (String)key); } else if (value instanceof Double) { if (key instanceof Date) barDataSet.addValue((Double)value, this.serie, (Date)key); else barDataSet.addValue((Double)value, this.serie, (String)key); } else if (value instanceof Long) { if (key instanceof Date) barDataSet.addValue((Long)value, this.serie, (Date)key); else barDataSet.addValue((Long)value, this.serie, (String)key); } else { if (key instanceof Date) barDataSet.addValue(new Double(value.toString()), this.serie, (Date)key); else barDataSet.addValue(new Double(value.toString()), this.serie, (String)key); } } } } /** * @param legend The legend to set. */ public void setLegend(boolean legend) { this.legend = legend; } /** * @param plotOrientation The plotOrientation to set. */ public void setPlotOrientation(PlotOrientation plotOrientation) { this.plotOrientation = plotOrientation; } /** * @param serie The serie to set. */ public void setSerie(String serie) { this.serie = serie; } /** * @param tooltips The tooltips to set. */ public void setTooltips(boolean tooltips) { this.tooltips = tooltips; } /** * @param urls The urls to set. */ public void setUrls(boolean urls) { this.urls = urls; } /** * @param sorted The sorted to set. */ public void setSorted(boolean sorted) { this.sorted = sorted; } /** * Especifica um formato para que a data seja impressa. * @param format Formato que a data seja impressa. Exemplo: "MMM/yyyy" | "dd/MM/yyyy" * @author Alisson gomes */ public void setDateFormatOverride(String format) { this.overrideDate = true; this.dateFormatOverride = format; } /** * Sets the flag that controls whether the tick labels are displayed vertically * (that is, rotated 90 degrees from horizontal). * @param */ public void setVerticalTickLabels(boolean flag) { this.verticalTickLabels = flag; }} Compartilhar este post Link para o post Compartilhar em outros sites
webroot 0 Denunciar post Postado Novembro 19, 2004 Com relação à primeira duvida não entendi nada, 'desculpe' mas com relação à segunda Java2 têm uma opção para isto chamada GlassPane com ela você consegue resolver seu problema. você pode encontrar no site da Sun Blza? Compartilhar este post Link para o post Compartilhar em outros sites