# Grafica plot not displaying in G4P window

**URL:** <https://discourse.processing.org/t/grafica-plot-not-displaying-in-g4p-window/44491>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [May 27, 2024, 6:49am UTC](https://discourse.processing.org/t/grafica-plot-not-displaying-in-g4p-window/44491 "2024-05-27T06:49:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hakim](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hakim](https://discourse.processing.org/u/hakim)\
**Post date:** [May 27, 2024, 6:49am UTC](https://discourse.processing.org/t/grafica-plot-not-displaying-in-g4p-window/44491/1 "2024-05-27T06:49:25Z")

</div>

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”

```auto
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 :

```auto
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 :

```auto
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 !

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 27, 2024, 10:49am UTC](https://discourse.processing.org/t/grafica-plot-not-displaying-in-g4p-window/44491/2 "2024-05-27T10:49:52Z")

</div>

Hello @hakim,

Welcome.

Please read:

> [@Guidelines—Asking Questions](https://discourse.processing.org/t/guidelines-asking-questions/2147):
>
> Summary (TL;DR) Ask complete questions to get better answers! Be specific. For example: I want to load an image. I tried using createImg() , and I expected the image to be on canvas, but what happened instead was the image showing up below the canvas. Isolate your problem and work in small steps. Share only the code directly related to your problem if it is part of a bigger project, and if something isn’t working, try the smallest code that could do the thing you want. Can we run your code to …

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

`:)`

---

<div class="post-metadata">

**Author:** ![hakim](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hakim](https://discourse.processing.org/u/hakim)\
**Post date:** [May 27, 2024, 11:26am UTC](https://discourse.processing.org/t/grafica-plot-not-displaying-in-g4p-window/44491/3 "2024-05-27T11:26:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [May 27, 2024, 1:46pm UTC](https://discourse.processing.org/t/grafica-plot-not-displaying-in-g4p-window/44491/4 "2024-05-27T13:46:24Z")

</div>

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 😄

PS welcome to the forum 😁

---

<div class="post-metadata">

**Author:** ![hakim](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hakim](https://discourse.processing.org/u/hakim)\
**Post date:** [May 27, 2024, 2:06pm UTC](https://discourse.processing.org/t/grafica-plot-not-displaying-in-g4p-window/44491/5 "2024-05-27T14:06:29Z")

</div>

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 :

```auto
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 !
