Skip to content

Commit fa9ef73

Browse files
Grant Kaminghannesa2
Grant Kaming
authored andcommitted
Fix Drawable LineChart Fill Bug
The LineChart fill draws using intervals to avoid memory issues, but with a larger data set and many different (darker) colors Android does not draw the drawable all the way to the edge of the interval. This makes it look like there are spaces between the fill. Draw a little beyond the existing interval so there are no gaps. PhilJay#5284
1 parent 40223e2 commit fa9ef73

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,14 +462,25 @@ protected void drawLinearFill(Canvas c, ILineDataSet dataSet, Transformer trans,
462462
do {
463463
currentStartIndex = startingIndex + (iterations * indexInterval);
464464
currentEndIndex = currentStartIndex + indexInterval;
465-
currentEndIndex = currentEndIndex > endingIndex ? endingIndex : currentEndIndex;
465+
currentEndIndex = Math.min(currentEndIndex, endingIndex);
466466

467467
if (currentStartIndex <= currentEndIndex) {
468-
generateFilledPath(dataSet, currentStartIndex, currentEndIndex, filled);
468+
final Drawable drawable = dataSet.getFillDrawable();
469+
470+
int startIndex = currentStartIndex;
471+
int endIndex = currentEndIndex;
472+
473+
// Add a little extra to the path for drawables, larger data sets were showing space between adjacent drawables
474+
if (drawable != null) {
475+
476+
startIndex = Math.max(0, currentStartIndex - 1);
477+
endIndex = Math.min(endingIndex, currentEndIndex + 1);
478+
}
479+
480+
generateFilledPath(dataSet, startIndex, endIndex, filled);
469481

470482
trans.pathValueToPixel(filled);
471483

472-
final Drawable drawable = dataSet.getFillDrawable();
473484
if (drawable != null) {
474485

475486
drawFilledPath(c, filled, drawable);

0 commit comments

Comments
 (0)