Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/07/2008, 15:46
dokannon
 
Fecha de Ingreso: mayo-2008
Mensajes: 3
Antigüedad: 16 años
Puntos: 0
Exclamación Formatear Texto en Java

tengo el siguiente codigo que es un servlet que dubuja un grafico ocupando jfreechart y necesito que el texot que em devuelva lo deje como texto blanco
si alguien me oudiera ayudar estaria muy agradecido ;los titulos del grafico se llenan con un sp que utiliza el bussines object de abajo, si faltan datos para que puedan ayudarme pidanmelos por fis =)

de antemano muchas gracias


@SuppressWarnings("serial")
public class IndicesValoresServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
OutputStream out = response.getOutputStream();

try {
response.setContentType("image/png");
ChartUtilities.writeChartAsPNG( out,
this.obtenerGrafico(request,
response),
450,
400);

} catch (Exception e) {
Logger.getLogger(IndicesValoresServlet.class).erro r(e.getMessage());
} finally {
out.close();
}
}

private FacesContext getFacesContext(ServletRequest request, ServletResponse response) {

FacesContextFactory contextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTE XT_FACTORY);
LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_F ACTORY);
Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEF AULT_LIFECYCLE);
ServletContext servletContext = ((HttpServletRequest) request).getSession().getServletContext();
FacesContext facesContext = contextFactory.getFacesContext( servletContext,
request,
response,
lifecycle);
return facesContext;
}

private JFreeChart generarGrafico(List<Coordenada> listaGrafico, List<EtiquetasGrafico> listaEtiquetasGrafico) {
if ((listaGrafico != null)
&& (listaEtiquetasGrafico != null)
&& (listaEtiquetasGrafico.size() > 0)) {

EtiquetasGrafico etiquetasGrafico = listaEtiquetasGrafico.get(0);

DefaultCategoryDataset dataset = new DefaultCategoryDataset();

for (Coordenada grafico : listaGrafico) {
try {
if (grafico != null) {
dataset.addValue( grafico.getValor1(),
etiquetasGrafico.getEjeX(),
(grafico.getMes() == null ? null
: (grafico.getMes() < 10 ? "0"
+ grafico.getMes()
: ""
+ grafico.getMes()))
+ "/"
+ grafico.getAno());
}
} catch (RuntimeException e) {
Logger.getLogger(IndicesValoresServlet.class).erro r(e.getMessage());
}
}

JFreeChart chart = ChartFactory.createLineChart(etiquetasGrafico.getT itulo(),
etiquetasGrafico.getEjeX(),
etiquetasGrafico.getEjeY1(),
dataset,
PlotOrientation.VERTICAL,
false,
true,
false);

chart.setAntiAlias(true);

CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.WHITE);
plot.setDomainGridlinePaint(new Color( 204,
204,
204));
plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinePaint(new Color( 204,
204,
204));

LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
plot.setDataset(1,
dataset);
plot.setRenderer( 1,
renderer2);

renderer2.setBaseShapesVisible(true);
renderer2.setDrawOutlines(true);
renderer2.setUseFillPaint(true);
renderer2.setBaseFillPaint(Color.white);
renderer2.setSeriesPaint( 0,
new Color( 0,
207,
255));
renderer2.setSeriesStroke( 0,
new BasicStroke(2.5f));
renderer2.setSeriesOutlineStroke( 0,
new BasicStroke(2.0f));
renderer2.setSeriesShape( 0,
new Ellipse2D.Double( -4.0,
-5.0,
8.0,
8.0));
//plot.setBackgroundPaint(Color.BLUE);

CategoryAxis domainAxis = plot.getDomainAxis();

domainAxis.setCategoryLabelPositions(CategoryLabel Positions.UP_45);

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
//rangeAxis.setLabelPaint(Color.white);
//rangeAxis.setTickLabelPaint(Color.white);
rangeAxis.setStandardTickUnits(NumberAxis.createIn tegerTickUnits());
//chart.setBackgroundPaint(Color.black);

return chart;
}

return null;
}

@SuppressWarnings("unchecked")
private synchronized JFreeChart obtenerGrafico(HttpServletRequest request, HttpServletResponse response) {
Integer indice = request.getParameter("indice") == null ? null
: new Integer(request.getParameter("indice"));
Integer num = request.getParameter("num") == null ? null
: new Integer(request.getParameter("num"));

if (indice != null
&& num != null) {
WebApplicationContext ctx = FacesContextUtils.getWebApplicationContext(this.ge tFacesContext(request,
response));
GraficoServletService graficoServletService = (GraficoServletService) ctx.getBean("graficoServletService");
Map map = null;

try {
map = graficoServletService.obtenerMapaIndiceValores( indice,
num);

return this.generarGrafico( (List) map.get("values"),
(List) map.get("values1"));
} catch (DataAccessException e1) {
Logger.getLogger(IndicesValoresServlet.class).erro r(e1.getMessage());
}
}

return null;
}
}



////////////////////////////////////////////////////////////////////////////////////////



public class EtiquetasGrafico {

private String titulo;
private String ejeX;
private String ejeY1;
private String ejeY2;



public String getTitulo() {
return this.titulo;
}

public void setTitulo(String titulo) {
this.titulo = titulo;
}

public String getEjeX() {
return this.ejeX;
}

public void setEjeX(String ejeX) {
this.ejeX = ejeX;
}

public String getEjeY1() {
return this.ejeY1;
}

public void setEjeY1(String ejeY1) {
this.ejeY1 = ejeY1;
}

public String getEjeY2() {
return this.ejeY2;
}

public void setEjeY2(String ejeY2) {
this.ejeY2 = ejeY2;
}

}