El problema que tengo es el siguiente no puedo personalizar mi ejex ya que solo quiero que m muestre las horas
String labels = "00:00,00:10,00:20,00:30,00:40,00:50," +
"01:00,01:10,01:20,01:30,01:40,01:50," +
"02:00,02:10,02:20,02:30,02:40,02:50," +
"03:00,03:10,03:20,03:30,03:40,03:50," +
"04:00,04:10,04:20,04:30,04:40,04:50," +
"05:00,05:10,05:20,05:30,05:40,05:50," +
"06:00,06:10,06:20,06:30,06:40,06:50," +
"07:00,07:10,07:20,07:30,07:40,07:50," +
"08:00,08:10,08:20,08:30,08:40,08:50," +
"09:00,09:10,09:20,09:30,09:40,09:50," +
"10:00,10:10,10:20,10:30,10:40,10:50," +
"11:00,11:10,11:20,11:30,11:40,11:50," +
"12:00,12:10,12:20,12:30,12:40,12:50," +
"13:00,13:10,13:20,13:30,13:40,13:50," +
"14:00,14:10,14:20,14:30,14:40,14:50," +
"15:00,15:10,15:20,15:30,15:40,15:50," +
"16:00,16:10,16:20,16:30,16:40,16:50," +
"17:00,17:10,17:20,17:30,17:40,17:50," +
"18:00,18:10,18:20,18:30,18:40,18:50," +
"19:00,19:10,19:20,19:30,19:40,19:50," +
"20:00,20:10,20:20,20:30,20:40,20:50," +
"21:00,21:10,21:20,21:30,21:40,21:50," +
"22:00,22:10,22:20,22:30,22:40,22:50," +
"23:00,23:10,23:20,23:30,23:40,23:50";
que todos los valores es enviado por otra clase, el grafico me sale casi ok, lo que quiero es que en el eje "x" solo me muestre las horas, pero tomando en cuenta todo los valores de x_labels para hacer el grafico
es decir que en el grafico el eje x solo muestre "00:00,01:00,02:00,03:00,04:00,05:00,06:00,07:00,0 8:00,09:00,10:00,11:00,12:00,13:00,14:00,15:00,16: 00,17:00,18:00,19:00,20:00,21:00,22:00,23:00,00:00 ";"
tb tengo una variable dias, lo que quiero es que con los elementos del ejex haga la siguiente operacion, que si son 2 dias que muestre 2 veces desde el 00:00 al 23:00
en openflashchart lohacia de la siguiente manera
Cita:
imprimir.java.....
"&x_label_style=10,#0101DF,2,"+ 6 * Integer.parseInt(dias)+",#FFFFFF& \n"
"&x_labels="+x_labels+",00:00& \n"+
...........
"&x_label_style=10,#0101DF,2,"+ 6 * Integer.parseInt(dias)+",#FFFFFF& \n"
"&x_labels="+x_labels+",00:00& \n"+
...........
Cita:
Muchas Gracias de antemano! public class Imprimir extends HttpServlet {
public Imprimir(){
}
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException, IndexOutOfBoundsException{
OutputStream salida = res.getOutputStream();
res.setContentType("text/html");
try{
HttpSession sesion=req.getSession(true);
String circulacion=(String)sesion.getAttribute("circulaci on");
String accidente=(String)sesion.getAttribute("accidente") ;
String total=(String)sesion.getAttribute("total");
String dias=(String)sesion.getAttribute("dias");
String xlabels=(String)sesion.getAttribute("x_labels");
System.out.println("circulacion"+circulacion);
System.out.println("accidente"+accidente);
System.out.println("total"+total);
System.out.println("xlabels"+xlabels);
String url="R:/Workspace"+req.getContextPath()+"/WebContent/";
//String t=getServletContext().getRealPath(arg0)Path("/")+"imagenes/";
//System.out.println("t"+t);
System.out.println("t"+url);
JFreeChart grafica=generaGrafico(generarDatos(circulacion, accidente, total, xlabels,dias),url);
ChartUtilities.writeChartAsJPEG(salida,grafica,100 0,600);
salida.close();
}catch(Exception e)
{
e.printStackTrace(System.out);
}
}
public DefaultCategoryDataset generarDatos(String circulacion, String accidente, String total, String xlabels,String dias)
{ String []circu=circulacion.split(",");
String []accid=accidente.split(",");
String []tota=total.split(",");
String []x_labels=xlabels.split(",");
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for(int i=0;i<x_labels.length;i++)
{ dataset.setValue(Double.valueOf(tota[i]).doubleValue(), "Total",x_labels[i]);
dataset.setValue(Double.valueOf(accid[i]).doubleValue(), "Accidente", x_labels[i]);
dataset.setValue(Double.valueOf(circu[i]).doubleValue(),"Circulacion", x_labels[i]);
}
return dataset;
}
public JFreeChart generaGrafico(DefaultCategoryDataset dataset,String url)
{
JFreeChart chart= ChartFactory.createLineChart("Cola de Retenciones", "Tiempo (Horas)",
"kilometro (km)", dataset, PlotOrientation.VERTICAL, true, true, true);
chart.setBackgroundPaint(Color.white);
salvaGraficoEnFichero(chart,url);
BasicStroke nuevo;
CategoryPlot plot= chart.getCategoryPlot ();
//COLOR DE FONDO DE LA IMAGEN
plot.setBackgroundPaint(Color.WHITE);
plot.getRenderer().setSeriesPaint(0, ChartColor.DARK_GREEN);
plot.getRenderer().setSeriesPaint(1, ChartColor.DARK_RED);
plot.getRenderer().setSeriesPaint(2, ChartColor.DARK_BLUE);
//STYLO DE LAS LINEAS
LineAndShapeRenderer lrenderer= (LineAndShapeRenderer) plot.getRenderer();
lrenderer.setStroke(new BasicStroke(4F, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL));
//PROPIEDADES DE EJE X
CategoryAxis ejex = plot.getDomainAxis();
ejex.setLabelPaint(Color.BLUE);
ejex.setAxisLinePaint(Color.BLUE);
//PROPIEDADES DEL EJE Y
NumberAxis ejey = (NumberAxis) plot.getRangeAxis();
ejey.setLabelPaint(Color.BLUE);
ejey.setAxisLinePaint(Color.BLUE);
return chart;
}
private void salvaGraficoEnFichero(JFreeChart chart, String ruta) {
try {
String tmpDir=ruta;
ChartUtilities.saveChartAsJPEG(new File(tmpDir+"grafico.jpg"), chart, 500, 800);
System.out.println("Salvada imagen en " + tmpDir +"grafico.jpg");
} catch (IOException e) {
System.err.println("Error creando grafico.");
}
}
}
public Imprimir(){
}
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException, IndexOutOfBoundsException{
OutputStream salida = res.getOutputStream();
res.setContentType("text/html");
try{
HttpSession sesion=req.getSession(true);
String circulacion=(String)sesion.getAttribute("circulaci on");
String accidente=(String)sesion.getAttribute("accidente") ;
String total=(String)sesion.getAttribute("total");
String dias=(String)sesion.getAttribute("dias");
String xlabels=(String)sesion.getAttribute("x_labels");
System.out.println("circulacion"+circulacion);
System.out.println("accidente"+accidente);
System.out.println("total"+total);
System.out.println("xlabels"+xlabels);
String url="R:/Workspace"+req.getContextPath()+"/WebContent/";
//String t=getServletContext().getRealPath(arg0)Path("/")+"imagenes/";
//System.out.println("t"+t);
System.out.println("t"+url);
JFreeChart grafica=generaGrafico(generarDatos(circulacion, accidente, total, xlabels,dias),url);
ChartUtilities.writeChartAsJPEG(salida,grafica,100 0,600);
salida.close();
}catch(Exception e)
{
e.printStackTrace(System.out);
}
}
public DefaultCategoryDataset generarDatos(String circulacion, String accidente, String total, String xlabels,String dias)
{ String []circu=circulacion.split(",");
String []accid=accidente.split(",");
String []tota=total.split(",");
String []x_labels=xlabels.split(",");
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for(int i=0;i<x_labels.length;i++)
{ dataset.setValue(Double.valueOf(tota[i]).doubleValue(), "Total",x_labels[i]);
dataset.setValue(Double.valueOf(accid[i]).doubleValue(), "Accidente", x_labels[i]);
dataset.setValue(Double.valueOf(circu[i]).doubleValue(),"Circulacion", x_labels[i]);
}
return dataset;
}
public JFreeChart generaGrafico(DefaultCategoryDataset dataset,String url)
{
JFreeChart chart= ChartFactory.createLineChart("Cola de Retenciones", "Tiempo (Horas)",
"kilometro (km)", dataset, PlotOrientation.VERTICAL, true, true, true);
chart.setBackgroundPaint(Color.white);
salvaGraficoEnFichero(chart,url);
BasicStroke nuevo;
CategoryPlot plot= chart.getCategoryPlot ();
//COLOR DE FONDO DE LA IMAGEN
plot.setBackgroundPaint(Color.WHITE);
plot.getRenderer().setSeriesPaint(0, ChartColor.DARK_GREEN);
plot.getRenderer().setSeriesPaint(1, ChartColor.DARK_RED);
plot.getRenderer().setSeriesPaint(2, ChartColor.DARK_BLUE);
//STYLO DE LAS LINEAS
LineAndShapeRenderer lrenderer= (LineAndShapeRenderer) plot.getRenderer();
lrenderer.setStroke(new BasicStroke(4F, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL));
//PROPIEDADES DE EJE X
CategoryAxis ejex = plot.getDomainAxis();
ejex.setLabelPaint(Color.BLUE);
ejex.setAxisLinePaint(Color.BLUE);
//PROPIEDADES DEL EJE Y
NumberAxis ejey = (NumberAxis) plot.getRangeAxis();
ejey.setLabelPaint(Color.BLUE);
ejey.setAxisLinePaint(Color.BLUE);
return chart;
}
private void salvaGraficoEnFichero(JFreeChart chart, String ruta) {
try {
String tmpDir=ruta;
ChartUtilities.saveChartAsJPEG(new File(tmpDir+"grafico.jpg"), chart, 500, 800);
System.out.println("Salvada imagen en " + tmpDir +"grafico.jpg");
} catch (IOException e) {
System.err.println("Error creando grafico.");
}
}
}