puzii
puzii

Reputation: 117

Androidplot: Create a square plot area

In Androidplot, I need to create a square plot area. i.e. the actual plot area not the graph area. This is so that the scale on both axis are the same i.e. the distance between two grid points on the x-axis is the same as the y-axis. I hope this makes sense.

In Androidplot I can set the graph area size using:

    final Size sm = new Size(900, SizeLayoutType.ABSOLUTE, 900, SizeLayoutType.ABSOLUTE);
    myPositionLines.getGraphWidget().setSize(sm);

But then how do I ensure that the plot area comes out also 'square'. I have made sure all margins/paddings are set to zero...

Would there be something like this ... myPlot.setPlotSize()...

Please help!

Upvotes: 0

Views: 176

Answers (1)

Nick
Nick

Reputation: 8317

There are several factors involved here. As you noted, theres a difference between the plot (the actual View element that Android positions) and the graph widget (the area inside of the plot View that visually represents the graph portion of the plot.)

It sounds like you've got the View part covered so I'll focus only on the graph widget piece. The first thing you need to do is set the size and orientation of the graph widget inside of the plot. Take a look at the X/Y Positioning Widgets and Sizing Widgets sections of the Styling Your Plot doc. You can get a handle to the graph widget by invoking plot.getGraphWidget().

The next step is to decide how to subdivide the graph area for drawing; this is what determines how many lines are visible and how many units each tick along the domain or range axis represents. You do this by setting boundaries. For example:

plot.setDomainBoundaries(0, 10, BoundaryMode.FIXED);
plot.setRangeBoundaries(0, 0, BoundaryMode.FIXED);

This subdivides the graph area into a 10x10 grid. The BoundaryMode.FIXED portion tells Androidplot not to auto-frame the data being plotted, which it tries to do by default.

Upvotes: 1

Related Questions