10 | * author : JinBiao 11 | * CSDN : http://my.csdn.net/DT235201314 12 | * time : 2017/08/16 13 | * desc : 用于横向柱状图数据 14 | * version: 1.0 15 | *16 | */ 17 | 18 | public class BarDataEntity implements Serializable{ 19 | private List
4 | * author : JinBiao 5 | * CSDN : http://my.csdn.net/DT235201314 6 | * time : 2017/04/05 7 | * desc :实体类 8 | * version: 1.0 9 | *10 | */ 11 | 12 | public class RealListEntity { 13 | private String year; 14 | private String month; 15 | private String amount; //销售数值 16 | 17 | public String getYear() { 18 | return year; 19 | } 20 | 21 | public void setYear(String year) { 22 | this.year = year; 23 | } 24 | 25 | public String getMonth() { 26 | return month; 27 | } 28 | 29 | public void setMonth(String month) { 30 | this.month = month; 31 | } 32 | 33 | public String getAmount() { 34 | return amount; 35 | } 36 | 37 | public void setAmount(String amount) { 38 | this.amount = amount; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/entity/SourceEntity.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.entity; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Random; 7 | 8 | 9 | /** 10 | * Created by chenjie05 on 2016/12/8. 11 | */ 12 | 13 | public class SourceEntity { 14 | public class Source{ 15 | private int allCount; 16 | private int badCount; 17 | private int goodCount; 18 | private int otherCount; 19 | private String source; 20 | private int scale; 21 | public float getAllCount() { 22 | return allCount; 23 | } 24 | 25 | public void setAllCount(int allCount) { 26 | this.allCount = allCount; 27 | } 28 | 29 | public int getBadCount() { 30 | return badCount; 31 | } 32 | 33 | public void setBadCount(int badCount) { 34 | this.badCount = badCount; 35 | } 36 | 37 | public int getGoodCount() { 38 | return goodCount; 39 | } 40 | 41 | public void setGoodCount(int goodCount) { 42 | this.goodCount = goodCount; 43 | } 44 | 45 | public int getOtherCount() { 46 | return otherCount; 47 | } 48 | 49 | public void setOtherCount(int otherCount) { 50 | this.otherCount = otherCount; 51 | } 52 | 53 | public int getScale() { 54 | return scale; 55 | } 56 | 57 | public void setScale(int scale) { 58 | this.scale = scale; 59 | } 60 | 61 | public String getSource() { 62 | return source; 63 | } 64 | 65 | public void setSource(String source) { 66 | this.source = source; 67 | } 68 | } 69 | private List
5 | * author : JinBiao 6 | * CSDN : http://my.csdn.net/DT235201314 7 | * time : 2017/04/05 8 | * desc :实体类 9 | * version: 1.0 10 | *11 | */ 12 | 13 | public class YoyListEntity { 14 | private String year; 15 | private String month; 16 | private String amount; //销售数值 17 | 18 | public String getYear() { 19 | return year; 20 | } 21 | 22 | public void setYear(String year) { 23 | this.year = year; 24 | } 25 | 26 | public String getMonth() { 27 | return month; 28 | } 29 | 30 | public void setMonth(String month) { 31 | this.month = month; 32 | } 33 | 34 | public String getAmount() { 35 | return amount; 36 | } 37 | 38 | public void setAmount(String amount) { 39 | this.amount = amount; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/exception/DrawingDataSetNotCreatedException.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.exception; 2 | 3 | public class DrawingDataSetNotCreatedException extends RuntimeException { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = 1L; 9 | 10 | public DrawingDataSetNotCreatedException() { 11 | super("Have to create a new drawing set first. Call ChartData's createNewDrawingDataSet() method"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/formatter/ColorFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.data.DataSet; 4 | import com.github.mikephil.charting.data.Entry; 5 | import com.github.mikephil.charting.interfaces.datasets.IDataSet; 6 | 7 | /** 8 | * Interface that can be used to return a customized color instead of setting 9 | * colors via the setColor(...) method of the DataSet. 10 | * 11 | * @author Philipp Jahoda 12 | */ 13 | public interface ColorFormatter { 14 | 15 | /** 16 | * Returns the color to be used for the given Entry at the given index (in the entries array) 17 | * 18 | * @param index index in the entries array 19 | * @param e the entry to color 20 | * @param set the DataSet the entry belongs to 21 | * @return 22 | */ 23 | int getColor(int index, Entry e, IDataSet set); 24 | } -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultAxisValueFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.components.AxisBase; 4 | 5 | import java.text.DecimalFormat; 6 | 7 | /** 8 | * Created by philipp on 02/06/16. 9 | */ 10 | public class DefaultAxisValueFormatter implements IAxisValueFormatter 11 | { 12 | 13 | /** 14 | * decimalformat for formatting 15 | */ 16 | protected DecimalFormat mFormat; 17 | 18 | /** 19 | * the number of decimal digits this formatter uses 20 | */ 21 | protected int digits = 0; 22 | 23 | /** 24 | * Constructor that specifies to how many digits the value should be 25 | * formatted. 26 | * 27 | * @param digits 28 | */ 29 | public DefaultAxisValueFormatter(int digits) { 30 | this.digits = digits; 31 | 32 | StringBuffer b = new StringBuffer(); 33 | for (int i = 0; i < digits; i++) { 34 | if (i == 0) 35 | b.append("."); 36 | b.append("0"); 37 | } 38 | 39 | mFormat = new DecimalFormat("###,###,###,##0" + b.toString()); 40 | } 41 | 42 | @Override 43 | public String getFormattedValue(float value, AxisBase axis) { 44 | // avoid memory allocations here (for performance) 45 | return mFormat.format(value); 46 | } 47 | 48 | /** 49 | * Returns the number of decimal digits this formatter uses or -1, if unspecified. 50 | * 51 | * @return 52 | */ 53 | public int getDecimalDigits() { 54 | return digits; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultFillFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | 4 | import com.github.mikephil.charting.data.LineData; 5 | import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider; 6 | import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; 7 | 8 | /** 9 | * Default formatter that calculates the position of the filled line. 10 | * 11 | * @author Philipp Jahoda 12 | */ 13 | public class DefaultFillFormatter implements IFillFormatter 14 | { 15 | 16 | @Override 17 | public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) { 18 | 19 | float fillMin = 0f; 20 | float chartMaxY = dataProvider.getYChartMax(); 21 | float chartMinY = dataProvider.getYChartMin(); 22 | 23 | LineData data = dataProvider.getLineData(); 24 | 25 | if (dataSet.getYMax() > 0 && dataSet.getYMin() < 0) { 26 | fillMin = 0f; 27 | } else { 28 | 29 | float max, min; 30 | 31 | if (data.getYMax() > 0) 32 | max = 0f; 33 | else 34 | max = chartMaxY; 35 | if (data.getYMin() < 0) 36 | min = 0f; 37 | else 38 | min = chartMinY; 39 | 40 | fillMin = dataSet.getYMin() >= 0 ? min : max; 41 | } 42 | 43 | return fillMin; 44 | } 45 | } -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultValueFormatter.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.formatter; 3 | 4 | import com.github.mikephil.charting.data.Entry; 5 | import com.github.mikephil.charting.utils.ViewPortHandler; 6 | 7 | import java.text.DecimalFormat; 8 | 9 | /** 10 | * Default formatter used for formatting values inside the chart. Uses a DecimalFormat with 11 | * pre-calculated number of digits (depending on max and min value). 12 | * 13 | * @author Philipp Jahoda 14 | */ 15 | public class DefaultValueFormatter implements IValueFormatter 16 | { 17 | 18 | /** 19 | * DecimalFormat for formatting 20 | */ 21 | protected DecimalFormat mFormat; 22 | 23 | protected int mDecimalDigits; 24 | 25 | /** 26 | * Constructor that specifies to how many digits the value should be 27 | * formatted. 28 | * 29 | * @param digits 30 | */ 31 | public DefaultValueFormatter(int digits) { 32 | setup(digits); 33 | } 34 | 35 | /** 36 | * Sets up the formatter with a given number of decimal digits. 37 | * 38 | * @param digits 39 | */ 40 | public void setup(int digits) { 41 | 42 | this.mDecimalDigits = digits; 43 | 44 | StringBuffer b = new StringBuffer(); 45 | for (int i = 0; i < digits; i++) { 46 | if (i == 0) 47 | b.append("."); 48 | b.append("0"); 49 | } 50 | 51 | mFormat = new DecimalFormat("###,###,###,##0" + b.toString()); 52 | } 53 | 54 | @Override 55 | public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { 56 | 57 | // put more logic here ... 58 | // avoid memory allocations here (for performance reasons) 59 | 60 | return mFormat.format(value); 61 | } 62 | 63 | /** 64 | * Returns the number of decimal digits this formatter uses. 65 | * 66 | * @return 67 | */ 68 | public int getDecimalDigits() { 69 | return mDecimalDigits; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IAxisValueFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.components.AxisBase; 4 | 5 | /** 6 | * Created by Philipp Jahoda on 20/09/15. 7 | * Custom formatter interface that allows formatting of 8 | * axis labels before they are being drawn. 9 | */ 10 | public interface IAxisValueFormatter 11 | { 12 | 13 | /** 14 | * Called when a value from an axis is to be formatted 15 | * before being drawn. For performance reasons, avoid excessive calculations 16 | * and memory allocations inside this method. 17 | * 18 | * @param value the value to be formatted 19 | * @param axis the axis the value belongs to 20 | * @return 21 | */ 22 | String getFormattedValue(float value, AxisBase axis); 23 | } 24 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IFillFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; 4 | import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider; 5 | 6 | /** 7 | * Interface for providing a custom logic to where the filling line of a LineDataSet 8 | * should end. This of course only works if setFillEnabled(...) is set to true. 9 | * 10 | * @author Philipp Jahoda 11 | */ 12 | public interface IFillFormatter 13 | { 14 | 15 | /** 16 | * Returns the vertical (y-axis) position where the filled-line of the 17 | * LineDataSet should end. 18 | * 19 | * @param dataSet the ILineDataSet that is currently drawn 20 | * @param dataProvider 21 | * @return 22 | */ 23 | float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider); 24 | } 25 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IValueFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.data.Entry; 4 | import com.github.mikephil.charting.utils.ViewPortHandler; 5 | 6 | /** 7 | * Interface that allows custom formatting of all values inside the chart before they are 8 | * being drawn to the screen. Simply create your own formatting class and let 9 | * it implement IValueFormatter. Then override the getFormattedValue(...) method 10 | * and return whatever you want. 11 | * 12 | * @author Philipp Jahoda 13 | */ 14 | public interface IValueFormatter 15 | { 16 | 17 | /** 18 | * Called when a value (from labels inside the chart) is formatted 19 | * before being drawn. For performance reasons, avoid excessive calculations 20 | * and memory allocations inside this method. 21 | * 22 | * @param value the value to be formatted 23 | * @param entry the entry the value belongs to - in e.g. BarChart, this is of class BarEntry 24 | * @param dataSetIndex the index of the DataSet the entry in focus belongs to 25 | * @param viewPortHandler provides information about the current chart state (scale, translation, ...) 26 | * @return the formatted label ready for being drawn 27 | */ 28 | String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler); 29 | } 30 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IndexAxisValueFormatter.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.formatter; 3 | 4 | import com.github.mikephil.charting.components.AxisBase; 5 | import com.github.mikephil.charting.data.Entry; 6 | import com.github.mikephil.charting.utils.ViewPortHandler; 7 | 8 | import java.text.DecimalFormat; 9 | import java.util.Arrays; 10 | import java.util.Collection; 11 | 12 | /** 13 | * This formatter is used for passing an array of x-axis labels, on whole x steps. 14 | */ 15 | public class IndexAxisValueFormatter implements IAxisValueFormatter 16 | { 17 | private String[] mValues = new String[] {}; 18 | private int mValueCount = 0; 19 | 20 | /** 21 | * An empty constructor. 22 | * Use `setValues` to set the axis labels. 23 | */ 24 | public IndexAxisValueFormatter() { 25 | } 26 | 27 | /** 28 | * Constructor that specifies axis labels. 29 | * 30 | * @param values The values string array 31 | */ 32 | public IndexAxisValueFormatter(String[] values) { 33 | if (values != null) 34 | setValues(values); 35 | } 36 | 37 | /** 38 | * Constructor that specifies axis labels. 39 | * 40 | * @param values The values string array 41 | */ 42 | public IndexAxisValueFormatter(Collection
设置bar宽度
76 | * @param barWidth float 77 | */ 78 | public void setBarWidth(float barWidth) { 79 | ((BarChart)mChart).getData().setBarWidth(barWidth); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/newchart/GroupBarChartEntity.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.newchart; 2 | 3 | 4 | 5 | import com.github.mikephil.charting.charts.BarChart; 6 | import com.github.mikephil.charting.charts.BarLineChartBase; 7 | import com.github.mikephil.charting.components.YAxis; 8 | import com.github.mikephil.charting.data.BarData; 9 | import com.github.mikephil.charting.data.BarDataSet; 10 | import com.github.mikephil.charting.data.BarEntry; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * 16 | * 组合柱状图 17 | * Created by jin 18 | */ 19 | 20 | public class GroupBarChartEntity extends BaseChartEntity设置bar宽度
61 | * @param barWidth float 62 | */ 63 | public void setBarWidth(float barWidth) { 64 | float groupSpace = 1f; 65 | float barSpace = 0.0f; // x2 dataset 66 | // float barWidth = 0.45f; // x2 dataset 67 | ((BarChart)mChart).getData().setBarWidth(barWidth); 68 | ((BarChart)mChart).getData().groupBars(0, groupSpace, barSpace); 69 | } 70 | 71 | public void setDrawValueAboveBar(boolean aboveBar) { 72 | ((BarChart)mChart).setDrawValueAboveBar(aboveBar); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/newchart/StackBarChartEntry.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.newchart; 2 | 3 | 4 | import com.github.mikephil.charting.charts.BarChart; 5 | import com.github.mikephil.charting.charts.BarLineChartBase; 6 | import com.github.mikephil.charting.components.YAxis; 7 | import com.github.mikephil.charting.data.BarData; 8 | import com.github.mikephil.charting.data.BarDataSet; 9 | import com.github.mikephil.charting.data.BarEntry; 10 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * 叠加柱状图 17 | * Created by jin 18 | */ 19 | public class StackBarChartEntry extends BaseChartEntity设置bar宽度
57 | * 58 | * @param barWidth float 59 | */ 60 | public void setBarWidth(float barWidth) { 61 | ((BarChart) mChart).getData().setBarWidth(barWidth); 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineRadarRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.renderer; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Paint; 5 | import android.graphics.Path; 6 | import android.graphics.drawable.Drawable; 7 | 8 | import com.github.mikephil.charting.animation.ChartAnimator; 9 | import com.github.mikephil.charting.utils.Utils; 10 | import com.github.mikephil.charting.utils.ViewPortHandler; 11 | 12 | /** 13 | * Created by Philipp Jahoda on 25/01/16. 14 | */ 15 | public abstract class LineRadarRenderer extends LineScatterCandleRadarRenderer { 16 | 17 | public LineRadarRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) { 18 | super(animator, viewPortHandler); 19 | } 20 | 21 | /** 22 | * Draws the provided path in filled mode with the provided drawable. 23 | * 24 | * @param c 25 | * @param filledPath 26 | * @param drawable 27 | */ 28 | protected void drawFilledPath(Canvas c, Path filledPath, Drawable drawable) { 29 | 30 | if (clipPathSupported()) { 31 | 32 | int save = c.save(); 33 | c.clipPath(filledPath); 34 | 35 | drawable.setBounds((int) mViewPortHandler.contentLeft(), 36 | (int) mViewPortHandler.contentTop(), 37 | (int) mViewPortHandler.contentRight(), 38 | (int) mViewPortHandler.contentBottom()); 39 | drawable.draw(c); 40 | 41 | c.restoreToCount(save); 42 | } else { 43 | throw new RuntimeException("Fill-drawables not (yet) supported below API level 18, " + 44 | "this code was run on API level " + Utils.getSDKInt() + "."); 45 | } 46 | } 47 | 48 | /** 49 | * Draws the provided path in filled mode with the provided color and alpha. 50 | * Special thanks to Angelo Suzuki (https://github.com/tinsukE) for this. 51 | * 52 | * @param c 53 | * @param filledPath 54 | * @param fillColor 55 | * @param fillAlpha 56 | */ 57 | protected void drawFilledPath(Canvas c, Path filledPath, int fillColor, int fillAlpha) { 58 | 59 | int color = (fillAlpha << 24) | (fillColor & 0xffffff); 60 | 61 | if (clipPathSupported()) { 62 | 63 | int save = c.save(); 64 | 65 | c.clipPath(filledPath); 66 | 67 | c.drawColor(color); 68 | c.restoreToCount(save); 69 | } else { 70 | 71 | // save 72 | Paint.Style previous = mRenderPaint.getStyle(); 73 | int previousColor = mRenderPaint.getColor(); 74 | 75 | // set 76 | mRenderPaint.setStyle(Paint.Style.FILL); 77 | mRenderPaint.setColor(color); 78 | 79 | c.drawPath(filledPath, mRenderPaint); 80 | 81 | // restore 82 | mRenderPaint.setColor(previousColor); 83 | mRenderPaint.setStyle(previous); 84 | } 85 | } 86 | 87 | /** 88 | * Clip path with hardware acceleration only working properly on API level 18 and above. 89 | * 90 | * @return 91 | */ 92 | private boolean clipPathSupported() { 93 | return Utils.getSDKInt() >= 18; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineScatterCandleRadarRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.renderer; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Path; 5 | 6 | import com.github.mikephil.charting.animation.ChartAnimator; 7 | import com.github.mikephil.charting.interfaces.datasets.ILineScatterCandleRadarDataSet; 8 | import com.github.mikephil.charting.utils.ViewPortHandler; 9 | 10 | /** 11 | * Created by Philipp Jahoda on 11/07/15. 12 | */ 13 | public abstract class LineScatterCandleRadarRenderer extends BarLineScatterCandleBubbleRenderer { 14 | 15 | /** 16 | * path that is used for drawing highlight-lines (drawLines(...) cannot be used because of dashes) 17 | */ 18 | private Path mHighlightLinePath = new Path(); 19 | 20 | public LineScatterCandleRadarRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) { 21 | super(animator, viewPortHandler); 22 | } 23 | 24 | /** 25 | * Draws vertical & horizontal highlight-lines if enabled. 26 | * 27 | * @param c 28 | * @param x x-position of the highlight line intersection 29 | * @param y y-position of the highlight line intersection 30 | * @param set the currently drawn dataset 31 | */ 32 | protected void drawHighlightLines(Canvas c, float x, float y, ILineScatterCandleRadarDataSet set) { 33 | 34 | // set color and stroke-width 35 | mHighlightPaint.setColor(set.getHighLightColor()); 36 | mHighlightPaint.setStrokeWidth(set.getHighlightLineWidth()); 37 | 38 | // draw highlighted lines (if enabled) 39 | mHighlightPaint.setPathEffect(set.getDashPathEffectHighlight()); 40 | 41 | // draw vertical highlight lines 42 | if (set.isVerticalHighlightIndicatorEnabled()) { 43 | 44 | // create vertical path 45 | mHighlightLinePath.reset(); 46 | mHighlightLinePath.moveTo(x, mViewPortHandler.contentTop()); 47 | mHighlightLinePath.lineTo(x, mViewPortHandler.contentBottom()); 48 | 49 | c.drawPath(mHighlightLinePath, mHighlightPaint); 50 | } 51 | 52 | // draw horizontal highlight lines 53 | if (set.isHorizontalHighlightIndicatorEnabled()) { 54 | 55 | // create horizontal path 56 | mHighlightLinePath.reset(); 57 | mHighlightLinePath.moveTo(mViewPortHandler.contentLeft(), y); 58 | mHighlightLinePath.lineTo(mViewPortHandler.contentRight(), y); 59 | 60 | c.drawPath(mHighlightLinePath, mHighlightPaint); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/renderer/Renderer.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.renderer; 3 | 4 | import com.github.mikephil.charting.utils.ViewPortHandler; 5 | 6 | /** 7 | * Abstract baseclass of all Renderers. 8 | * 9 | * @author Philipp Jahoda 10 | */ 11 | public abstract class Renderer { 12 | 13 | /** 14 | * the component that handles the drawing area of the chart and it's offsets 15 | */ 16 | protected ViewPortHandler mViewPortHandler; 17 | 18 | public Renderer(ViewPortHandler viewPortHandler) { 19 | this.mViewPortHandler = viewPortHandler; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererRadarChart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.renderer; 3 | 4 | import android.graphics.Canvas; 5 | import android.graphics.PointF; 6 | 7 | import com.github.mikephil.charting.charts.RadarChart; 8 | import com.github.mikephil.charting.components.XAxis; 9 | import com.github.mikephil.charting.utils.MPPointF; 10 | import com.github.mikephil.charting.utils.Utils; 11 | import com.github.mikephil.charting.utils.ViewPortHandler; 12 | 13 | public class XAxisRendererRadarChart extends XAxisRenderer { 14 | 15 | private RadarChart mChart; 16 | 17 | public XAxisRendererRadarChart(ViewPortHandler viewPortHandler, XAxis xAxis, RadarChart chart) { 18 | super(viewPortHandler, xAxis, null); 19 | 20 | mChart = chart; 21 | } 22 | 23 | @Override 24 | public void renderAxisLabels(Canvas c) { 25 | 26 | if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled()) 27 | return; 28 | 29 | final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle(); 30 | final MPPointF drawLabelAnchor = MPPointF.getInstance(0.5f, 0.25f); 31 | 32 | mAxisLabelPaint.setTypeface(mXAxis.getTypeface()); 33 | mAxisLabelPaint.setTextSize(mXAxis.getTextSize()); 34 | mAxisLabelPaint.setColor(mXAxis.getTextColor()); 35 | 36 | float sliceangle = mChart.getSliceAngle(); 37 | 38 | // calculate the factor that is needed for transforming the value to 39 | // pixels 40 | float factor = mChart.getFactor(); 41 | 42 | MPPointF center = mChart.getCenterOffsets(); 43 | MPPointF pOut = MPPointF.getInstance(0,0); 44 | for (int i = 0; i < mChart.getData().getMaxEntryCountSet().getEntryCount(); i++) { 45 | 46 | String label = mXAxis.getValueFormatter().getFormattedValue(i, mXAxis); 47 | 48 | float angle = (sliceangle * i + mChart.getRotationAngle()) % 360f; 49 | 50 | Utils.getPosition(center, mChart.getYRange() * factor 51 | + mXAxis.mLabelRotatedWidth / 2f, angle, pOut); 52 | 53 | drawLabel(c, label, pOut.x, pOut.y - mXAxis.mLabelRotatedHeight / 2.f, 54 | drawLabelAnchor, labelRotationAngleDegrees); 55 | } 56 | 57 | MPPointF.recycleInstance(center); 58 | MPPointF.recycleInstance(pOut); 59 | MPPointF.recycleInstance(drawLabelAnchor); 60 | } 61 | 62 | /** 63 | * XAxis LimitLines on RadarChart not yet supported. 64 | * 65 | * @param c 66 | */ 67 | @Override 68 | public void renderLimitLines(Canvas c) { 69 | // this space intentionally left blank 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/ChevronDownShapeRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.renderer.scatter; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Paint; 5 | 6 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; 7 | import com.github.mikephil.charting.utils.Utils; 8 | import com.github.mikephil.charting.utils.ViewPortHandler; 9 | 10 | /** 11 | * Created by wajdic on 15/06/2016. 12 | * Created at Time 09:08 13 | */ 14 | public class ChevronDownShapeRenderer implements IShapeRenderer 15 | { 16 | 17 | 18 | @Override 19 | public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, 20 | float posX, float posY, Paint renderPaint) { 21 | 22 | final float shapeHalf = dataSet.getScatterShapeSize() / 2f; 23 | 24 | renderPaint.setStyle(Paint.Style.STROKE); 25 | renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f)); 26 | 27 | c.drawLine( 28 | posX, 29 | posY + (2 * shapeHalf), 30 | posX + (2 * shapeHalf), 31 | posY, 32 | renderPaint); 33 | 34 | c.drawLine( 35 | posX, 36 | posY + (2 * shapeHalf), 37 | posX - (2 * shapeHalf), 38 | posY, 39 | renderPaint); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/ChevronUpShapeRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.renderer.scatter; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Paint; 5 | 6 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; 7 | import com.github.mikephil.charting.utils.Utils; 8 | import com.github.mikephil.charting.utils.ViewPortHandler; 9 | 10 | /** 11 | * Created by wajdic on 15/06/2016. 12 | * Created at Time 09:08 13 | */ 14 | public class ChevronUpShapeRenderer implements IShapeRenderer 15 | { 16 | 17 | 18 | @Override 19 | public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, 20 | float posX, float posY, Paint renderPaint) { 21 | 22 | final float shapeHalf = dataSet.getScatterShapeSize() / 2f; 23 | 24 | renderPaint.setStyle(Paint.Style.STROKE); 25 | renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f)); 26 | 27 | c.drawLine( 28 | posX, 29 | posY - (2 * shapeHalf), 30 | posX + (2 * shapeHalf), 31 | posY, 32 | renderPaint); 33 | 34 | c.drawLine( 35 | posX, 36 | posY - (2 * shapeHalf), 37 | posX - (2 * shapeHalf), 38 | posY, 39 | renderPaint); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/CircleShapeRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.renderer.scatter; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Paint; 5 | 6 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; 7 | import com.github.mikephil.charting.utils.ColorTemplate; 8 | import com.github.mikephil.charting.utils.Utils; 9 | import com.github.mikephil.charting.utils.ViewPortHandler; 10 | 11 | /** 12 | * Created by wajdic on 15/06/2016. 13 | * Created at Time 09:08 14 | */ 15 | public class CircleShapeRenderer implements IShapeRenderer 16 | { 17 | 18 | @Override 19 | public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, 20 | float posX, float posY, Paint renderPaint) { 21 | 22 | final float shapeSize = dataSet.getScatterShapeSize(); 23 | final float shapeHalf = shapeSize / 2f; 24 | final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius()); 25 | final float shapeHoleSize = shapeHoleSizeHalf * 2.f; 26 | final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f; 27 | final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f; 28 | 29 | final int shapeHoleColor = dataSet.getScatterShapeHoleColor(); 30 | 31 | if (shapeSize > 0.0) { 32 | renderPaint.setStyle(Paint.Style.STROKE); 33 | renderPaint.setStrokeWidth(shapeStrokeSize); 34 | 35 | c.drawCircle( 36 | posX, 37 | posY, 38 | shapeHoleSizeHalf + shapeStrokeSizeHalf, 39 | renderPaint); 40 | 41 | if (shapeHoleColor != ColorTemplate.COLOR_NONE) { 42 | renderPaint.setStyle(Paint.Style.FILL); 43 | 44 | renderPaint.setColor(shapeHoleColor); 45 | c.drawCircle( 46 | posX, 47 | posY, 48 | shapeHoleSizeHalf, 49 | renderPaint); 50 | } 51 | } else { 52 | renderPaint.setStyle(Paint.Style.FILL); 53 | 54 | c.drawCircle( 55 | posX, 56 | posY, 57 | shapeHalf, 58 | renderPaint); 59 | } 60 | 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/CrossShapeRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.renderer.scatter; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Paint; 5 | 6 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; 7 | import com.github.mikephil.charting.utils.Utils; 8 | import com.github.mikephil.charting.utils.ViewPortHandler; 9 | 10 | /** 11 | * Created by wajdic on 15/06/2016. 12 | * Created at Time 09:08 13 | */ 14 | public class CrossShapeRenderer implements IShapeRenderer 15 | { 16 | 17 | 18 | @Override 19 | public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, 20 | float posX, float posY, Paint renderPaint) { 21 | 22 | final float shapeHalf = dataSet.getScatterShapeSize() / 2f; 23 | 24 | renderPaint.setStyle(Paint.Style.STROKE); 25 | renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f)); 26 | 27 | c.drawLine( 28 | posX - shapeHalf, 29 | posY, 30 | posX + shapeHalf, 31 | posY, 32 | renderPaint); 33 | c.drawLine( 34 | posX, 35 | posY - shapeHalf, 36 | posX, 37 | posY + shapeHalf, 38 | renderPaint); 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/IShapeRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.renderer.scatter; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Paint; 5 | 6 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; 7 | import com.github.mikephil.charting.utils.ViewPortHandler; 8 | 9 | /** 10 | * Created by wajdic on 15/06/2016. 11 | * Created at Time 09:07 12 | */ 13 | public interface IShapeRenderer 14 | { 15 | 16 | /** 17 | * Renders the provided ScatterDataSet with a shape. 18 | * 19 | * @param c Canvas object for drawing the shape 20 | * @param dataSet The DataSet to be drawn 21 | * @param viewPortHandler Contains information about the current state of the view 22 | * @param posX Position to draw the shape at 23 | * @param posY Position to draw the shape at 24 | * @param renderPaint Paint object used for styling and drawing 25 | */ 26 | void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, 27 | float posX, float posY, Paint renderPaint); 28 | } 29 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/SquareShapeRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.renderer.scatter; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Paint; 5 | 6 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; 7 | import com.github.mikephil.charting.utils.ColorTemplate; 8 | import com.github.mikephil.charting.utils.Utils; 9 | import com.github.mikephil.charting.utils.ViewPortHandler; 10 | 11 | /** 12 | * Created by wajdic on 15/06/2016. 13 | * Created at Time 09:08 14 | */ 15 | public class SquareShapeRenderer implements IShapeRenderer 16 | { 17 | 18 | 19 | @Override 20 | public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, 21 | float posX, float posY, Paint renderPaint) { 22 | 23 | final float shapeSize = dataSet.getScatterShapeSize(); 24 | final float shapeHalf = shapeSize / 2f; 25 | final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius()); 26 | final float shapeHoleSize = shapeHoleSizeHalf * 2.f; 27 | final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f; 28 | final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f; 29 | 30 | final int shapeHoleColor = dataSet.getScatterShapeHoleColor(); 31 | 32 | if (shapeSize > 0.0) { 33 | renderPaint.setStyle(Paint.Style.STROKE); 34 | renderPaint.setStrokeWidth(shapeStrokeSize); 35 | 36 | c.drawRect(posX - shapeHoleSizeHalf - shapeStrokeSizeHalf, 37 | posY - shapeHoleSizeHalf - shapeStrokeSizeHalf, 38 | posX + shapeHoleSizeHalf + shapeStrokeSizeHalf, 39 | posY + shapeHoleSizeHalf + shapeStrokeSizeHalf, 40 | renderPaint); 41 | 42 | if (shapeHoleColor != ColorTemplate.COLOR_NONE) { 43 | renderPaint.setStyle(Paint.Style.FILL); 44 | 45 | renderPaint.setColor(shapeHoleColor); 46 | c.drawRect(posX - shapeHoleSizeHalf, 47 | posY - shapeHoleSizeHalf, 48 | posX + shapeHoleSizeHalf, 49 | posY + shapeHoleSizeHalf, 50 | renderPaint); 51 | } 52 | 53 | } else { 54 | renderPaint.setStyle(Paint.Style.FILL); 55 | 56 | c.drawRect(posX - shapeHalf, 57 | posY - shapeHalf, 58 | posX + shapeHalf, 59 | posY + shapeHalf, 60 | renderPaint); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/TriangleShapeRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.renderer.scatter; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Paint; 5 | import android.graphics.Path; 6 | 7 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; 8 | import com.github.mikephil.charting.utils.ColorTemplate; 9 | import com.github.mikephil.charting.utils.Utils; 10 | import com.github.mikephil.charting.utils.ViewPortHandler; 11 | 12 | /** 13 | * Created by wajdic on 15/06/2016. 14 | * Created at Time 09:08 15 | */ 16 | public class TriangleShapeRenderer implements IShapeRenderer 17 | { 18 | 19 | protected Path mTrianglePathBuffer = new Path(); 20 | 21 | @Override 22 | public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, 23 | float posX, float posY, Paint renderPaint) { 24 | 25 | final float shapeSize = dataSet.getScatterShapeSize(); 26 | final float shapeHalf = shapeSize / 2f; 27 | final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius()); 28 | final float shapeHoleSize = shapeHoleSizeHalf * 2.f; 29 | final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f; 30 | 31 | final int shapeHoleColor = dataSet.getScatterShapeHoleColor(); 32 | 33 | renderPaint.setStyle(Paint.Style.FILL); 34 | 35 | // create a triangle path 36 | Path tri = mTrianglePathBuffer; 37 | tri.reset(); 38 | 39 | tri.moveTo(posX, posY - shapeHalf); 40 | tri.lineTo(posX + shapeHalf, posY + shapeHalf); 41 | tri.lineTo(posX - shapeHalf, posY + shapeHalf); 42 | 43 | if (shapeSize > 0.0) { 44 | tri.lineTo(posX, posY - shapeHalf); 45 | 46 | tri.moveTo(posX - shapeHalf + shapeStrokeSize, 47 | posY + shapeHalf - shapeStrokeSize); 48 | tri.lineTo(posX + shapeHalf - shapeStrokeSize, 49 | posY + shapeHalf - shapeStrokeSize); 50 | tri.lineTo(posX, 51 | posY - shapeHalf + shapeStrokeSize); 52 | tri.lineTo(posX - shapeHalf + shapeStrokeSize, 53 | posY + shapeHalf - shapeStrokeSize); 54 | } 55 | 56 | tri.close(); 57 | 58 | c.drawPath(tri, renderPaint); 59 | tri.reset(); 60 | 61 | if (shapeSize > 0.0 && 62 | shapeHoleColor != ColorTemplate.COLOR_NONE) { 63 | 64 | renderPaint.setColor(shapeHoleColor); 65 | 66 | tri.moveTo(posX, 67 | posY - shapeHalf + shapeStrokeSize); 68 | tri.lineTo(posX + shapeHalf - shapeStrokeSize, 69 | posY + shapeHalf - shapeStrokeSize); 70 | tri.lineTo(posX - shapeHalf + shapeStrokeSize, 71 | posY + shapeHalf - shapeStrokeSize); 72 | tri.close(); 73 | 74 | c.drawPath(tri, renderPaint); 75 | tri.reset(); 76 | } 77 | 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/renderer/scatter/XShapeRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.renderer.scatter; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Paint; 5 | 6 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; 7 | import com.github.mikephil.charting.utils.Utils; 8 | import com.github.mikephil.charting.utils.ViewPortHandler; 9 | 10 | /** 11 | * Created by wajdic on 15/06/2016. 12 | * Created at Time 09:08 13 | */ 14 | public class XShapeRenderer implements IShapeRenderer 15 | { 16 | 17 | 18 | @Override 19 | public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, 20 | float posX, float posY, Paint renderPaint) { 21 | 22 | final float shapeHalf = dataSet.getScatterShapeSize() / 2f; 23 | 24 | renderPaint.setStyle(Paint.Style.STROKE); 25 | renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f)); 26 | 27 | c.drawLine( 28 | posX - shapeHalf, 29 | posY - shapeHalf, 30 | posX + shapeHalf, 31 | posY + shapeHalf, 32 | renderPaint); 33 | c.drawLine( 34 | posX + shapeHalf, 35 | posY - shapeHalf, 36 | posX - shapeHalf, 37 | posY + shapeHalf, 38 | renderPaint); 39 | 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/utils/EntryXComparator.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.utils; 2 | 3 | import com.github.mikephil.charting.data.Entry; 4 | 5 | import java.util.Comparator; 6 | 7 | /** 8 | * Comparator for comparing Entry-objects by their x-value. 9 | * Created by philipp on 17/06/15. 10 | */ 11 | public class EntryXComparator implements Comparator5 | * author : JinBiao 6 | * CSDN : http://my.csdn.net/DT235201314 7 | * time : 2017/04/05 8 | * desc :工具类 9 | * version: 1.0 10 | *11 | */ 12 | 13 | public class StringUtils { 14 | /** 15 | * 判断给定字符串是否空白串。 空白串是指由空格、制表符、回车符、换行符组成的字符串 若输入字符串为null或空字符串,返回true 16 | * 17 | * @param input 18 | * @return boolean 19 | */ 20 | public static boolean isEmpty(String input) { 21 | if (input == null || "".equals(input)) 22 | return true; 23 | 24 | for (int i = 0; i < input.length(); i++) { 25 | char c = input.charAt(i); 26 | if (c != ' ' && c != '\t' && c != '\r' && c != '\n') { 27 | return false; 28 | } 29 | } 30 | return true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/utils/TransformerHorizontalBarChart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.utils; 3 | 4 | /** 5 | * Transformer class for the HorizontalBarChart. 6 | * 7 | * @author Philipp Jahoda 8 | */ 9 | public class TransformerHorizontalBarChart extends Transformer { 10 | 11 | public TransformerHorizontalBarChart(ViewPortHandler viewPortHandler) { 12 | super(viewPortHandler); 13 | } 14 | /** 15 | * Prepares the matrix that contains all offsets. 16 | * 17 | * @param inverted 18 | */ 19 | public void prepareMatrixOffset(boolean inverted) { 20 | 21 | mMatrixOffset.reset(); 22 | 23 | // offset.postTranslate(mOffsetLeft, getHeight() - mOffsetBottom); 24 | 25 | if (!inverted) 26 | mMatrixOffset.postTranslate(mViewPortHandler.offsetLeft(), 27 | mViewPortHandler.getChartHeight() - mViewPortHandler.offsetBottom()); 28 | else { 29 | mMatrixOffset 30 | .setTranslate( 31 | -(mViewPortHandler.getChartWidth() - mViewPortHandler.offsetRight()), 32 | mViewPortHandler.getChartHeight() - mViewPortHandler.offsetBottom()); 33 | mMatrixOffset.postScale(-1.0f, 1.0f); 34 | } 35 | 36 | // mMatrixOffset.set(offset); 37 | 38 | // mMatrixOffset.reset(); 39 | // 40 | // mMatrixOffset.postTranslate(mOffsetLeft, getHeight() - 41 | // mOffsetBottom); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/view/LineChartInViewPager.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.view; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.graphics.PointF; 6 | import android.util.AttributeSet; 7 | import android.view.MotionEvent; 8 | 9 | import com.github.mikephil.charting.charts.LineChart; 10 | 11 | /** 12 | * ************************************************************* 13 | *
14 | * .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. * 15 | * | ______ | * 16 | * | .-" "-. | * 17 | * | / \ | * 18 | * | _ | | _ | * 19 | * | ( \ |, .-. .-. ,| / ) | * 20 | * | > "=._ | )(__/ \__)( | _.=" < | * 21 | * | (_/"=._"=._ |/ /\ \| _.="_.="\_) | * 22 | * | "=._"(_ ^^ _)"_.=" | * 23 | * | "=\__|IIIIII|__/=" | * 24 | * | _.="| \IIIIII/ |"=._ | * 25 | * | _ _.="_.="\ /"=._"=._ _ | * 26 | * | ( \_.="_.=" `--------` "=._"=._/ ) | * 27 | * | > _.=" "=._ < | * 28 | * | (_/ \_) | * 29 | * | | * 30 | * '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' * 31 | *
32 | * ************************************************************* 33 | *
Created by 坚果-王健(wangjian3@kuyumall.com) on 2017/5/12.
34 | */
35 |
36 | public class LineChartInViewPager extends LineChart {
37 |
38 | PointF downPoint = new PointF();
39 |
40 | public LineChartInViewPager(Context context) {
41 | super(context);
42 | }
43 |
44 | public LineChartInViewPager(Context context, AttributeSet attrs) {
45 | super(context, attrs);
46 | }
47 |
48 | public LineChartInViewPager(Context context, AttributeSet attrs, int defStyle) {
49 | super(context, attrs, defStyle);
50 | }
51 |
52 | @SuppressLint("ClickableViewAccessibility")
53 | @Override
54 | public boolean onTouchEvent(MotionEvent evt) {
55 | switch (evt.getAction()) {
56 | case MotionEvent.ACTION_DOWN:
57 | downPoint.x = evt.getX();
58 | downPoint.y = evt.getY();
59 | break;
60 | case MotionEvent.ACTION_MOVE:
61 | if (getScaleX() > 1 && Math.abs(evt.getX() - downPoint.x) > 5) {
62 | getParent().requestDisallowInterceptTouchEvent(true);
63 | }
64 | break;
65 | }
66 | return super.onTouchEvent(evt);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/MPChartLib/src/test/java/com/github/mikephil/charting/test/ApproximatorTest.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.test;
2 |
3 | import com.github.mikephil.charting.data.Entry;
4 | import com.github.mikephil.charting.data.filter.Approximator;
5 |
6 | import org.junit.Test;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | import static junit.framework.Assert.assertEquals;
12 |
13 | /**
14 | * Created by philipp on 07/06/16.
15 | */
16 | public class ApproximatorTest {
17 |
18 | @Test
19 | public void testApproximation() {
20 |
21 | float[] points = new float[]{
22 | 10, 20,
23 | 20, 30,
24 | 25, 25,
25 | 30, 28,
26 | 31, 31,
27 | 33, 33,
28 | 40, 40,
29 | 44, 40,
30 | 48, 23,
31 | 50, 20,
32 | 55, 20,
33 | 60, 25};
34 |
35 | assertEquals(24, points.length);
36 |
37 | Approximator a = new Approximator();
38 |
39 | float[] reduced = a.reduceWithDouglasPeucker(points, 2);
40 |
41 | assertEquals(18, reduced.length);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/MPChartLib/src/test/java/com/github/mikephil/charting/test/BarDataTest.java:
--------------------------------------------------------------------------------
1 | package com.github.mikephil.charting.test;
2 |
3 | import com.github.mikephil.charting.data.BarData;
4 | import com.github.mikephil.charting.data.BarDataSet;
5 | import com.github.mikephil.charting.data.BarEntry;
6 |
7 | import org.junit.Test;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | import static junit.framework.Assert.assertEquals;
13 |
14 | /**
15 | * Created by philipp on 06/06/16.
16 | */
17 | public class BarDataTest {
18 |
19 | @Test
20 | public void testGroupBars() {
21 |
22 | float groupSpace = 5f;
23 | float barSpace = 1f;
24 |
25 | List