This commit is contained in:
Philipp Jahoda 2016-01-24 22:41:42 +01:00
commit f09770df38
11 changed files with 120 additions and 19 deletions

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:startColor="#00ff0000"
android:endColor="#ffff0000" />
</shape>

View file

@ -3,7 +3,9 @@ package com.xxmassdeveloper.mpchartexample;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@ -358,11 +360,9 @@ public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListe
set1.setCircleRadius(3f);
set1.setDrawCircleHole(false);
set1.setValueTextSize(9f);
set1.setFillAlpha(65);
set1.setFillColor(Color.BLACK);
// set1.setDrawFilled(true);
// set1.setShader(new LinearGradient(0, 0, 0, mChart.getHeight(),
// Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
set1.setFillDrawable(drawable);
set1.setDrawFilled(true);
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(set1); // add the datasets

View file

@ -4,6 +4,7 @@ package com.github.mikephil.charting.data;
import android.content.Context;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
@ -42,6 +43,7 @@ public class LineDataSet extends LineRadarDataSet<Entry> implements ILineDataSet
private boolean mDrawCircleHole = true;
public LineDataSet(List<Entry> yVals, String label) {
super(yVals, label);

View file

@ -2,6 +2,7 @@
package com.github.mikephil.charting.data;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.interfaces.datasets.ILineRadarDataSet;
import com.github.mikephil.charting.utils.Utils;
@ -10,21 +11,34 @@ import java.util.List;
/**
* Base dataset for line and radar DataSets.
*
*
* @author Philipp Jahoda
*/
public abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandleRadarDataSet<T> implements ILineRadarDataSet<T> {
/** the color that is used for filling the line surface */
/**
* the color that is used for filling the line surface
*/
private int mFillColor = Color.rgb(140, 234, 255);
/** transparency used for filling line surface */
/**
* the drawable to be used for filling the line surface
*/
protected Drawable mFillDrawable;
/**
* transparency used for filling line surface
*/
private int mFillAlpha = 85;
/** the width of the drawn data lines */
/**
* the width of the drawn data lines
*/
private float mLineWidth = 2.5f;
/** if true, the data will also be drawn filled */
/**
* if true, the data will also be drawn filled
*/
private boolean mDrawFilled = false;
@ -38,12 +52,28 @@ public abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandl
}
/**
* sets the color that is used for filling the line surface
*
* Sets the color that is used for filling the area below the line.
* Resets an eventually set "fillDrawable".
*
* @param color
*/
public void setFillColor(int color) {
mFillColor = color;
mFillDrawable = null;
}
@Override
public Drawable getFillDrawable() {
return mFillDrawable;
}
/**
* Sets the drawable to be used to fill the area below the line.
*
* @param drawable
*/
public void setFillDrawable(Drawable drawable) {
this.mFillDrawable = drawable;
}
@Override
@ -54,7 +84,7 @@ public abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandl
/**
* sets the alpha value (transparency) that is used for filling the line
* surface (0-255), default: 85
*
*
* @param alpha
*/
public void setFillAlpha(int alpha) {
@ -64,7 +94,7 @@ public abstract class LineRadarDataSet<T extends Entry> extends LineScatterCandl
/**
* set the line width of the chart (min = 0.2f, max = 10f); default 1f NOTE:
* thinner line == better performance, thicker line == worse performance
*
*
* @param width
*/
public void setLineWidth(float width) {

View file

@ -1,6 +1,7 @@
package com.github.mikephil.charting.data.realm.base;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.interfaces.datasets.ILineRadarDataSet;
@ -18,6 +19,9 @@ public abstract class RealmLineRadarDataSet<T extends RealmObject> extends Realm
/** the color that is used for filling the line surface */
private int mFillColor = Color.rgb(140, 234, 255);
/** the drawable to be used for filling the line surface*/
protected Drawable mFillDrawable;
/** transparency used for filling line surface */
private int mFillAlpha = 85;
@ -81,6 +85,20 @@ public abstract class RealmLineRadarDataSet<T extends RealmObject> extends Realm
mFillColor = color;
}
@Override
public Drawable getFillDrawable() {
return mFillDrawable;
}
/**
* Sets the drawable to be used to fill the area below the line.
*
* @param drawable
*/
public void setFillDrawable(Drawable drawable) {
this.mFillDrawable = drawable;
}
@Override
public int getFillAlpha() {
return mFillAlpha;

View file

@ -3,6 +3,7 @@ package com.github.mikephil.charting.data.realm.implementation;
import android.content.Context;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet;
import com.github.mikephil.charting.formatter.DefaultFillFormatter;
@ -64,7 +65,6 @@ public class RealmLineDataSet<T extends RealmObject> extends RealmLineRadarDataS
private boolean mDrawCircleHole = true;
/**
* Constructor for creating a LineDataSet with realm data.
*

View file

@ -1,6 +1,7 @@
package com.github.mikephil.charting.interfaces.datasets;
import android.graphics.DashPathEffect;
import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.FillFormatter;
@ -81,4 +82,4 @@ public interface ILineDataSet extends ILineRadarDataSet<Entry> {
* @return
*/
FillFormatter getFillFormatter();
}
}

View file

@ -1,5 +1,7 @@
package com.github.mikephil.charting.interfaces.datasets;
import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.data.Entry;
/**
@ -14,6 +16,13 @@ public interface ILineRadarDataSet<T extends Entry> extends ILineScatterCandleRa
*/
int getFillColor();
/**
* Returns the drawable used for filling the area below the line.
*
* @return
*/
Drawable getFillDrawable();
/**
* Returns the alpha value that is used for filling the line surface,
* default: 85

View file

@ -5,6 +5,7 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.buffer.CircleBuffer;
@ -86,7 +87,7 @@ public class LineChartRenderer extends LineScatterCandleRadarRenderer {
if (width > 0 && height > 0) {
mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444));
mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565));
mBitmapCanvas = new Canvas(mDrawBitmap.get());
} else
return;
@ -126,6 +127,22 @@ public class LineChartRenderer extends LineScatterCandleRadarRenderer {
mRenderPaint.setPathEffect(null);
}
/**
* Draws the provided path in filled mode with the provided drawable.
*/
protected void drawFilledPath(Canvas c, Path filledPath, Drawable drawable) {
c.save();
c.clipPath(filledPath);
drawable.setBounds((int) mViewPortHandler.contentLeft(),
(int) mViewPortHandler.contentTop(),
(int) mViewPortHandler.contentRight(),
(int) mViewPortHandler.contentBottom());
drawable.draw(c);
c.restore();
}
/**
* Draws a cubic line.
*
@ -253,7 +270,14 @@ public class LineChartRenderer extends LineScatterCandleRadarRenderer {
trans.pathValueToPixel(spline);
drawFilledPath(c, spline, dataSet.getFillColor(), dataSet.getFillAlpha());
final Drawable drawable = dataSet.getFillDrawable();
if (dataSet.getFillDrawable() != null) {
drawFilledPath(c, spline, drawable);
} else {
drawFilledPath(c, spline, dataSet.getFillColor(), dataSet.getFillAlpha());
}
}
/**
@ -350,7 +374,14 @@ public class LineChartRenderer extends LineScatterCandleRadarRenderer {
trans.pathValueToPixel(filled);
drawFilledPath(c, filled, dataSet.getFillColor(), dataSet.getFillAlpha());
final Drawable drawable = dataSet.getFillDrawable();
if (drawable != null) {
drawFilledPath(c, filled, drawable);
} else {
drawFilledPath(c, filled, dataSet.getFillColor(), dataSet.getFillAlpha());
}
}
/**

View file

@ -93,6 +93,9 @@ Features
- **LineChart (cubic lines)**
![alt tag](https://raw.github.com/PhilJay/MPChart/master/screenshots/cubiclinechart.png)
- **LineChart (gradient fill)**
![alt tag](https://raw.github.com/PhilJay/MPChart/master/screenshots/line_chart_gradient.png)
- **Combined-Chart (bar- and linechart in this case)**
![alt tag](https://raw.github.com/PhilJay/MPChart/master/screenshots/combined_chart.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB