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

拥有回忆 提交于 2019-12-11 05:10:36

问题


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 options 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!


回答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!



来源:https://stackoverflow.com/questions/7675208/how-do-i-set-grid-depth-z-index-of-achartengine-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!