Final fixes and improvements concerning zero line
This commit is contained in:
parent
661ed7dd70
commit
08dfebcc08
6 changed files with 54 additions and 3 deletions
|
@ -67,6 +67,8 @@ public class BarChartPositiveNegative extends DemoBase {
|
|||
left.setDrawAxisLine(false);
|
||||
left.setDrawGridLines(false);
|
||||
left.setDrawZeroLine(true); // draw a zero line
|
||||
left.setZeroLineColor(Color.GRAY);
|
||||
left.setZeroLineWidth(0.7f);
|
||||
mChart.getAxisRight().setEnabled(false);
|
||||
mChart.getLegend().setEnabled(false);
|
||||
|
||||
|
|
|
@ -133,6 +133,7 @@ public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListe
|
|||
leftAxis.setStartAtZero(false);
|
||||
//leftAxis.setYOffset(20f);
|
||||
leftAxis.enableGridDashedLine(10f, 10f, 0f);
|
||||
leftAxis.setDrawZeroLine(false);
|
||||
|
||||
// limit lines are drawn behind data (and not on top)
|
||||
leftAxis.setDrawLimitLinesBehindData(true);
|
||||
|
|
|
@ -123,6 +123,7 @@ public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListe
|
|||
rightAxis.setStartAtZero(false);
|
||||
rightAxis.setAxisMinValue(-200);
|
||||
rightAxis.setDrawGridLines(false);
|
||||
rightAxis.setDrawZeroLine(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.github.mikephil.charting.components;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import com.github.mikephil.charting.formatter.DefaultValueFormatter;
|
||||
|
@ -72,6 +73,16 @@ public class YAxis extends AxisBase {
|
|||
*/
|
||||
protected boolean mDrawZeroLine = true;
|
||||
|
||||
/**
|
||||
* Color of the zero line
|
||||
*/
|
||||
protected int mZeroLineColor = Color.GRAY;
|
||||
|
||||
/**
|
||||
* Width of the zero line in pixels
|
||||
*/
|
||||
protected float mZeroLineWidth = 1f;
|
||||
|
||||
/**
|
||||
* custom minimum value this axis represents
|
||||
*/
|
||||
|
@ -365,6 +376,32 @@ public class YAxis extends AxisBase {
|
|||
this.mDrawZeroLine = mDrawZeroLine;
|
||||
}
|
||||
|
||||
public int getZeroLineColor() {
|
||||
return mZeroLineColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the zero line
|
||||
*
|
||||
* @param color
|
||||
*/
|
||||
public void setZeroLineColor(int color) {
|
||||
mZeroLineColor = color;
|
||||
}
|
||||
|
||||
public float getZeroLineWidth() {
|
||||
return mZeroLineWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the width of the zero line in dp
|
||||
*
|
||||
* @param width
|
||||
*/
|
||||
public void setZeroLineWidth(float width) {
|
||||
this.mZeroLineWidth = Utils.convertDpToPixel(width);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is for normal (not horizontal) charts horizontal spacing.
|
||||
*
|
||||
|
|
|
@ -21,6 +21,8 @@ public class YAxisRenderer extends AxisRenderer {
|
|||
|
||||
protected YAxis mYAxis;
|
||||
|
||||
protected Paint mZeroLinePaint;
|
||||
|
||||
public YAxisRenderer(ViewPortHandler viewPortHandler, YAxis yAxis, Transformer trans) {
|
||||
super(viewPortHandler, trans);
|
||||
|
||||
|
@ -28,6 +30,11 @@ public class YAxisRenderer extends AxisRenderer {
|
|||
|
||||
mAxisLabelPaint.setColor(Color.BLACK);
|
||||
mAxisLabelPaint.setTextSize(Utils.convertDpToPixel(10f));
|
||||
|
||||
mZeroLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mZeroLinePaint.setColor(Color.GRAY);
|
||||
mZeroLinePaint.setStrokeWidth(1f);
|
||||
mZeroLinePaint.setStyle(Paint.Style.STROKE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -283,7 +290,7 @@ public class YAxisRenderer extends AxisRenderer {
|
|||
position[1] = 0f;
|
||||
mTrans.pointValuesToPixel(position);
|
||||
|
||||
drawZeroLine(c, mViewPortHandler.offsetLeft(), mViewPortHandler.contentRight(), position[1], position[1]);
|
||||
drawZeroLine(c, mViewPortHandler.offsetLeft(), mViewPortHandler.contentRight(), position[1]-1, position[1]-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,13 +305,16 @@ public class YAxisRenderer extends AxisRenderer {
|
|||
*/
|
||||
protected void drawZeroLine(Canvas c, float x1, float x2, float y1, float y2) {
|
||||
|
||||
mZeroLinePaint.setColor(mYAxis.getZeroLineColor());
|
||||
mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth());
|
||||
|
||||
Path zeroLinePath = new Path();
|
||||
|
||||
zeroLinePath.moveTo(x1, y1);
|
||||
zeroLinePath.lineTo(x2, y2);
|
||||
|
||||
// draw a path because lines don't support dashing on lower android versions
|
||||
c.drawPath(zeroLinePath, mGridPaint);
|
||||
c.drawPath(zeroLinePath, mZeroLinePaint);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -185,7 +185,7 @@ public class YAxisRendererHorizontalBarChart extends YAxisRenderer {
|
|||
position[0] = 0f;
|
||||
mTrans.pointValuesToPixel(position);
|
||||
|
||||
drawZeroLine(c, position[0], position[0], mViewPortHandler.contentTop(), mViewPortHandler.contentBottom());
|
||||
drawZeroLine(c, position[0]+1, position[0]+1, mViewPortHandler.contentTop(), mViewPortHandler.contentBottom());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue