Skip to content Skip to sidebar Skip to footer

How Do I Set Grid Depth\z-index Of Achartengine In Android?

Still having a great time fiddling with aChartEngine, but I have come to a point where I could some help. I'm looking to change the depth or z-index of the grid of a chart. But so

Solution 1:

I guess nobody has this issue, but just in case you might wonder how to change the depth of the grids in aChartEngine, I'll write it down here.

By default all the grids of aChartEngine are drawn on top of the graph itself. This happens in the public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint) of the XYChart.java class.

Both the labels and grids are drawn in the same conditional, which checks whether (showLabels == true || showGrid == true)

First thing you might want to do is split the drawing of the labels and grid. Here's what I did:

  1. Copy the whole conditional which checks for labels and grid, including the declaration of the 3 booleans showLabels, showGrid and showCustomTextGrid.

  2. Paste it below boolean hasValues = false; (set this to true)

  3. You'll have some errors in the class now, because of double declarations. Fix that later.

  4. In the conditional you just pasted, remove the code to draw the labels. It's easy to find, since it starts with if (showLabels). Below the conditional set hasValues = false;

  5. In the original conditional, remove the code to draw the grid. It's easy to find, since it starts with if (showGrid)

  6. Now get rid of the double declarations, by setting the booleans showLabels, showGrid and showCustomTextGrid, or just use the old ones.

  7. All the errors should be gone now, test your app. The labels and grid are now separated and the grid is shown behind your graph instead on top of it.

Hope it helps you.

Cheers!

Post a Comment for "How Do I Set Grid Depth\z-index Of Achartengine In Android?"