How to scroll a graph pixel by pixel on LCD st7920

When graph shall print to pixelpos 119 I want the graph to scroll one pixel left and put the last value in pos 119, but it always moves 8 pixels at a time with the last value as a 8-pixel line.
In the serial monitor I can see that there is a loop going 8 times with the values moving to the left before the drawpixel command. Why this loop ? And how can I just take the first loop-values ??
I use a DHT22 sensor on pin 2 and the LCD in serial.

if (y == 119) {

    for (x = 9; x < 119; x++) {

      hum[x] = hum[x + 1];
      temp[x] = temp[x + 1];

      if (hum[x] > maxVal) {
        hum[x] = maxVal;
      }
     // Serial.print (x) ; Serial.println(hum[x]);  Just to test
          
      u8g.drawPixel((x), (64 - hum[x] / 1.6));
      u8g.drawPixel((x), (64 - temp[x] / 1.6));
    }
  }
  else {
    for (x = 9; x < 119; x++) {

      if (hum[x] > maxVal) {
        hum[x] = maxVal;
      }
      //Serial.print (x) ; Serial.println(hum[x]);

      u8g.drawPixel((x), (64 - hum[x] / 1.6));
      u8g.drawPixel((x), (64 - temp[x] / 1.6));
    }
  }
  1. What I would consider is to implement a circular buffer for the measurements.
    That way I never need to shift them. just update an index

  2. I would allways draw the latest value at 119, that means always shift the whole screen

for (i=0...N-1)
{
   remove line[i]
   line[i] = line [i+1]
}
draw line 119

This way every new value is handled in an indentical manner.
no special cases to handle == shorter code == easier to understand.

Here is a picture of my graph. It draws pixels one by one and when it reaches the right edge of the frame (x pos 119) I want it to scroll one pixel left and draw the next pixel at x_pos 119. The frame is at pos 120. First graph pixel is at pos 9.

OK, algorithm is still same.

OK. Know nothing about circular buffer but, found an example sketch I shall try to use. Thanks!

I’ve solved my problem with this library :#include <U8g2lib.h>

and this constructor with a frame buffer :

U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=/ 13, / data=/ 11, / CS=/ 10, /

reset=*/ U8X8_PIN_NONE);

and I used this command :

u8g2.clearBuffer();

draw();

u8g2.sendBuffer();