Java - Actualizar serie JFreeChart

 
Vista:

Actualizar serie JFreeChart

Publicado por Mario (1 intervención) el 19/09/2006 11:40:12
Hola, tengo una gráfica sencilla implementada con el JFreeChart con unos datos ya introducidos. En un momento dado quiero agregar un nuevo dato y no soy capaz de que se actualice la gráfica. ¿Sabeis cómo hacerlo? Adjunto el código de la gráfica actual, la idea sería añadir un método para meter un nuevo dato de la serie y que la gráfica se repintase.
Gracias.

public class ventanaGrafica extends java.awt.Frame {

BufferedImage grafica = null;

/** Creates new form ventanaGrafica */
public ventanaGrafica() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {

addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});

pack();
}

/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {

ventanaGrafica miventana = new ventanaGrafica();
miventana.setSize(400,400);
miventana.show();
}

public BufferedImage creaImagen()
{
XYSeries series = new XYSeries("Evolucion");
series.add(1, 23);
series.add(2, 34);
series.add(3, 51);
series.add(4, 67);
series.add(5, 89);
series.add(6, 121);
series.add(7, 137);
XYDataset juegoDatos= new XYSeriesCollection(series);

JFreeChart chart =
ChartFactory.createXYLineChart("Demanda",
"Meses","Sesiones",juegoDatos,PlotOrientation.VERTICAL,
false,
false,
true // Show legend
);

BufferedImage image = chart.createBufferedImage(300,300);
return image;
}

public void paint(java.awt.Graphics g) {
//super.paint(g);

if(grafica == null)
{
grafica = this.creaImagen();
}
g.drawImage(grafica,30,30,null);
}

}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder