Skip to content

Commit 978201c

Browse files
committed
Fixed dashed line issue on x-axis grid (issue PhilJay#755).
1 parent 9db1b2f commit 978201c

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public void renderGridLines(Canvas c) {
163163
if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled())
164164
return;
165165

166+
// pre alloc
166167
float[] position = new float[] {
167168
0f, 0f
168169
};
@@ -171,18 +172,24 @@ public void renderGridLines(Canvas c) {
171172
mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());
172173
mGridPaint.setPathEffect(mXAxis.getGridDashPathEffect());
173174

175+
Path gridLinePath = new Path();
176+
174177
for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) {
175178

176179
position[0] = i;
177-
178180
mTrans.pointValuesToPixel(position);
179181

180182
if (position[0] >= mViewPortHandler.offsetLeft()
181183
&& position[0] <= mViewPortHandler.getChartWidth()) {
182184

183-
c.drawLine(position[0], mViewPortHandler.offsetTop(), position[0],
184-
mViewPortHandler.contentBottom(), mGridPaint);
185+
gridLinePath.moveTo(position[0], mViewPortHandler.contentBottom());
186+
gridLinePath.lineTo(position[0], mViewPortHandler.contentTop());
187+
188+
// draw a path because lines don't support dashing on lower android versions
189+
c.drawPath(gridLinePath, mGridPaint);
185190
}
191+
192+
gridLinePath.reset();
186193
}
187194
}
188195

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ public void renderGridLines(Canvas c) {
253253
gridLinePath.lineTo(mViewPortHandler.contentRight(),
254254
position[1]);
255255

256+
// draw a path because lines don't support dashing on lower android versions
256257
c.drawPath(gridLinePath, mGridPaint);
257258

258259
gridLinePath.reset();

0 commit comments

Comments
 (0)