Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart above grid lines in AChartEngine Bar Chart

In AChartEngine Bar Chart, is it possible that the bars are drawn over grid lines? How to do that? Currently grid lines are drawn over bars which make it a bit awkward.

Sample Image is attached below.enter image description here

like image 404
Fahad Abid Janjua Avatar asked Oct 04 '12 07:10

Fahad Abid Janjua


People also ask

How many types of gridlines are there for chart?

Grid lines come in two types: major and minor. Major grid lines separate the axis into major units. On category axes, major grid lines are the only grid lines available (you cannot show minor grid lines on a category axis.) On value axes, major grid lines are drawn for every major axis division.

What is gridlines in bar graph?

Gridlines extend from any horizontal and vertical axes across the plot area of the chart. You can also display depth gridlines in 3-D charts. Displayed for major and minor units, gridlines align with major and minor tick marks on the axes when tick marks are displayed.

How to remove lines from bar chart in excel?

Click the chart with the lines, and then click the Chart Design tab. Click Add Chart Element, click Gridlines, and then click More Gridline Options. Select No line. You can also click the line and press DELETE .

Should charts have gridlines?

Grid lines are rarely needed in graphs to help readers assign accurate numeric values to the data; the approximate values that can be perceived without the aid of grid lines are almost always adequate.


2 Answers

You cannot change which one is drawn first and which one next.

However, you can change the color of the grid lines. For instance, you can set a color that is a bit transparent, such as it doesn't really look like it is drawn above the bars.

like image 164
Dan D. Avatar answered Oct 20 '22 05:10

Dan D.


Even tough this is not a perfect answer, it is possible to achieve that behaviour, by making some changes to the method 'draw' of the class XYChart.

I am not sure this will not cause any other issues, but for me it has been working. Basically the idea consists in drawing the labels and grid before drawing the chart line.

I moved all the code starting and ending in:

        boolean showLabels = mRenderer.isShowLabels() && hasValues;
        ...
           drawText(canvas, mRenderer.getChartTitle(), x + size, top + height / 2, paint, 0);
         }
        }

to before this line:

boolean hasValues = false;

Also, I commented the && hasValues part. Note that this is definitely not reliable code, just a slight hack.

like image 44
dwbrito Avatar answered Oct 20 '22 07:10

dwbrito