2

I'm using AndroidPlot 0.61. I want to make a graph with round-number gridlines, much the same way as Desmos Calculator (online), but sub-grid-lines are not necessary. I'm currently using INCREMENT_BY_VALUE with a custom function to calculate the best grid spacing. Unfortunately, the gridlines begin at the origin, and each line is (origin + n*mod) instead of (n*mod). How do I make gridlines all multiples of an absolute value?

(An extension of this question is how to make gridlines scroll with the graph and change sizes when it's zoomed. It's related in concept to this question How to make domain grid line scroll, but I refuse to believe that the two most popular graphing frameworks on Android are both blatantly omitting such an essential feature).

nyanpasu64
  • 2,805
  • 2
  • 23
  • 31

2 Answers2

1

You found the answer yourself without knowing:

"the gridlines begin at the origin"

so just set the origin to any value you like by

setUserDomainOrigin()    and    setUserRangeOrigin()

and the grid will be calculated and drawn in relation to this User chosen origin.

Jantlem
  • 331
  • 2
  • 9
0

I'm afraid I'm not completely tracking the first half of your question. Gridlines are calculated relative to the origin but you can set the origin to be anything you want. If you want your gridlines to be multiples of an absolute value and you are stepping via INCREMENT_BY_VALUE then why not just set your origin to one of those multiples?

Regarding the second part of your question about making gridlines scroll: If you manually set the userDomainOrigin instead of allowing it to "float" with the data and then adjust your domain boundaries as necessary, you should get the desired effect. The thing to keep in mind is that the grid is drawn relative to the origin so if you let it float with your boundaries (default behavior) then the grid will appear to be fixed.

To illustrate, if you add the below code to the end of onCreate(...) in the DemoApp's SimpleXYPlotActivity the grid will scroll from right to left in increments of 0.1 at a frequency of 1hz:

plot.setUserDomainOrigin(0);
new Thread(new Runnable() {
    float offset = 0.1f;
    float window = 6f;
    @Override
    public void run() {
        try {
            while(true) {
                Thread.sleep(1000);                        
                plot.setDomainBoundaries(offset, offset + window, BoundaryMode.FIXED);
                plot.redraw();
                offset+= 0.1f;
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}).start();
Nick
  • 8,181
  • 4
  • 38
  • 63