MikroC, Drawing line graph

352 views Asked by At

I'm trying to create a function that will draw a line graph within a specific window on a GLCD screen.

Lets say that the window's x-axle runs from pixel 24 through 205 (left to right) and the y-axle runs from pixel 55 through 5 (low to high).

I'll simply need the graph to add a new value (or dot) whenever new data is available. So I can call the graph refreshing within the data collection routine. Thats no problem.

The latest value always needs to be added to the most right position on the graph, which is 205. So I will need to clear that line and a draw a new value/dot. Also no problem.

T6963C_line(205, 5, 205, 55, T6963C_BLACK); //Clearing the whole line
T6963C_dot(205, posy, T6963C_WHITE);        //Drawing new dot

But what I'm not sure about is, how to shift all the previous values/dots one place to left on refreshing (each time a new value/dot is added on x-position 205), until it reaches the border of the window, which is 22.

Any help would be greatly appriciated!

ADDITION:

int posy1[181];
int i1;

 for(i1 = 0; i1 < 181 - 1; i1++)
 {
     T6963C_dot(i1 + 24, posy1[i1], T6963C_BLACK); //Erase old dots
 }
 for(i1 = 0; i1 < 181 - 1; i1++)
 {
     posy1[i1] = posy1[i1 + 1]; //Shift array
 }
 posy1[181] = EQ; //Add new value (EQ) to array
 for(i1 = 0; i1 < 181 - 1; i1++)
 {
     T6963C_dot(i1 + 24, posy1[i1], T6963C_WHITE); //Redraw dots
 }
1

There are 1 answers

2
Jongware On

Create an array of the width of your data, and store the y values in there. Then, on adding a new value, erase the previous dots, shift values in your array one position down, and redraw them. Finally, add the y position of the new dot at the end of your array.

This is the general idea; there are lots of optimizations possible. To erase a dot on a known y position, you don't have to draw a vertical line -- plotting a single black dot over it is enough. Also, you don't have to physically copy every plot[x+1] to plot[x] -- you can leave the array as it is and just update an offset index modulus data width.