开发者

How do I set grid depth\z-index of achartengine in Android?

开发者 https://www.devze.com 2023-04-11 09:16 出处:网络
Still having a great time fiddling with aChartEngine, but I have come to a point where I could some help.

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 far I haven't found any optio开发者_StackOverflow中文版ns in both the regular documentation as in the source to set the this.

Does anyone has a tip or solution regarding the grids in aChartEngine?

Thanks for your help!


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号