Ver Mensaje Individual
  #4 (permalink)  
Antiguo 01/06/2010, 01:57
garaemon
 
Fecha de Ingreso: mayo-2010
Mensajes: 6
Antigüedad: 14 años
Puntos: 0
Respuesta: Graficas con JfreeChart

Buenas de nuevo!!

Mas o menos me enterado de como funciona todo esto pero ahora tengo un problemilla con la programación. Tengo implementado este codigo:

Cita:
public class Lineas {

DefaultTableModel resultado=null;
JList datos=null;
TimeSeries valores = new TimeSeries("Linea de Crecimiento", Day.class);

public Lineas(DefaultTableModel result, JList lDatosSeleccionados){
resultado=result;
datos=lDatosSeleccionados;
}

public void lanzar(){
valores=this.obtenerValores();
//dataset.addSeries(valores);
//Generate the graph
JFreeChart chart = ChartFactory.createXYLineChart("Crecimiento Ubuntu", // Title
"Tiempo", // x-axis Label
"Usuarios", // y-axis Label
(XYDataset) valores, // Dataset
PlotOrientation.VERTICAL, // Plot Orientation
true, // Show Legend
true, // Use tooltips
false // Configure chart to generate URLs?
);
//crear y visualizar una ventana...
ChartFrame frame = new ChartFrame("First", chart);
frame.pack();
frame.setVisible(true);
}

public TimeSeries obtenerValores(){
for (int i=0; i < resultado.getRowCount();i++){
System.out.println(resultado.getValueAt(i,3));
Object aux1 = resultado.getValueAt(i, 3);
java.math.BigDecimal granDecimal = (java.math.BigDecimal) aux1;
double cosa = (double)granDecimal.intValue();
RegularTimePeriod fecha= (RegularTimePeriod)resultado.getValueAt(i, 0);
valores.add(fecha,cosa);
}

return valores;
}
}
El problema es que me da este error en la linea que esta en negrita:
Cita:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String
at ordago.Lineas.obtenerValores(Lineas.java:80)
1
at ordago.Lineas.lanzar(Lineas.java:34)
at ordago.GenerarGrafica.actionPerformed(GenerarGrafi ca.java:34)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierar chy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Todo esto viene de:

Yo tengo una consulta sql realizada contra una base de datos y lo que quiero es que cogiendo dos columnas del resultado de esta me genere una gráfica de linea.


Necesito un poco de ayuda porque hasta el momento solo encuentro como hacer graficas metiendo los datos yo a mano pero no cogiendolos de otra parte.

Un saludo y gracias de antemano.

Última edición por garaemon; 02/06/2010 a las 01:19