Skip to content

Commit ebb1468

Browse files
committed
Added feature that allows to set the grid-line width for each axis.
1 parent 0a00522 commit ebb1468

8 files changed

Lines changed: 32 additions & 0 deletions

File tree

-533 KB
Binary file not shown.

MPChartExample/project.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212

1313
# Project target.
1414
target=android-19
15+
android.library.reference.1=../MPChartLib

MPChartLib/src/com/github/mikephil/charting/components/AxisBase.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public abstract class AxisBase extends ComponentBase {
1414

1515
private int mGridColor = Color.GRAY;
1616

17+
private float mGridLineWidth = 1f;
18+
1719
private int mAxisLineColor = Color.GRAY;
1820

1921
private float mAxisLineWidth = 1f;
@@ -108,6 +110,26 @@ public float getAxisLineWidth() {
108110
return mAxisLineWidth;
109111
}
110112

113+
/**
114+
* Sets the width of the grid lines that are drawn away from each axis
115+
* label.
116+
*
117+
* @param width
118+
*/
119+
public void setGridLineWidth(float width) {
120+
mGridLineWidth = Utils.convertDpToPixel(width);
121+
}
122+
123+
/**
124+
* Returns the width of the grid lines that are drawn away from each axis
125+
* label.
126+
*
127+
* @return
128+
*/
129+
public float getGridLineWidth() {
130+
return mGridLineWidth;
131+
}
132+
111133
/**
112134
* Sets the color of the border surrounding the chart.
113135
*

MPChartLib/src/com/github/mikephil/charting/renderer/XAxisRenderer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public void renderGridLines(Canvas c) {
164164
};
165165

166166
mGridPaint.setColor(mXAxis.getGridColor());
167+
mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());
167168

168169
for (int i = 0; i < mXAxis.getValues().size(); i += mXAxis.mAxisLabelModulus) {
169170

MPChartLib/src/com/github/mikephil/charting/renderer/XAxisRendererBarChart.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public void renderGridLines(Canvas c) {
8686
float[] position = new float[] {
8787
0f, 0f
8888
};
89+
90+
mGridPaint.setColor(mXAxis.getGridColor());
91+
mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());
8992

9093
BarData bd = mChart.getData();
9194
// take into consideration that multiple DataSets increase mDeltaX

MPChartLib/src/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ public void renderGridLines(Canvas c) {
117117
float[] position = new float[] {
118118
0f, 0f
119119
};
120+
121+
mGridPaint.setColor(mXAxis.getGridColor());
122+
mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());
120123

121124
BarData bd = mChart.getData();
122125
// take into consideration that multiple DataSets increase mDeltaX

MPChartLib/src/com/github/mikephil/charting/renderer/YAxisRenderer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ public void renderGridLines(Canvas c) {
245245
float[] position = new float[2];
246246

247247
mGridPaint.setColor(mYAxis.getGridColor());
248+
mGridPaint.setStrokeWidth(mYAxis.getGridLineWidth());
248249

249250
// draw the horizontal grid
250251
for (int i = 0; i < mYAxis.mEntryCount; i++) {

MPChartLib/src/com/github/mikephil/charting/renderer/YAxisRendererHorizontalBarChart.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public void renderGridLines(Canvas c) {
161161
float[] position = new float[2];
162162

163163
mGridPaint.setColor(mYAxis.getGridColor());
164+
mGridPaint.setStrokeWidth(mYAxis.getGridLineWidth());
164165

165166
// draw the horizontal grid
166167
for (int i = 0; i < mYAxis.mEntryCount; i++) {

0 commit comments

Comments
 (0)