Skip to content

Commit

Permalink
Update BarChartRenderer, Fill
Browse files Browse the repository at this point in the history
  • Loading branch information
Viet Duong committed Mar 5, 2020
1 parent e9007c1 commit b216e40
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.RectF;
import android.net.Uri;
import android.os.Bundle;
Expand Down Expand Up @@ -160,7 +161,7 @@ private void setData(int count, float range) {
chart.notifyDataSetChanged();

} else {
set1 = new BarDataSet(values, "The year 2017");
set1 = new BarDataSet(values, "The year 2020");

set1.setDrawIcons(false);

Expand All @@ -181,7 +182,7 @@ private void setData(int count, float range) {
gradientFills.add(new Fill(startColor3, endColor3));
gradientFills.add(new Fill(startColor4, endColor4));
gradientFills.add(new Fill(startColor5, endColor5));

gradientFills.add(new Fill(Color.TRANSPARENT, Color.BLACK));
set1.setFills(gradientFills);

ArrayList<IBarDataSet> dataSets = new ArrayList<>();
Expand All @@ -191,6 +192,11 @@ private void setData(int count, float range) {
data.setValueTextSize(10f);
data.setValueTypeface(tfLight);
data.setBarWidth(0.9f);
chart.setDrawBarShadow(true);
data.setRoundedBarCorners(true);
data.setCornerRadius(50);
data.setVerticalLineColor(Color.BLACK);
data.setDrawVerticalLine(true);

chart.setData(data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;

Expand Down Expand Up @@ -167,22 +168,40 @@ protected void drawDataSet(Canvas c, IBarDataSet dataSet, int index) {
}

if (isRoundedBarCorners) {

float cornerRadius = barData.getCornerRadius();

if (isCustomFill) {
dataSet.getFill(pos).fillRoundRect(c,
mRenderPaint,
buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3],
cornerRadius);
} else {
c.drawRoundRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3],
cornerRadius, cornerRadius, mRenderPaint);
}

/*
int startColor = barData.getStartColor();
int endColor = barData.getEndColor();
float cornerRadius = barData.getCornerRadius();
Rect rect = c.getClipBounds();
mRenderPaint.setShader(new LinearGradient(
buffer.buffer[j],
buffer.buffer[j + 3],
buffer.buffer[j],
LinearGradient gradient = new LinearGradient(
rect.left,
rect.bottom,
rect.left,
buffer.buffer[j + 1],
startColor,
endColor,
android.graphics.Shader.TileMode.MIRROR));
Path path2 = roundRect(new RectF(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2],
buffer.buffer[j + 3]), cornerRadius, cornerRadius, true, true, false, false);
c.drawPath(path2, mRenderPaint);
android.graphics.Shader.TileMode.MIRROR);
mRenderPaint.setShader(gradient);
c.drawRoundRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3],
cornerRadius, cornerRadius, mRenderPaint); */

} else {

if (isCustomFill) {
dataSet.getFill(pos).fillRect(
c, mRenderPaint,
Expand Down
Loading

0 comments on commit b216e40

Please sign in to comment.