Grafica plot not displaying in G4P window

Hello, hope you doing all well, i have a problem regarding grafica plot, well first of all i did multiple windows using G4P, everything just works fine, i then added a button “lancer mesures” which on click will trigger a new window calle “Suivi mesures”

public void Lancer_mesures_click(GButton source, GEvent event) {

  Suivi_mesures = GWindow.getWindow(this, "Suivi des mesures", 0, 0, 1000, 600, JAVA2D);
  Suivi_mesures.noLoop();
  Suivi_mesures.setActionOnClose(G4P.CLOSE_WINDOW);
  Suivi_mesures.addDrawHandler(this, "Suivi_mesures_draw");


  Filtres_label = new GLabel(Suivi_mesures, 459, 8, 80, 20);
  Filtres_label.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
  Filtres_label.setText("Filtres");
  Filtres_label.setOpaque(false);

 Suivi_mesures.loop();
 }

this works, but i want to also add a plot in that window too, so i tried :

public void Lancer_mesures_click(GButton source, GEvent event) {

  Suivi_mesures = GWindow.getWindow(this, "Suivi des mesures", 0, 0, 1000, 600, JAVA2D);
  Suivi_mesures.noLoop();
  Suivi_mesures.setActionOnClose(G4P.CLOSE_WINDOW);
  Suivi_mesures.addDrawHandler(this, "Suivi_mesures_draw");

  plot = new GPlot(this); 
  plot.setPos(50, 50);
  plot.setDim(900, 500);
  plot.setTitleText("Suivi des mesures");
  plot.getXAxis().setAxisLabelText("X Axis");
  plot.getYAxis().setAxisLabelText("Y Axis");

  // Add some sample points to the plot
  plot.setPoints(createSamplePoints());

  Filtres_label = new GLabel(Suivi_mesures, 459, 8, 80, 20);
  Filtres_label.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
  Filtres_label.setText("Filtres");
  Filtres_label.setOpaque(false);

 Suivi_mesures.loop();
 }

the function then to draw it is added here :

void Suivi_mesures_draw(PApplet app, GWinData data) {
  if (isPlotInitialized) {
    app.background(255);
    println("Drawing plot"); // Debug statement
    plot.beginDraw();
    plot.drawBackground();
    plot.drawBox();
    plot.drawXAxis();
    plot.drawYAxis();
    plot.drawTitle();
    plot.drawPoints();
    plot.endDraw();
  }
}

i m getting no error but also i have no rplot rendering ? can ayone explain and thanks !

Hello @hakim,

Welcome.

Please read:

There is a section in there on how to format your code.

:)

done, thanks for the feedback and i hope it s more coherent now , tell me if i need to change anything

1 Like

Ok I can’t test your code because it is not all there but based on what there is I suggest changing the line
plot = new GPlot(this);
to
plot = new GPlot(Suivi_mesures);
and see if this fixes the problem. Let us know wht happens :smile:

PS welcome to the forum :grin:

1 Like

thanks, it worked ! i m huge fan of your work, it really made it easy doing all GUI especially with the builder, just one tiny question about the graph, my goal was to plot real time data that i get from arduino sensors, so i will just need to feed the data coming from this function :

void serialEvent(Serial myPort) {
  String msg = myPort.readStringUntil('\n'); 
  if (msg != null) {
     println(msg);              // Print the received message
                               //extractAndWriteData(msg, selectedMode); 
   }
}` to this line `// Add some sample points to the plot
  plot.setPoints(createSamplePoints());

no need to change anything else? ( i mean i will just need to modify the createSamplePoints to extract data from the serial port and return Gpoints array? ) and thanks a lot !