├── .gitignore ├── .idea ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── MPChartLib ├── .gitignore ├── .settings │ └── gradle │ │ └── org.springsource.ide.eclipse.gradle.core.prefs ├── build.gradle ├── ic_launcher-web.png ├── pom.xml ├── proguard-project.txt ├── project.properties └── src │ ├── main │ ├── AndroidManifest.xml │ └── java │ │ └── com │ │ └── github │ │ └── mikephil │ │ └── charting │ │ ├── animation │ │ ├── ChartAnimator.java │ │ └── Easing.java │ │ ├── buffer │ │ ├── AbstractBuffer.java │ │ ├── BarBuffer.java │ │ └── HorizontalBarBuffer.java │ │ ├── charts │ │ ├── BarChart.java │ │ ├── BarLineChartBase.java │ │ ├── BubbleChart.java │ │ ├── CandleStickChart.java │ │ ├── Chart.java │ │ ├── CombinedChart.java │ │ ├── HorizontalBarChart.java │ │ ├── LineChart.java │ │ ├── PieChart.java │ │ ├── PieRadarChartBase.java │ │ ├── RadarChart.java │ │ └── ScatterChart.java │ │ ├── components │ │ ├── AxisBase.java │ │ ├── ComponentBase.java │ │ ├── Description.java │ │ ├── IMarker.java │ │ ├── Legend.java │ │ ├── LegendEntry.java │ │ ├── LimitLine.java │ │ ├── MarkerImage.java │ │ ├── MarkerView.java │ │ ├── NomalMarkerView.java │ │ ├── XAxis.java │ │ └── YAxis.java │ │ ├── data │ │ ├── BarData.java │ │ ├── BarDataSet.java │ │ ├── BarEntry.java │ │ ├── BarLineScatterCandleBubbleData.java │ │ ├── BarLineScatterCandleBubbleDataSet.java │ │ ├── BaseDataSet.java │ │ ├── BaseEntry.java │ │ ├── BubbleData.java │ │ ├── BubbleDataSet.java │ │ ├── BubbleEntry.java │ │ ├── CandleData.java │ │ ├── CandleDataSet.java │ │ ├── CandleEntry.java │ │ ├── ChartData.java │ │ ├── CombinedData.java │ │ ├── DataSet.java │ │ ├── Entry.java │ │ ├── LineData.java │ │ ├── LineDataSet.java │ │ ├── LineRadarDataSet.java │ │ ├── LineScatterCandleRadarDataSet.java │ │ ├── PieData.java │ │ ├── PieDataSet.java │ │ ├── PieEntry.java │ │ ├── RadarData.java │ │ ├── RadarDataSet.java │ │ ├── RadarEntry.java │ │ ├── ScatterData.java │ │ ├── ScatterDataSet.java │ │ └── filter │ │ │ └── Approximator.java │ │ ├── entity │ │ ├── BarDataEntity.java │ │ ├── BarEntity.java │ │ ├── MonthItemEntity.java │ │ ├── PercentageEntity.java │ │ ├── RealListEntity.java │ │ ├── SourceEntity.java │ │ ├── TextBarDataEntity.java │ │ └── YoyListEntity.java │ │ ├── exception │ │ └── DrawingDataSetNotCreatedException.java │ │ ├── formatter │ │ ├── ColorFormatter.java │ │ ├── DefaultAxisValueFormatter.java │ │ ├── DefaultFillFormatter.java │ │ ├── DefaultValueFormatter.java │ │ ├── IAxisValueFormatter.java │ │ ├── IFillFormatter.java │ │ ├── IValueFormatter.java │ │ ├── IndexAxisValueFormatter.java │ │ ├── LargeValueFormatter.java │ │ ├── PercentFormatter.java │ │ └── StackedValueFormatter.java │ │ ├── highlight │ │ ├── BarHighlighter.java │ │ ├── ChartHighlighter.java │ │ ├── CombinedHighlighter.java │ │ ├── Highlight.java │ │ ├── HorizontalBarHighlighter.java │ │ ├── IHighlighter.java │ │ ├── PieHighlighter.java │ │ ├── PieRadarHighlighter.java │ │ ├── RadarHighlighter.java │ │ └── Range.java │ │ ├── interfaces │ │ ├── dataprovider │ │ │ ├── BarDataProvider.java │ │ │ ├── BarLineScatterCandleBubbleDataProvider.java │ │ │ ├── BubbleDataProvider.java │ │ │ ├── CandleDataProvider.java │ │ │ ├── ChartInterface.java │ │ │ ├── CombinedDataProvider.java │ │ │ ├── LineDataProvider.java │ │ │ └── ScatterDataProvider.java │ │ └── datasets │ │ │ ├── IBarDataSet.java │ │ │ ├── IBarLineScatterCandleBubbleDataSet.java │ │ │ ├── IBubbleDataSet.java │ │ │ ├── ICandleDataSet.java │ │ │ ├── IDataSet.java │ │ │ ├── ILineDataSet.java │ │ │ ├── ILineRadarDataSet.java │ │ │ ├── ILineScatterCandleRadarDataSet.java │ │ │ ├── IPieDataSet.java │ │ │ ├── IRadarDataSet.java │ │ │ └── IScatterDataSet.java │ │ ├── jobs │ │ ├── AnimatedMoveViewJob.java │ │ ├── AnimatedViewPortJob.java │ │ ├── AnimatedZoomJob.java │ │ ├── MoveViewJob.java │ │ ├── ViewPortJob.java │ │ └── ZoomJob.java │ │ ├── listener │ │ ├── BarLineChartTouchListener.java │ │ ├── ChartTouchListener.java │ │ ├── OnChartGestureListener.java │ │ ├── OnChartValueSelectedListener.java │ │ ├── OnDrawLineChartTouchListener.java │ │ ├── OnDrawListener.java │ │ └── PieRadarChartTouchListener.java │ │ ├── matrix │ │ └── Vector3.java │ │ ├── model │ │ └── GradientColor.java │ │ ├── newchart │ │ ├── BarChartEntity.java │ │ ├── BaseChartEntity.java │ │ ├── ChartsDemo.java │ │ ├── GroupBarChartEntity.java │ │ ├── LineChartEntity.java │ │ ├── PieChartEntity.java │ │ └── StackBarChartEntry.java │ │ ├── renderer │ │ ├── AxisRenderer.java │ │ ├── BarChartRenderer.java │ │ ├── BarLineScatterCandleBubbleRenderer.java │ │ ├── BubbleChartRenderer.java │ │ ├── CandleStickChartRenderer.java │ │ ├── CombinedChartRenderer.java │ │ ├── DataRenderer.java │ │ ├── HorizontalBarChartRenderer.java │ │ ├── LegendRenderer.java │ │ ├── LineChartRenderer.java │ │ ├── LineRadarRenderer.java │ │ ├── LineScatterCandleRadarRenderer.java │ │ ├── PieChartRenderer.java │ │ ├── RadarChartRenderer.java │ │ ├── Renderer.java │ │ ├── ScatterChartRenderer.java │ │ ├── XAxisRenderer.java │ │ ├── XAxisRendererHorizontalBarChart.java │ │ ├── XAxisRendererRadarChart.java │ │ ├── YAxisRenderer.java │ │ ├── YAxisRendererHorizontalBarChart.java │ │ ├── YAxisRendererRadarChart.java │ │ └── scatter │ │ │ ├── ChevronDownShapeRenderer.java │ │ │ ├── ChevronUpShapeRenderer.java │ │ │ ├── CircleShapeRenderer.java │ │ │ ├── CrossShapeRenderer.java │ │ │ ├── IShapeRenderer.java │ │ │ ├── SquareShapeRenderer.java │ │ │ ├── TriangleShapeRenderer.java │ │ │ └── XShapeRenderer.java │ │ ├── utils │ │ ├── ColorTemplate.java │ │ ├── EntryXComparator.java │ │ ├── FSize.java │ │ ├── FileUtils.java │ │ ├── HorizontalViewPortHandler.java │ │ ├── MPPointD.java │ │ ├── MPPointF.java │ │ ├── ObjectPool.java │ │ ├── ParseUtils.java │ │ ├── SPoolUtils.java │ │ ├── StringUtils.java │ │ ├── Transformer.java │ │ ├── TransformerHorizontalBarChart.java │ │ ├── Utils.java │ │ └── ViewPortHandler.java │ │ └── view │ │ ├── BarView.java │ │ └── LineChartInViewPager.java │ └── test │ └── java │ └── com │ └── github │ └── mikephil │ └── charting │ └── test │ ├── ApproximatorTest.java │ ├── AxisRendererTest.java │ ├── BarDataTest.java │ ├── ChartDataTest.java │ ├── DataSetTest.java │ ├── LargeValueFormatterTest.java │ └── ObjectPoolTest.java ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── smartchart │ │ └── cn │ │ └── mpandroidchart │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ ├── test.json │ │ └── test1.json │ ├── java │ │ └── com │ │ │ └── smartchart │ │ │ └── cn │ │ │ └── mpandroidchart │ │ │ ├── MainActivity.java │ │ │ ├── NomalChartActivity.java │ │ │ ├── bean │ │ │ └── YomthEnity.java │ │ │ ├── utils │ │ │ ├── BaseUtils.java │ │ │ └── FileUtils.java │ │ │ └── view │ │ │ ├── MyMarkerView.java │ │ │ └── NewMarkerView.java │ └── res │ │ ├── drawable-hdpi │ │ ├── ic_launcher.png │ │ └── view_dash_line.xml │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable-xhdpi │ │ ├── chart_callserice_call_casecount.xml │ │ ├── chart_popu.9.png │ │ ├── chart_popu_right.9.png │ │ ├── chart_thisyear_blue.xml │ │ └── ic_launcher.png │ │ ├── drawable │ │ ├── ac_bg_oval.xml │ │ ├── bg_null.png │ │ ├── chart_view_selector_line.xml │ │ ├── ic_launcher_background.xml │ │ ├── jfdfdj.png │ │ ├── line_bg_pressed.png │ │ └── marker3.png │ │ ├── layout │ │ ├── activity_a.xml │ │ ├── activity_line.xml │ │ ├── activity_main.xml │ │ ├── custom_marker_view.xml │ │ ├── custom_marker_view_2.xml │ │ └── custom_marker_view_layout.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── smartchart │ └── cn │ └── mpandroidchart │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshot ├── chart.png └── chart_cutom.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /MPChartLib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /MPChartLib/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs: -------------------------------------------------------------------------------- 1 | #org.springsource.ide.eclipse.gradle.core.preferences.GradleProjectPreferences 2 | #Mon Jan 18 23:02:46 CET 2016 3 | org.springsource.ide.eclipse.gradle.linkedresources= 4 | org.springsource.ide.eclipse.gradle.rootprojectloc=.. 5 | -------------------------------------------------------------------------------- /MPChartLib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'maven' 3 | //apply plugin: 'com.github.dcendents.android-maven' 4 | //apply plugin: 'realm-android' 5 | 6 | android { 7 | compileSdkVersion 27 8 | buildToolsVersion '27.0.3' 9 | // resourcePrefix 'mpcht' 10 | defaultConfig { 11 | //noinspection MinSdkTooLow 12 | minSdkVersion 9 13 | targetSdkVersion 27 14 | versionCode 3 15 | versionName '3.0.3' 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | lintOptions { 24 | abortOnError false 25 | } 26 | testOptions { 27 | unitTests.returnDefaultValues = true // this prevents "not mocked" error 28 | } 29 | } 30 | 31 | repositories { 32 | maven { 33 | url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' 34 | } 35 | } 36 | 37 | dependencies { 38 | //provided 'io.realm:realm-android:0.87.5' // "optional" dependency to realm-database API 39 | implementation 'com.android.support:support-annotations:27.1.1' 40 | testImplementation 'junit:junit:4.12' 41 | testImplementation "org.mockito:mockito-core:1.10.19" 42 | } 43 | 44 | android.libraryVariants.all { variant -> 45 | def name = variant.buildType.name 46 | def task = project.tasks.create "jar${name.capitalize()}", Jar 47 | task.dependsOn variant.javaCompiler 48 | task.from variant.javaCompiler.destinationDir 49 | artifacts.add('archives', task) 50 | } 51 | 52 | task sourcesJar(type: Jar) { 53 | from android.sourceSets.main.java.srcDirs 54 | classifier = 'sources' 55 | } 56 | 57 | task javadoc(type: Javadoc) { 58 | options.charSet = 'UTF-8' 59 | failOnError false 60 | source = android.sourceSets.main.java.sourceFiles 61 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 62 | } 63 | 64 | task javadocJar(type: Jar, dependsOn: javadoc) { 65 | classifier = 'javadoc' 66 | from javadoc.destinationDir 67 | } 68 | 69 | artifacts { 70 | archives sourcesJar 71 | archives javadocJar 72 | } 73 | -------------------------------------------------------------------------------- /MPChartLib/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangi789/MPAndroidChart/3de0d767490665353603bb8745e25e8a1bb04580/MPChartLib/ic_launcher-web.png -------------------------------------------------------------------------------- /MPChartLib/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /MPChartLib/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-23 15 | android.library=true 16 | -------------------------------------------------------------------------------- /MPChartLib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/buffer/AbstractBuffer.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.buffer; 3 | 4 | import java.util.List; 5 | 6 | /** 7 | * Buffer class to boost performance while drawing. Concept: Replace instead of 8 | * recreate. 9 | * 10 | * @author Philipp Jahoda 11 | * @param The data the buffer accepts to be fed with. 12 | */ 13 | public abstract class AbstractBuffer { 14 | 15 | /** index in the buffer */ 16 | protected int index = 0; 17 | 18 | /** float-buffer that holds the data points to draw, order: x,y,x,y,... */ 19 | public final float[] buffer; 20 | 21 | /** animation phase x-axis */ 22 | protected float phaseX = 1f; 23 | 24 | /** animation phase y-axis */ 25 | protected float phaseY = 1f; 26 | 27 | /** indicates from which x-index the visible data begins */ 28 | protected int mFrom = 0; 29 | 30 | /** indicates to which x-index the visible data ranges */ 31 | protected int mTo = 0; 32 | 33 | /** 34 | * Initialization with buffer-size. 35 | * 36 | * @param size 37 | */ 38 | public AbstractBuffer(int size) { 39 | index = 0; 40 | buffer = new float[size]; 41 | } 42 | 43 | /** limits the drawing on the x-axis */ 44 | public void limitFrom(int from) { 45 | if (from < 0) 46 | from = 0; 47 | mFrom = from; 48 | } 49 | 50 | /** limits the drawing on the x-axis */ 51 | public void limitTo(int to) { 52 | if (to < 0) 53 | to = 0; 54 | mTo = to; 55 | } 56 | 57 | /** 58 | * Resets the buffer index to 0 and makes the buffer reusable. 59 | */ 60 | public void reset() { 61 | index = 0; 62 | } 63 | 64 | /** 65 | * Returns the size (length) of the buffer array. 66 | * 67 | * @return 68 | */ 69 | public int size() { 70 | return buffer.length; 71 | } 72 | 73 | /** 74 | * Set the phases used for animations. 75 | * 76 | * @param phaseX 77 | * @param phaseY 78 | */ 79 | public void setPhases(float phaseX, float phaseY) { 80 | this.phaseX = phaseX; 81 | this.phaseY = phaseY; 82 | } 83 | 84 | /** 85 | * Builds up the buffer with the provided data and resets the buffer-index 86 | * after feed-completion. This needs to run FAST. 87 | * 88 | * @param data 89 | */ 90 | public abstract void feed(T data); 91 | } 92 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/buffer/HorizontalBarBuffer.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.buffer; 3 | 4 | import com.github.mikephil.charting.data.BarEntry; 5 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; 6 | 7 | public class HorizontalBarBuffer extends BarBuffer { 8 | 9 | public HorizontalBarBuffer(int size, int dataSetCount, boolean containsStacks) { 10 | super(size, dataSetCount, containsStacks); 11 | } 12 | 13 | @Override 14 | public void feed(IBarDataSet data) { 15 | 16 | float size = data.getEntryCount() * phaseX; 17 | float barWidthHalf = mBarWidth / 2f; 18 | 19 | for (int i = 0; i < size; i++) { 20 | 21 | BarEntry e = data.getEntryForIndex(i); 22 | 23 | if(e == null) 24 | continue; 25 | 26 | float x = e.getX(); 27 | float y = e.getY(); 28 | float[] vals = e.getYVals(); 29 | 30 | if (!mContainsStacks || vals == null) { 31 | 32 | float bottom = x - barWidthHalf; 33 | float top = x + barWidthHalf; 34 | float left, right; 35 | if (mInverted) { 36 | left = y >= 0 ? y : 0; 37 | right = y <= 0 ? y : 0; 38 | } else { 39 | right = y >= 0 ? y : 0; 40 | left = y <= 0 ? y : 0; 41 | } 42 | 43 | // multiply the height of the rect with the phase 44 | if (right > 0) 45 | right *= phaseY; 46 | else 47 | left *= phaseY; 48 | 49 | addBar(left, top, right, bottom); 50 | 51 | } else { 52 | 53 | float posY = 0f; 54 | float negY = -e.getNegativeSum(); 55 | float yStart = 0f; 56 | 57 | // fill the stack 58 | for (int k = 0; k < vals.length; k++) { 59 | 60 | float value = vals[k]; 61 | 62 | if (value >= 0f) { 63 | y = posY; 64 | yStart = posY + value; 65 | posY = yStart; 66 | } else { 67 | y = negY; 68 | yStart = negY + Math.abs(value); 69 | negY += Math.abs(value); 70 | } 71 | 72 | float bottom = x - barWidthHalf; 73 | float top = x + barWidthHalf; 74 | float left, right; 75 | if (mInverted) { 76 | left = y >= yStart ? y : yStart; 77 | right = y <= yStart ? y : yStart; 78 | } else { 79 | right = y >= yStart ? y : yStart; 80 | left = y <= yStart ? y : yStart; 81 | } 82 | 83 | // multiply the height of the rect with the phase 84 | right *= phaseY; 85 | left *= phaseY; 86 | 87 | addBar(left, top, right, bottom); 88 | } 89 | } 90 | } 91 | 92 | reset(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/charts/BubbleChart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.charts; 3 | 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | 7 | import com.github.mikephil.charting.data.BubbleData; 8 | import com.github.mikephil.charting.interfaces.dataprovider.BubbleDataProvider; 9 | import com.github.mikephil.charting.renderer.BubbleChartRenderer; 10 | 11 | /** 12 | * The BubbleChart. Draws bubbles. Bubble chart implementation: Copyright 2015 13 | * Pierre-Marc Airoldi Licensed under Apache License 2.0. In the BubbleChart, it 14 | * is the area of the bubble, not the radius or diameter of the bubble that 15 | * conveys the data. 16 | * 17 | * @author Philipp Jahoda 18 | */ 19 | public class BubbleChart extends BarLineChartBase implements BubbleDataProvider { 20 | 21 | public BubbleChart(Context context) { 22 | super(context); 23 | } 24 | 25 | public BubbleChart(Context context, AttributeSet attrs) { 26 | super(context, attrs); 27 | } 28 | 29 | public BubbleChart(Context context, AttributeSet attrs, int defStyle) { 30 | super(context, attrs, defStyle); 31 | } 32 | 33 | @Override 34 | protected void init() { 35 | super.init(); 36 | 37 | mRenderer = new BubbleChartRenderer(this, mAnimator, mViewPortHandler); 38 | } 39 | 40 | public BubbleData getBubbleData() { 41 | return mData; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/charts/CandleStickChart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.charts; 3 | 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | 7 | import com.github.mikephil.charting.data.CandleData; 8 | import com.github.mikephil.charting.interfaces.dataprovider.CandleDataProvider; 9 | import com.github.mikephil.charting.renderer.CandleStickChartRenderer; 10 | 11 | /** 12 | * Financial chart type that draws candle-sticks (OHCL chart). 13 | * 14 | * @author Philipp Jahoda 15 | */ 16 | public class CandleStickChart extends BarLineChartBase implements CandleDataProvider { 17 | 18 | public CandleStickChart(Context context) { 19 | super(context); 20 | } 21 | 22 | public CandleStickChart(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | public CandleStickChart(Context context, AttributeSet attrs, int defStyle) { 27 | super(context, attrs, defStyle); 28 | } 29 | 30 | @Override 31 | protected void init() { 32 | super.init(); 33 | 34 | mRenderer = new CandleStickChartRenderer(this, mAnimator, mViewPortHandler); 35 | 36 | getXAxis().setSpaceMin(0.5f); 37 | getXAxis().setSpaceMax(0.5f); 38 | } 39 | 40 | @Override 41 | public CandleData getCandleData() { 42 | return mData; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/charts/LineChart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.charts; 3 | 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | 7 | import com.github.mikephil.charting.data.LineData; 8 | import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider; 9 | import com.github.mikephil.charting.renderer.LineChartRenderer; 10 | 11 | /** 12 | * Chart that draws lines, surfaces, circles, ... 13 | * 14 | * @author Philipp Jahoda 15 | */ 16 | public class LineChart extends BarLineChartBase implements LineDataProvider { 17 | 18 | public LineChart(Context context) { 19 | super(context); 20 | } 21 | 22 | public LineChart(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | public LineChart(Context context, AttributeSet attrs, int defStyle) { 27 | super(context, attrs, defStyle); 28 | } 29 | 30 | @Override 31 | protected void init() { 32 | super.init(); 33 | 34 | mRenderer = new LineChartRenderer(this, mAnimator, mViewPortHandler); 35 | } 36 | 37 | @Override 38 | public LineData getLineData() { 39 | return mData; 40 | } 41 | 42 | @Override 43 | protected void onDetachedFromWindow() { 44 | // releases the bitmap in the renderer to avoid oom error 45 | if (mRenderer != null && mRenderer instanceof LineChartRenderer) { 46 | ((LineChartRenderer) mRenderer).releaseBitmap(); 47 | } 48 | super.onDetachedFromWindow(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/charts/ScatterChart.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.charts; 3 | 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | 7 | import com.github.mikephil.charting.data.ScatterData; 8 | import com.github.mikephil.charting.interfaces.dataprovider.ScatterDataProvider; 9 | import com.github.mikephil.charting.renderer.ScatterChartRenderer; 10 | 11 | /** 12 | * The ScatterChart. Draws dots, triangles, squares and custom shapes into the 13 | * Chart-View. CIRCLE and SCQUARE offer the best performance, TRIANGLE has the 14 | * worst performance. 15 | * 16 | * @author Philipp Jahoda 17 | */ 18 | public class ScatterChart extends BarLineChartBase implements ScatterDataProvider { 19 | 20 | public ScatterChart(Context context) { 21 | super(context); 22 | } 23 | 24 | public ScatterChart(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | } 27 | 28 | public ScatterChart(Context context, AttributeSet attrs, int defStyle) { 29 | super(context, attrs, defStyle); 30 | } 31 | 32 | 33 | @Override 34 | protected void init() { 35 | super.init(); 36 | 37 | mRenderer = new ScatterChartRenderer(this, mAnimator, mViewPortHandler); 38 | 39 | getXAxis().setSpaceMin(0.5f); 40 | getXAxis().setSpaceMax(0.5f); 41 | } 42 | 43 | @Override 44 | public ScatterData getScatterData() { 45 | return mData; 46 | } 47 | 48 | /** 49 | * Predefined ScatterShapes that allow the specification of a shape a ScatterDataSet should be drawn with. 50 | * If a ScatterShape is specified for a ScatterDataSet, the required renderer is set. 51 | */ 52 | public enum ScatterShape { 53 | 54 | SQUARE("SQUARE"), 55 | CIRCLE("CIRCLE"), 56 | TRIANGLE("TRIANGLE"), 57 | CROSS("CROSS"), 58 | X("X"), 59 | CHEVRON_UP("CHEVRON_UP"), 60 | CHEVRON_DOWN("CHEVRON_DOWN"); 61 | 62 | private final String shapeIdentifier; 63 | 64 | ScatterShape(final String shapeIdentifier) { 65 | this.shapeIdentifier = shapeIdentifier; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return shapeIdentifier; 71 | } 72 | 73 | public static ScatterShape[] getAllDefaultShapes() { 74 | return new ScatterShape[]{SQUARE, CIRCLE, TRIANGLE, CROSS, X, CHEVRON_UP, CHEVRON_DOWN}; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/components/Description.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.components; 2 | 3 | import android.graphics.Paint; 4 | 5 | import com.github.mikephil.charting.utils.MPPointF; 6 | import com.github.mikephil.charting.utils.Utils; 7 | 8 | /** 9 | * Created by Philipp Jahoda on 17/09/16. 10 | */ 11 | public class Description extends ComponentBase { 12 | 13 | /** 14 | * the text used in the description 15 | */ 16 | private String text = "Description Label"; 17 | 18 | /** 19 | * the custom position of the description text 20 | */ 21 | private MPPointF mPosition; 22 | 23 | /** 24 | * the alignment of the description text 25 | */ 26 | private Paint.Align mTextAlign = Paint.Align.RIGHT; 27 | 28 | public Description() { 29 | super(); 30 | 31 | // default size 32 | mTextSize = Utils.convertDpToPixel(8f); 33 | } 34 | 35 | /** 36 | * Sets the text to be shown as the description. 37 | * Never set this to null as this will cause nullpointer exception when drawing with Android Canvas. 38 | * 39 | * @param text 40 | */ 41 | public void setText(String text) { 42 | this.text = text; 43 | } 44 | 45 | /** 46 | * Returns the description text. 47 | * 48 | * @return 49 | */ 50 | public String getText() { 51 | return text; 52 | } 53 | 54 | /** 55 | * Sets a custom position for the description text in pixels on the screen. 56 | * 57 | * @param x - xcoordinate 58 | * @param y - ycoordinate 59 | */ 60 | public void setPosition(float x, float y) { 61 | if (mPosition == null) { 62 | mPosition = MPPointF.getInstance(x, y); 63 | } else { 64 | mPosition.x = x; 65 | mPosition.y = y; 66 | } 67 | } 68 | 69 | /** 70 | * Returns the customized position of the description, or null if none set. 71 | * 72 | * @return 73 | */ 74 | public MPPointF getPosition() { 75 | return mPosition; 76 | } 77 | 78 | /** 79 | * Sets the text alignment of the description text. Default RIGHT. 80 | * 81 | * @param align 82 | */ 83 | public void setTextAlign(Paint.Align align) { 84 | this.mTextAlign = align; 85 | } 86 | 87 | /** 88 | * Returns the text alignment of the description. 89 | * 90 | * @return 91 | */ 92 | public Paint.Align getTextAlign() { 93 | return mTextAlign; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/components/IMarker.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.components; 2 | 3 | import android.graphics.Canvas; 4 | 5 | import com.github.mikephil.charting.data.Entry; 6 | import com.github.mikephil.charting.highlight.Highlight; 7 | import com.github.mikephil.charting.utils.MPPointF; 8 | 9 | public interface IMarker { 10 | 11 | /** 12 | * @return The desired (general) offset you wish the IMarker to have on the x- and y-axis. 13 | * By returning x: -(width / 2) you will center the IMarker horizontally. 14 | * By returning y: -(height / 2) you will center the IMarker vertically. 15 | */ 16 | MPPointF getOffset(); 17 | 18 | /** 19 | * @return The offset for drawing at the specific `point`. This allows conditional adjusting of the Marker position. 20 | * If you have no adjustments to make, return getOffset(). 21 | * 22 | * @param posX This is the X position at which the marker wants to be drawn. 23 | * You can adjust the offset conditionally based on this argument. 24 | * @param posY This is the X position at which the marker wants to be drawn. 25 | * You can adjust the offset conditionally based on this argument. 26 | */ 27 | MPPointF getOffsetForDrawingAtPoint(float posX, float posY); 28 | 29 | /** 30 | * This method enables a specified custom IMarker to update it's content every time the IMarker is redrawn. 31 | * 32 | * @param e The Entry the IMarker belongs to. This can also be any subclass of Entry, like BarEntry or 33 | * CandleEntry, simply cast it at runtime. 34 | * @param highlight The highlight object contains information about the highlighted value such as it's dataset-index, the 35 | * selected range or stack-index (only stacked bar entries). 36 | */ 37 | void refreshContent(Entry e, Highlight highlight); 38 | 39 | /** 40 | * Draws the IMarker on the given position on the screen with the given Canvas object. 41 | * 42 | * @param canvas 43 | * @param posX 44 | * @param posY 45 | */ 46 | void draw(Canvas canvas, float posX, float posY); 47 | } 48 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/components/LegendEntry.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.components; 2 | 3 | 4 | import android.graphics.DashPathEffect; 5 | 6 | import com.github.mikephil.charting.utils.ColorTemplate; 7 | 8 | public class LegendEntry { 9 | public LegendEntry() { 10 | 11 | } 12 | 13 | /** 14 | * 15 | * @param label The legend entry text. A `null` label will start a group. 16 | * @param form The form to draw for this entry. 17 | * @param formSize Set to NaN to use the legend's default. 18 | * @param formLineWidth Set to NaN to use the legend's default. 19 | * @param formLineDashEffect Set to nil to use the legend's default. 20 | * @param formColor The color for drawing the form. 21 | */ 22 | public LegendEntry(String label, 23 | Legend.LegendForm form, 24 | float formSize, 25 | float formLineWidth, 26 | DashPathEffect formLineDashEffect, 27 | int formColor) 28 | { 29 | this.label = label; 30 | this.form = form; 31 | this.formSize = formSize; 32 | this.formLineWidth = formLineWidth; 33 | this.formLineDashEffect = formLineDashEffect; 34 | this.formColor = formColor; 35 | } 36 | 37 | /** 38 | * The legend entry text. 39 | * A `null` label will start a group. 40 | */ 41 | public String label; 42 | 43 | /** 44 | * The form to draw for this entry. 45 | * 46 | * `NONE` will avoid drawing a form, and any related space. 47 | * `EMPTY` will avoid drawing a form, but keep its space. 48 | * `DEFAULT` will use the Legend's default. 49 | */ 50 | public Legend.LegendForm form = Legend.LegendForm.DEFAULT; 51 | 52 | /** 53 | * Form size will be considered except for when .None is used 54 | * 55 | * Set as NaN to use the legend's default 56 | */ 57 | public float formSize = Float.NaN; 58 | 59 | /** 60 | * Line width used for shapes that consist of lines. 61 | * 62 | * Set as NaN to use the legend's default 63 | */ 64 | public float formLineWidth = Float.NaN; 65 | 66 | /** 67 | * Line dash path effect used for shapes that consist of lines. 68 | * 69 | * Set to null to use the legend's default 70 | */ 71 | public DashPathEffect formLineDashEffect = null; 72 | 73 | /** 74 | * The color for drawing the form 75 | */ 76 | public int formColor = ColorTemplate.COLOR_NONE; 77 | 78 | } -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Baseclass for all Line, Bar, Scatter, Candle and Bubble data. 10 | * 11 | * @author Philipp Jahoda 12 | */ 13 | public abstract class BarLineScatterCandleBubbleData> 14 | extends ChartData { 15 | 16 | public BarLineScatterCandleBubbleData() { 17 | super(); 18 | } 19 | 20 | public BarLineScatterCandleBubbleData(T... sets) { 21 | super(sets); 22 | } 23 | 24 | public BarLineScatterCandleBubbleData(List sets) { 25 | super(sets); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/BarLineScatterCandleBubbleDataSet.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import android.graphics.Color; 5 | 6 | import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Baseclass of all DataSets for Bar-, Line-, Scatter- and CandleStickChart. 12 | * 13 | * @author Philipp Jahoda 14 | */ 15 | public abstract class BarLineScatterCandleBubbleDataSet 16 | extends DataSet 17 | implements IBarLineScatterCandleBubbleDataSet { 18 | 19 | /** 20 | * default highlight color 21 | */ 22 | protected int mHighLightColor = Color.rgb(255, 187, 115); 23 | 24 | public BarLineScatterCandleBubbleDataSet(List yVals, String label) { 25 | super(yVals, label); 26 | } 27 | 28 | /** 29 | * Sets the color that is used for drawing the highlight indicators. Dont 30 | * forget to resolve the color using getResources().getColor(...) or 31 | * Color.rgb(...). 32 | * 33 | * @param color 34 | */ 35 | public void setHighLightColor(int color) { 36 | mHighLightColor = color; 37 | } 38 | 39 | @Override 40 | public int getHighLightColor() { 41 | return mHighLightColor; 42 | } 43 | 44 | protected void copy(BarLineScatterCandleBubbleDataSet barLineScatterCandleBubbleDataSet) { 45 | super.copy(barLineScatterCandleBubbleDataSet); 46 | barLineScatterCandleBubbleDataSet.mHighLightColor = mHighLightColor; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseEntry.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data; 2 | 3 | import android.graphics.drawable.Drawable; 4 | 5 | /** 6 | * Created by Philipp Jahoda on 02/06/16. 7 | */ 8 | public abstract class BaseEntry { 9 | 10 | /** the y value */ 11 | private float y = 0f; 12 | 13 | /** optional spot for additional data this Entry represents */ 14 | private Object mData = null; 15 | 16 | /** optional icon image */ 17 | private Drawable mIcon = null; 18 | 19 | public BaseEntry() { 20 | 21 | } 22 | 23 | public BaseEntry(float y) { 24 | this.y = y; 25 | } 26 | 27 | public BaseEntry(float y, Object data) { 28 | this(y); 29 | this.mData = data; 30 | } 31 | 32 | public BaseEntry(float y, Drawable icon) { 33 | this(y); 34 | this.mIcon = icon; 35 | } 36 | 37 | public BaseEntry(float y, Drawable icon, Object data) { 38 | this(y); 39 | this.mIcon = icon; 40 | this.mData = data; 41 | } 42 | 43 | /** 44 | * Returns the y value of this Entry. 45 | * 46 | * @return 47 | */ 48 | public float getY() { 49 | return y; 50 | } 51 | 52 | /** 53 | * Sets the icon drawable 54 | * 55 | * @param icon 56 | */ 57 | public void setIcon(Drawable icon) { 58 | this.mIcon = icon; 59 | } 60 | 61 | /** 62 | * Returns the icon of this Entry. 63 | * 64 | * @return 65 | */ 66 | public Drawable getIcon() { 67 | return mIcon; 68 | } 69 | 70 | /** 71 | * Sets the y-value for the Entry. 72 | * 73 | * @param y 74 | */ 75 | public void setY(float y) { 76 | this.y = y; 77 | } 78 | 79 | /** 80 | * Returns the data, additional information that this Entry represents, or 81 | * null, if no data has been specified. 82 | * 83 | * @return 84 | */ 85 | public Object getData() { 86 | return mData; 87 | } 88 | 89 | /** 90 | * Sets additional data this Entry should represent. 91 | * 92 | * @param data 93 | */ 94 | public void setData(Object data) { 95 | this.mData = data; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/BubbleData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet; 5 | 6 | import java.util.List; 7 | 8 | public class BubbleData extends BarLineScatterCandleBubbleData { 9 | 10 | public BubbleData() { 11 | super(); 12 | } 13 | 14 | public BubbleData(IBubbleDataSet... dataSets) { 15 | super(dataSets); 16 | } 17 | 18 | public BubbleData(List dataSets) { 19 | super(dataSets); 20 | } 21 | 22 | 23 | /** 24 | * Sets the width of the circle that surrounds the bubble when highlighted 25 | * for all DataSet objects this data object contains, in dp. 26 | * 27 | * @param width 28 | */ 29 | public void setHighlightCircleWidth(float width) { 30 | for (IBubbleDataSet set : mDataSets) { 31 | set.setHighlightCircleWidth(width); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/BubbleDataSet.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet; 5 | import com.github.mikephil.charting.utils.Utils; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class BubbleDataSet extends BarLineScatterCandleBubbleDataSet implements IBubbleDataSet { 11 | 12 | protected float mMaxSize; 13 | protected boolean mNormalizeSize = true; 14 | 15 | private float mHighlightCircleWidth = 2.5f; 16 | 17 | public BubbleDataSet(List yVals, String label) { 18 | super(yVals, label); 19 | } 20 | 21 | @Override 22 | public void setHighlightCircleWidth(float width) { 23 | mHighlightCircleWidth = Utils.convertDpToPixel(width); 24 | } 25 | 26 | @Override 27 | public float getHighlightCircleWidth() { 28 | return mHighlightCircleWidth; 29 | } 30 | 31 | @Override 32 | protected void calcMinMax(BubbleEntry e) { 33 | super.calcMinMax(e); 34 | 35 | final float size = e.getSize(); 36 | 37 | if (size > mMaxSize) { 38 | mMaxSize = size; 39 | } 40 | } 41 | 42 | @Override 43 | public DataSet copy() { 44 | List entries = new ArrayList(); 45 | for (int i = 0; i < mValues.size(); i++) { 46 | entries.add(mValues.get(i).copy()); 47 | } 48 | BubbleDataSet copied = new BubbleDataSet(entries, getLabel()); 49 | copy(copied); 50 | return copied; 51 | } 52 | 53 | protected void copy(BubbleDataSet bubbleDataSet) { 54 | bubbleDataSet.mHighlightCircleWidth = mHighlightCircleWidth; 55 | bubbleDataSet.mNormalizeSize = mNormalizeSize; 56 | } 57 | 58 | @Override 59 | public float getMaxSize() { 60 | return mMaxSize; 61 | } 62 | 63 | @Override 64 | public boolean isNormalizeSizeEnabled() { 65 | return mNormalizeSize; 66 | } 67 | 68 | public void setNormalizeSizeEnabled(boolean normalizeSize) { 69 | mNormalizeSize = normalizeSize; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/BubbleEntry.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import android.annotation.SuppressLint; 5 | import android.graphics.drawable.Drawable; 6 | 7 | /** 8 | * Subclass of Entry that holds a value for one entry in a BubbleChart. Bubble 9 | * chart implementation: Copyright 2015 Pierre-Marc Airoldi Licensed under 10 | * Apache License 2.0 11 | * 12 | * @author Philipp Jahoda 13 | */ 14 | @SuppressLint("ParcelCreator") 15 | public class BubbleEntry extends Entry { 16 | 17 | /** size value */ 18 | private float mSize = 0f; 19 | 20 | /** 21 | * Constructor. 22 | * 23 | * @param x The value on the x-axis. 24 | * @param y The value on the y-axis. 25 | * @param size The size of the bubble. 26 | */ 27 | public BubbleEntry(float x, float y, float size) { 28 | super(x, y); 29 | this.mSize = size; 30 | } 31 | 32 | /** 33 | * Constructor. 34 | * 35 | * @param x The value on the x-axis. 36 | * @param y The value on the y-axis. 37 | * @param size The size of the bubble. 38 | * @param data Spot for additional data this Entry represents. 39 | */ 40 | public BubbleEntry(float x, float y, float size, Object data) { 41 | super(x, y, data); 42 | this.mSize = size; 43 | } 44 | 45 | /** 46 | * Constructor. 47 | * 48 | * @param x The value on the x-axis. 49 | * @param y The value on the y-axis. 50 | * @param size The size of the bubble. 51 | * @param icon Icon image 52 | */ 53 | public BubbleEntry(float x, float y, float size, Drawable icon) { 54 | super(x, y, icon); 55 | this.mSize = size; 56 | } 57 | 58 | /** 59 | * Constructor. 60 | * 61 | * @param x The value on the x-axis. 62 | * @param y The value on the y-axis. 63 | * @param size The size of the bubble. 64 | * @param icon Icon image 65 | * @param data Spot for additional data this Entry represents. 66 | */ 67 | public BubbleEntry(float x, float y, float size, Drawable icon, Object data) { 68 | super(x, y, icon, data); 69 | this.mSize = size; 70 | } 71 | 72 | public BubbleEntry copy() { 73 | 74 | BubbleEntry c = new BubbleEntry(getX(), getY(), mSize, getData()); 75 | return c; 76 | } 77 | 78 | /** 79 | * Returns the size of this entry (the size of the bubble). 80 | * 81 | * @return 82 | */ 83 | public float getSize() { 84 | return mSize; 85 | } 86 | 87 | public void setSize(float size) { 88 | this.mSize = size; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/CandleData.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data; 2 | 3 | import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class CandleData extends BarLineScatterCandleBubbleData { 9 | 10 | public CandleData() { 11 | super(); 12 | } 13 | 14 | public CandleData(List dataSets) { 15 | super(dataSets); 16 | } 17 | 18 | public CandleData(ICandleDataSet... dataSets) { 19 | super(dataSets); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/LineData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * Data object that encapsulates all data associated with a LineChart. 11 | * 12 | * @author Philipp Jahoda 13 | */ 14 | public class LineData extends BarLineScatterCandleBubbleData { 15 | 16 | public LineData() { 17 | super(); 18 | } 19 | 20 | public LineData(ILineDataSet... dataSets) { 21 | super(dataSets); 22 | } 23 | 24 | public LineData(List dataSets) { 25 | super(dataSets); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/PieData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.highlight.Highlight; 5 | import com.github.mikephil.charting.interfaces.datasets.IPieDataSet; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * A PieData object can only represent one DataSet. Unlike all other charts, the 12 | * legend labels of the PieChart are created from the x-values array, and not 13 | * from the DataSet labels. Each PieData object can only represent one 14 | * PieDataSet (multiple PieDataSets inside a single PieChart are not possible). 15 | * 16 | * @author Philipp Jahoda 17 | */ 18 | public class PieData extends ChartData { 19 | 20 | public PieData() { 21 | super(); 22 | } 23 | 24 | public PieData(IPieDataSet dataSet) { 25 | super(dataSet); 26 | } 27 | 28 | /** 29 | * Sets the PieDataSet this data object should represent. 30 | * 31 | * @param dataSet 32 | */ 33 | public void setDataSet(IPieDataSet dataSet) { 34 | mDataSets.clear(); 35 | mDataSets.add(dataSet); 36 | notifyDataChanged(); 37 | } 38 | 39 | /** 40 | * Returns the DataSet this PieData object represents. A PieData object can 41 | * only contain one DataSet. 42 | * 43 | * @return 44 | */ 45 | public IPieDataSet getDataSet() { 46 | return mDataSets.get(0); 47 | } 48 | 49 | /** 50 | * The PieData object can only have one DataSet. Use getDataSet() method instead. 51 | * 52 | * @param index 53 | * @return 54 | */ 55 | @Override 56 | public IPieDataSet getDataSetByIndex(int index) { 57 | return index == 0 ? getDataSet() : null; 58 | } 59 | 60 | @Override 61 | public IPieDataSet getDataSetByLabel(String label, boolean ignorecase) { 62 | return ignorecase ? label.equalsIgnoreCase(mDataSets.get(0).getLabel()) ? mDataSets.get(0) 63 | : null : label.equals(mDataSets.get(0).getLabel()) ? mDataSets.get(0) : null; 64 | } 65 | 66 | @Override 67 | public Entry getEntryForHighlight(Highlight highlight) { 68 | return getDataSet().getEntryForIndex((int) highlight.getX()); 69 | } 70 | 71 | /** 72 | * Returns the sum of all values in this PieData object. 73 | * 74 | * @return 75 | */ 76 | public float getYValueSum() { 77 | 78 | float sum = 0; 79 | 80 | for (int i = 0; i < getDataSet().getEntryCount(); i++) 81 | sum += getDataSet().getEntryForIndex(i).getY(); 82 | 83 | 84 | return sum; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/PieEntry.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.graphics.drawable.Drawable; 5 | import android.util.Log; 6 | 7 | /** 8 | * @author Philipp Jahoda 9 | */ 10 | @SuppressLint("ParcelCreator") 11 | public class PieEntry extends Entry { 12 | 13 | private String label; 14 | 15 | public PieEntry(float value) { 16 | super(0f, value); 17 | } 18 | 19 | public PieEntry(float value, Object data) { 20 | super(0f, value, data); 21 | } 22 | 23 | public PieEntry(float value, Drawable icon) { 24 | super(0f, value, icon); 25 | } 26 | 27 | public PieEntry(float value, Drawable icon, Object data) { 28 | super(0f, value, icon, data); 29 | } 30 | 31 | public PieEntry(float value, String label) { 32 | super(0f, value); 33 | this.label = label; 34 | } 35 | 36 | public PieEntry(float value, String label, Object data) { 37 | super(0f, value, data); 38 | this.label = label; 39 | } 40 | 41 | public PieEntry(float value, String label, Drawable icon) { 42 | super(0f, value, icon); 43 | this.label = label; 44 | } 45 | 46 | public PieEntry(float value, String label, Drawable icon, Object data) { 47 | super(0f, value, icon, data); 48 | this.label = label; 49 | } 50 | 51 | /** 52 | * This is the same as getY(). Returns the value of the PieEntry. 53 | * 54 | * @return 55 | */ 56 | public float getValue() { 57 | return getY(); 58 | } 59 | 60 | public String getLabel() { 61 | return label; 62 | } 63 | 64 | public void setLabel(String label) { 65 | this.label = label; 66 | } 67 | 68 | @Deprecated 69 | @Override 70 | public void setX(float x) { 71 | super.setX(x); 72 | Log.i("DEPRECATED", "Pie entries do not have x values"); 73 | } 74 | 75 | @Deprecated 76 | @Override 77 | public float getX() { 78 | Log.i("DEPRECATED", "Pie entries do not have x values"); 79 | return super.getX(); 80 | } 81 | 82 | public PieEntry copy() { 83 | PieEntry e = new PieEntry(getY(), label, getData()); 84 | return e; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.highlight.Highlight; 5 | import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | /** 12 | * Data container for the RadarChart. 13 | * 14 | * @author Philipp Jahoda 15 | */ 16 | public class RadarData extends ChartData { 17 | 18 | private List mLabels; 19 | 20 | public RadarData() { 21 | super(); 22 | } 23 | 24 | public RadarData(List dataSets) { 25 | super(dataSets); 26 | } 27 | 28 | public RadarData(IRadarDataSet... dataSets) { 29 | super(dataSets); 30 | } 31 | 32 | /** 33 | * Sets the labels that should be drawn around the RadarChart at the end of each web line. 34 | * 35 | * @param labels 36 | */ 37 | public void setLabels(List labels) { 38 | this.mLabels = labels; 39 | } 40 | 41 | /** 42 | * Sets the labels that should be drawn around the RadarChart at the end of each web line. 43 | * 44 | * @param labels 45 | */ 46 | public void setLabels(String... labels) { 47 | this.mLabels = Arrays.asList(labels); 48 | } 49 | 50 | public List getLabels() { 51 | return mLabels; 52 | } 53 | 54 | @Override 55 | public Entry getEntryForHighlight(Highlight highlight) { 56 | return getDataSetByIndex(highlight.getDataSetIndex()).getEntryForIndex((int) highlight.getX()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarEntry.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.data; 2 | 3 | import android.annotation.SuppressLint; 4 | 5 | /** 6 | * Created by philipp on 13/06/16. 7 | */ 8 | @SuppressLint("ParcelCreator") 9 | public class RadarEntry extends Entry { 10 | 11 | public RadarEntry(float value) { 12 | super(0f, value); 13 | } 14 | 15 | public RadarEntry(float value, Object data) { 16 | super(0f, value, data); 17 | } 18 | 19 | /** 20 | * This is the same as getY(). Returns the value of the RadarEntry. 21 | * 22 | * @return 23 | */ 24 | public float getValue() { 25 | return getY(); 26 | } 27 | 28 | public RadarEntry copy() { 29 | RadarEntry e = new RadarEntry(getY(), getData()); 30 | return e; 31 | } 32 | 33 | @Deprecated 34 | @Override 35 | public void setX(float x) { 36 | super.setX(x); 37 | } 38 | 39 | @Deprecated 40 | @Override 41 | public float getX() { 42 | return super.getX(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/ScatterData.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data; 3 | 4 | import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; 5 | 6 | import java.util.List; 7 | 8 | public class ScatterData extends BarLineScatterCandleBubbleData { 9 | 10 | public ScatterData() { 11 | super(); 12 | } 13 | 14 | public ScatterData(List dataSets) { 15 | super(dataSets); 16 | } 17 | 18 | public ScatterData(IScatterDataSet... dataSets) { 19 | super(dataSets); 20 | } 21 | 22 | /** 23 | * Returns the maximum shape-size across all DataSets. 24 | * 25 | * @return 26 | */ 27 | public float getGreatestShapeSize() { 28 | 29 | float max = 0f; 30 | 31 | for (IScatterDataSet set : mDataSets) { 32 | float size = set.getScatterShapeSize(); 33 | 34 | if (size > max) 35 | max = size; 36 | } 37 | 38 | return max; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/data/filter/Approximator.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.data.filter; 3 | 4 | import android.annotation.TargetApi; 5 | import android.os.Build; 6 | 7 | import java.util.Arrays; 8 | 9 | /** 10 | * Implemented according to Wiki-Pseudocode {@link} 11 | * http://en.wikipedia.org/wiki/Ramer�Douglas�Peucker_algorithm 12 | * 13 | * @author Philipp Baldauf & Phliipp Jahoda 14 | */ 15 | public class Approximator { 16 | 17 | @TargetApi(Build.VERSION_CODES.GINGERBREAD) 18 | public float[] reduceWithDouglasPeucker(float[] points, float tolerance) { 19 | 20 | int greatestIndex = 0; 21 | float greatestDistance = 0f; 22 | 23 | Line line = new Line(points[0], points[1], points[points.length - 2], points[points.length - 1]); 24 | 25 | for (int i = 2; i < points.length - 2; i += 2) { 26 | 27 | float distance = line.distance(points[i], points[i + 1]); 28 | 29 | if (distance > greatestDistance) { 30 | greatestDistance = distance; 31 | greatestIndex = i; 32 | } 33 | } 34 | 35 | if (greatestDistance > tolerance) { 36 | 37 | float[] reduced1 = reduceWithDouglasPeucker(Arrays.copyOfRange(points, 0, greatestIndex + 2), tolerance); 38 | float[] reduced2 = reduceWithDouglasPeucker(Arrays.copyOfRange(points, greatestIndex, points.length), 39 | tolerance); 40 | 41 | float[] result1 = reduced1; 42 | float[] result2 = Arrays.copyOfRange(reduced2, 2, reduced2.length); 43 | 44 | return concat(result1, result2); 45 | } else { 46 | return line.getPoints(); 47 | } 48 | } 49 | 50 | /** 51 | * Combine arrays. 52 | * 53 | * @param arrays 54 | * @return 55 | */ 56 | float[] concat(float[]... arrays) { 57 | int length = 0; 58 | for (float[] array : arrays) { 59 | length += array.length; 60 | } 61 | float[] result = new float[length]; 62 | int pos = 0; 63 | for (float[] array : arrays) { 64 | for (float element : array) { 65 | result[pos] = element; 66 | pos++; 67 | } 68 | } 69 | return result; 70 | } 71 | 72 | private class Line { 73 | 74 | private float[] points; 75 | 76 | private float sxey; 77 | private float exsy; 78 | 79 | private float dx; 80 | private float dy; 81 | 82 | private float length; 83 | 84 | public Line(float x1, float y1, float x2, float y2) { 85 | dx = x1 - x2; 86 | dy = y1 - y2; 87 | sxey = x1 * y2; 88 | exsy = x2 * y1; 89 | length = (float) Math.sqrt(dx * dx + dy * dy); 90 | 91 | points = new float[]{x1, y1, x2, y2}; 92 | } 93 | 94 | public float distance(float x, float y) { 95 | return Math.abs(dy * x - dx * y + sxey - exsy) / length; 96 | } 97 | 98 | public float[] getPoints() { 99 | return points; 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/entity/BarDataEntity.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.entity; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Random; 7 | 8 | /** 9 | *
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 typeList; 20 | 21 | public List getTypeList() { 22 | return typeList; 23 | } 24 | 25 | public static class Type implements Serializable { 26 | private String typeName;//类型名称 27 | private int sale;//销量 28 | private double typeScale;//类型占比 29 | 30 | public String getTypeName() { 31 | return typeName; 32 | } 33 | 34 | public void setTypeName(String typeName) { 35 | this.typeName = typeName; 36 | } 37 | 38 | public int getSale() { 39 | return sale; 40 | } 41 | 42 | public void setSale(int sale) { 43 | this.sale = sale; 44 | } 45 | 46 | public double getTypeScale() { 47 | return typeScale; 48 | } 49 | 50 | public void setTypeScale(double typeScale) { 51 | this.typeScale = typeScale; 52 | } 53 | } 54 | 55 | public List parseData(){ 56 | typeList = new ArrayList<>(); 57 | Random r = new Random(); 58 | int all=0; 59 | for (int i= 0;i<=6;i++){ 60 | Type type = new Type(); 61 | type.setSale(r.nextInt(100)); 62 | type.setTypeName("品类" + i); 63 | typeList.add(type); 64 | } 65 | for (int i= 0;i<=6;i++){ 66 | all+= typeList.get(i).getSale(); 67 | } 68 | for (int i= 0;i<=6;i++){ 69 | double typeScale = (double) typeList.get(i).getSale()/all; 70 | typeList.get(i).setTypeScale(typeScale); 71 | System.out.println("==>"+typeList.get(i).getTypeScale()); 72 | } 73 | return typeList; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/entity/PercentageEntity.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.entity; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | /** 7 | * @author 张海洋 8 | * @Date on 2018/09/26. 9 | * @org 上海..科技有限公司 10 | * @describe 11 | */ 12 | 13 | public class PercentageEntity { 14 | private String overviewName;//区块名称 15 | private List recordList;//数据列表,按时间区间 16 | 17 | public static class Record implements Serializable { 18 | private String date;//时间区间 19 | private String exponentList; 20 | private String solidLineData; 21 | 22 | public String getDate() { 23 | return date; 24 | } 25 | public void setDate(String date) { 26 | this.date = date; 27 | } 28 | public String getExponentList() { 29 | return exponentList; 30 | } 31 | public void setExponentList(String exponentList) { 32 | this.exponentList = exponentList; 33 | } 34 | 35 | public String getSolidLineData() { 36 | return solidLineData; 37 | } 38 | public void setSolidLineData(String solidLineData) { 39 | this.solidLineData = solidLineData; 40 | } 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/entity/RealListEntity.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.entity; 2 | /** 3 | *
 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 list; 70 | 71 | public List parseData() { 72 | list = new ArrayList<>(); 73 | Random r = new Random(); 74 | for (int i= 0;i<=6;i++){ 75 | Source source = new Source(); 76 | source.setBadCount(r.nextInt(100)); 77 | source.setGoodCount(r.nextInt(100)); 78 | source.setOtherCount(r.nextInt(100)); 79 | source.setScale(r.nextInt(100)); 80 | source.setSource("品类" + i); 81 | source.setAllCount(source.getBadCount() + source.getGoodCount() + source.getOtherCount()); 82 | list.add(source); 83 | } 84 | return list; 85 | } 86 | 87 | 88 | 89 | public List getList() { 90 | return list; 91 | } 92 | 93 | public void setList(List list) { 94 | this.list = list; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/entity/YoyListEntity.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.entity; 2 | 3 | /** 4 | *
 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 values) { 43 | if (values != null) 44 | setValues(values.toArray(new String[values.size()])); 45 | } 46 | 47 | public String getFormattedValue(float value, AxisBase axis) { 48 | int index = Math.round(value); 49 | 50 | if (index < 0 || index >= mValueCount || index != (int)value) 51 | return ""; 52 | 53 | return mValues[index]; 54 | } 55 | 56 | public String[] getValues() 57 | { 58 | return mValues; 59 | } 60 | 61 | public void setValues(String[] values) 62 | { 63 | if (values == null) 64 | values = new String[] {}; 65 | 66 | this.mValues = values; 67 | this.mValueCount = values.length; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.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 | 10 | /** 11 | * This IValueFormatter is just for convenience and simply puts a "%" sign after 12 | * each value. (Recommeded for PieChart) 13 | * 14 | * @author Philipp Jahoda 15 | */ 16 | public class PercentFormatter implements IValueFormatter, IAxisValueFormatter 17 | { 18 | 19 | protected DecimalFormat mFormat; 20 | 21 | public PercentFormatter() { 22 | mFormat = new DecimalFormat("###,###,##0.0"); 23 | } 24 | 25 | /** 26 | * Allow a custom decimalformat 27 | * 28 | * @param format 29 | */ 30 | public PercentFormatter(DecimalFormat format) { 31 | this.mFormat = format; 32 | } 33 | 34 | // IValueFormatter 35 | @Override 36 | public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { 37 | return mFormat.format(value) + " %"; 38 | } 39 | 40 | // IAxisValueFormatter 41 | @Override 42 | public String getFormattedValue(float value, AxisBase axis) { 43 | return mFormat.format(value) + " %"; 44 | } 45 | 46 | public int getDecimalDigits() { 47 | return 1; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/formatter/StackedValueFormatter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.formatter; 2 | 3 | import com.github.mikephil.charting.data.BarEntry; 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 | * Created by Philipp Jahoda on 28/01/16. 11 | *

12 | * A formatter specifically for stacked BarChart that allows to specify whether the all stack values 13 | * or just the top value should be drawn. 14 | */ 15 | public class StackedValueFormatter implements IValueFormatter 16 | { 17 | 18 | /** 19 | * if true, all stack values of the stacked bar entry are drawn, else only top 20 | */ 21 | private boolean mDrawWholeStack; 22 | 23 | /** 24 | * a string that should be appended behind the value 25 | */ 26 | private String mAppendix; 27 | 28 | private DecimalFormat mFormat; 29 | 30 | /** 31 | * Constructor. 32 | * 33 | * @param drawWholeStack if true, all stack values of the stacked bar entry are drawn, else only top 34 | * @param appendix a string that should be appended behind the value 35 | * @param decimals the number of decimal digits to use 36 | */ 37 | public StackedValueFormatter(boolean drawWholeStack, String appendix, int decimals) { 38 | this.mDrawWholeStack = drawWholeStack; 39 | this.mAppendix = appendix; 40 | 41 | StringBuffer b = new StringBuffer(); 42 | for (int i = 0; i < decimals; i++) { 43 | if (i == 0) 44 | b.append("."); 45 | b.append("0"); 46 | } 47 | 48 | this.mFormat = new DecimalFormat("###,###,###,##0" + b.toString()); 49 | } 50 | 51 | @Override 52 | public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { 53 | 54 | if (!mDrawWholeStack && entry instanceof BarEntry) { 55 | 56 | BarEntry barEntry = (BarEntry) entry; 57 | float[] vals = barEntry.getYVals(); 58 | 59 | if (vals != null) { 60 | 61 | // find out if we are on top of the stack 62 | if (vals[vals.length - 1] == value) { 63 | 64 | // return the "sum" across all stack values 65 | return mFormat.format(barEntry.getY()) + mAppendix; 66 | } else { 67 | return ""; // return empty 68 | } 69 | } 70 | } 71 | 72 | // return the "proposed" value 73 | return mFormat.format(value) + mAppendix; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/highlight/HorizontalBarHighlighter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.highlight; 2 | 3 | import com.github.mikephil.charting.data.BarData; 4 | import com.github.mikephil.charting.data.DataSet; 5 | import com.github.mikephil.charting.data.Entry; 6 | import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider; 7 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; 8 | import com.github.mikephil.charting.interfaces.datasets.IDataSet; 9 | import com.github.mikephil.charting.utils.MPPointD; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * Created by Philipp Jahoda on 22/07/15. 16 | */ 17 | public class HorizontalBarHighlighter extends BarHighlighter { 18 | 19 | public HorizontalBarHighlighter(BarDataProvider chart) { 20 | super(chart); 21 | } 22 | 23 | @Override 24 | public Highlight getHighlight(float x, float y) { 25 | 26 | BarData barData = mChart.getBarData(); 27 | 28 | MPPointD pos = getValsForTouch(y, x); 29 | 30 | Highlight high = getHighlightForX((float) pos.y, y, x); 31 | if (high == null) 32 | return null; 33 | 34 | IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex()); 35 | if (set.isStacked()) { 36 | 37 | return getStackedHighlight(high, 38 | set, 39 | (float) pos.y, 40 | (float) pos.x); 41 | } 42 | 43 | MPPointD.recycleInstance(pos); 44 | 45 | return high; 46 | } 47 | 48 | @Override 49 | protected List buildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) { 50 | 51 | ArrayList highlights = new ArrayList<>(); 52 | 53 | //noinspection unchecked 54 | List entries = set.getEntriesForXValue(xVal); 55 | if (entries.size() == 0) { 56 | // Try to find closest x-value and take all entries for that x-value 57 | final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding); 58 | if (closest != null) 59 | { 60 | //noinspection unchecked 61 | entries = set.getEntriesForXValue(closest.getX()); 62 | } 63 | } 64 | 65 | if (entries.size() == 0) 66 | return highlights; 67 | 68 | for (Entry e : entries) { 69 | MPPointD pixels = mChart.getTransformer( 70 | set.getAxisDependency()).getPixelForValues(e.getY(), e.getX()); 71 | 72 | highlights.add(new Highlight( 73 | e.getX(), e.getY(), 74 | (float) pixels.x, (float) pixels.y, 75 | dataSetIndex, set.getAxisDependency())); 76 | } 77 | 78 | return highlights; 79 | } 80 | 81 | @Override 82 | protected float getDistance(float x1, float y1, float x2, float y2) { 83 | return Math.abs(y1 - y2); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/highlight/IHighlighter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.highlight; 2 | 3 | /** 4 | * Created by philipp on 10/06/16. 5 | */ 6 | public interface IHighlighter 7 | { 8 | 9 | /** 10 | * Returns a Highlight object corresponding to the given x- and y- touch positions in pixels. 11 | * 12 | * @param x 13 | * @param y 14 | * @return 15 | */ 16 | Highlight getHighlight(float x, float y); 17 | } 18 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieHighlighter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.highlight; 2 | 3 | import com.github.mikephil.charting.charts.PieChart; 4 | import com.github.mikephil.charting.data.Entry; 5 | import com.github.mikephil.charting.interfaces.datasets.IPieDataSet; 6 | 7 | /** 8 | * Created by philipp on 12/06/16. 9 | */ 10 | public class PieHighlighter extends PieRadarHighlighter { 11 | 12 | public PieHighlighter(PieChart chart) { 13 | super(chart); 14 | } 15 | 16 | @Override 17 | protected Highlight getClosestHighlight(int index, float x, float y) { 18 | 19 | IPieDataSet set = mChart.getData().getDataSet(); 20 | 21 | final Entry entry = set.getEntryForIndex(index); 22 | 23 | return new Highlight(index, entry.getY(), x, y, 0, set.getAxisDependency()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/highlight/PieRadarHighlighter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.highlight; 2 | 3 | import com.github.mikephil.charting.charts.PieChart; 4 | import com.github.mikephil.charting.charts.PieRadarChartBase; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by philipp on 12/06/16. 11 | */ 12 | public abstract class PieRadarHighlighter implements IHighlighter 13 | { 14 | 15 | protected T mChart; 16 | 17 | /** 18 | * buffer for storing previously highlighted values 19 | */ 20 | protected List mHighlightBuffer = new ArrayList(); 21 | 22 | public PieRadarHighlighter(T chart) { 23 | this.mChart = chart; 24 | } 25 | 26 | @Override 27 | public Highlight getHighlight(float x, float y) { 28 | 29 | float touchDistanceToCenter = mChart.distanceToCenter(x, y); 30 | 31 | // check if a slice was touched 32 | if (touchDistanceToCenter > mChart.getRadius()) { 33 | 34 | // if no slice was touched, highlight nothing 35 | return null; 36 | 37 | } else { 38 | 39 | float angle = mChart.getAngleForPoint(x, y); 40 | 41 | if (mChart instanceof PieChart) { 42 | angle /= mChart.getAnimator().getPhaseY(); 43 | } 44 | 45 | int index = mChart.getIndexForAngle(angle); 46 | 47 | // check if the index could be found 48 | if (index < 0 || index >= mChart.getData().getMaxEntryCountSet().getEntryCount()) { 49 | return null; 50 | 51 | } else { 52 | return getClosestHighlight(index, x, y); 53 | } 54 | } 55 | } 56 | 57 | /** 58 | * Returns the closest Highlight object of the given objects based on the touch position inside the chart. 59 | * 60 | * @param index 61 | * @param x 62 | * @param y 63 | * @return 64 | */ 65 | protected abstract Highlight getClosestHighlight(int index, float x, float y); 66 | } 67 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/highlight/RadarHighlighter.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.highlight; 2 | 3 | import com.github.mikephil.charting.charts.RadarChart; 4 | import com.github.mikephil.charting.data.Entry; 5 | import com.github.mikephil.charting.interfaces.datasets.IDataSet; 6 | import com.github.mikephil.charting.utils.MPPointF; 7 | import com.github.mikephil.charting.utils.Utils; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by philipp on 12/06/16. 13 | */ 14 | public class RadarHighlighter extends PieRadarHighlighter { 15 | 16 | public RadarHighlighter(RadarChart chart) { 17 | super(chart); 18 | } 19 | 20 | @Override 21 | protected Highlight getClosestHighlight(int index, float x, float y) { 22 | 23 | List highlights = getHighlightsAtIndex(index); 24 | 25 | float distanceToCenter = mChart.distanceToCenter(x, y) / mChart.getFactor(); 26 | 27 | Highlight closest = null; 28 | float distance = Float.MAX_VALUE; 29 | 30 | for (int i = 0; i < highlights.size(); i++) { 31 | 32 | Highlight high = highlights.get(i); 33 | 34 | float cdistance = Math.abs(high.getY() - distanceToCenter); 35 | if (cdistance < distance) { 36 | closest = high; 37 | distance = cdistance; 38 | } 39 | } 40 | 41 | return closest; 42 | } 43 | /** 44 | * Returns an array of Highlight objects for the given index. The Highlight 45 | * objects give information about the value at the selected index and the 46 | * DataSet it belongs to. INFORMATION: This method does calculations at 47 | * runtime. Do not over-use in performance critical situations. 48 | * 49 | * @param index 50 | * @return 51 | */ 52 | protected List getHighlightsAtIndex(int index) { 53 | 54 | mHighlightBuffer.clear(); 55 | 56 | float phaseX = mChart.getAnimator().getPhaseX(); 57 | float phaseY = mChart.getAnimator().getPhaseY(); 58 | float sliceangle = mChart.getSliceAngle(); 59 | float factor = mChart.getFactor(); 60 | 61 | MPPointF pOut = MPPointF.getInstance(0,0); 62 | for (int i = 0; i < mChart.getData().getDataSetCount(); i++) { 63 | 64 | IDataSet dataSet = mChart.getData().getDataSetByIndex(i); 65 | 66 | final Entry entry = dataSet.getEntryForIndex(index); 67 | 68 | float y = (entry.getY() - mChart.getYChartMin()); 69 | 70 | Utils.getPosition( 71 | mChart.getCenterOffsets(), y * factor * phaseY, 72 | sliceangle * index * phaseX + mChart.getRotationAngle(), pOut); 73 | 74 | mHighlightBuffer.add(new Highlight(index, entry.getY(), pOut.x, pOut.y, i, dataSet.getAxisDependency())); 75 | } 76 | 77 | return mHighlightBuffer; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/highlight/Range.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.highlight; 2 | 3 | /** 4 | * Created by Philipp Jahoda on 24/07/15. Class that represents the range of one value in a stacked bar entry. e.g. 5 | * stack values are -10, 5, 20 -> then ranges are (-10 - 0, 0 - 5, 5 - 25). 6 | */ 7 | public final class Range { 8 | 9 | public float from; 10 | public float to; 11 | 12 | public Range(float from, float to) { 13 | this.from = from; 14 | this.to = to; 15 | } 16 | 17 | /** 18 | * Returns true if this range contains (if the value is in between) the given value, false if not. 19 | * 20 | * @param value 21 | * @return 22 | */ 23 | public boolean contains(float value) { 24 | 25 | if (value > from && value <= to) 26 | return true; 27 | else 28 | return false; 29 | } 30 | 31 | public boolean isLarger(float value) { 32 | return value > to; 33 | } 34 | 35 | public boolean isSmaller(float value) { 36 | return value < from; 37 | } 38 | } -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/BarDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import com.github.mikephil.charting.data.BarData; 4 | 5 | public interface BarDataProvider extends BarLineScatterCandleBubbleDataProvider { 6 | 7 | BarData getBarData(); 8 | boolean isDrawBarShadowEnabled(); 9 | boolean isDrawValueAboveBarEnabled(); 10 | boolean isHighlightFullBarEnabled(); 11 | } 12 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/BarLineScatterCandleBubbleDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import com.github.mikephil.charting.components.YAxis.AxisDependency; 4 | import com.github.mikephil.charting.data.BarLineScatterCandleBubbleData; 5 | import com.github.mikephil.charting.utils.Transformer; 6 | 7 | public interface BarLineScatterCandleBubbleDataProvider extends ChartInterface { 8 | 9 | Transformer getTransformer(AxisDependency axis); 10 | boolean isInverted(AxisDependency axis); 11 | 12 | float getLowestVisibleX(); 13 | float getHighestVisibleX(); 14 | 15 | BarLineScatterCandleBubbleData getData(); 16 | } 17 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/BubbleDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import com.github.mikephil.charting.data.BubbleData; 4 | 5 | public interface BubbleDataProvider extends BarLineScatterCandleBubbleDataProvider { 6 | 7 | BubbleData getBubbleData(); 8 | } 9 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/CandleDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import com.github.mikephil.charting.data.CandleData; 4 | 5 | public interface CandleDataProvider extends BarLineScatterCandleBubbleDataProvider { 6 | 7 | CandleData getCandleData(); 8 | } 9 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/ChartInterface.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import android.graphics.RectF; 4 | 5 | import com.github.mikephil.charting.data.ChartData; 6 | import com.github.mikephil.charting.formatter.IValueFormatter; 7 | import com.github.mikephil.charting.utils.MPPointF; 8 | 9 | /** 10 | * Interface that provides everything there is to know about the dimensions, 11 | * bounds, and range of the chart. 12 | * 13 | * @author Philipp Jahoda 14 | */ 15 | public interface ChartInterface { 16 | 17 | /** 18 | * Returns the minimum x value of the chart, regardless of zoom or translation. 19 | * 20 | * @return 21 | */ 22 | float getXChartMin(); 23 | 24 | /** 25 | * Returns the maximum x value of the chart, regardless of zoom or translation. 26 | * 27 | * @return 28 | */ 29 | float getXChartMax(); 30 | 31 | float getXRange(); 32 | 33 | /** 34 | * Returns the minimum y value of the chart, regardless of zoom or translation. 35 | * 36 | * @return 37 | */ 38 | float getYChartMin(); 39 | 40 | /** 41 | * Returns the maximum y value of the chart, regardless of zoom or translation. 42 | * 43 | * @return 44 | */ 45 | float getYChartMax(); 46 | 47 | /** 48 | * Returns the maximum distance in scren dp a touch can be away from an entry to cause it to get highlighted. 49 | * 50 | * @return 51 | */ 52 | float getMaxHighlightDistance(); 53 | 54 | int getWidth(); 55 | 56 | int getHeight(); 57 | 58 | MPPointF getCenterOfView(); 59 | 60 | MPPointF getCenterOffsets(); 61 | 62 | RectF getContentRect(); 63 | 64 | IValueFormatter getDefaultValueFormatter(); 65 | 66 | ChartData getData(); 67 | 68 | int getMaxVisibleCount(); 69 | } 70 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/CombinedDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import com.github.mikephil.charting.data.CombinedData; 4 | 5 | /** 6 | * Created by philipp on 11/06/16. 7 | */ 8 | public interface CombinedDataProvider extends LineDataProvider, BarDataProvider, BubbleDataProvider, CandleDataProvider, ScatterDataProvider { 9 | 10 | CombinedData getCombinedData(); 11 | } 12 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/LineDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import com.github.mikephil.charting.components.YAxis; 4 | import com.github.mikephil.charting.data.LineData; 5 | 6 | public interface LineDataProvider extends BarLineScatterCandleBubbleDataProvider { 7 | 8 | LineData getLineData(); 9 | 10 | YAxis getAxis(YAxis.AxisDependency dependency); 11 | } 12 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/ScatterDataProvider.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.dataprovider; 2 | 3 | import com.github.mikephil.charting.data.ScatterData; 4 | 5 | public interface ScatterDataProvider extends BarLineScatterCandleBubbleDataProvider { 6 | 7 | ScatterData getScatterData(); 8 | } 9 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import com.github.mikephil.charting.data.BarEntry; 4 | 5 | /** 6 | * Created by philipp on 21/10/15. 7 | */ 8 | public interface IBarDataSet extends IBarLineScatterCandleBubbleDataSet { 9 | 10 | /** 11 | * Returns true if this DataSet is stacked (stacksize > 1) or not. 12 | * 13 | * @return 14 | */ 15 | boolean isStacked(); 16 | 17 | /** 18 | * Returns the maximum number of bars that can be stacked upon another in 19 | * this DataSet. This should return 1 for non stacked bars, and > 1 for stacked bars. 20 | * 21 | * @return 22 | */ 23 | int getStackSize(); 24 | 25 | /** 26 | * Returns the color used for drawing the bar-shadows. The bar shadows is a 27 | * surface behind the bar that indicates the maximum value. 28 | * 29 | * @return 30 | */ 31 | int getBarShadowColor(); 32 | 33 | /** 34 | * Returns the width used for drawing borders around the bars. 35 | * If borderWidth == 0, no border will be drawn. 36 | * 37 | * @return 38 | */ 39 | float getBarBorderWidth(); 40 | 41 | /** 42 | * Returns the color drawing borders around the bars. 43 | * 44 | * @return 45 | */ 46 | int getBarBorderColor(); 47 | 48 | /** 49 | * Returns the alpha value (transparency) that is used for drawing the 50 | * highlight indicator. 51 | * 52 | * @return 53 | */ 54 | int getHighLightAlpha(); 55 | 56 | 57 | /** 58 | * Returns the labels used for the different value-stacks in the legend. 59 | * This is only relevant for stacked bar entries. 60 | * 61 | * @return 62 | */ 63 | String[] getStackLabels(); 64 | } 65 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBarLineScatterCandleBubbleDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import com.github.mikephil.charting.data.Entry; 4 | 5 | /** 6 | * Created by philipp on 21/10/15. 7 | */ 8 | public interface IBarLineScatterCandleBubbleDataSet extends IDataSet { 9 | 10 | /** 11 | * Returns the color that is used for drawing the highlight indicators. 12 | * 13 | * @return 14 | */ 15 | int getHighLightColor(); 16 | } 17 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IBubbleDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import com.github.mikephil.charting.data.BubbleEntry; 4 | 5 | /** 6 | * Created by philipp on 21/10/15. 7 | */ 8 | public interface IBubbleDataSet extends IBarLineScatterCandleBubbleDataSet { 9 | 10 | /** 11 | * Sets the width of the circle that surrounds the bubble when highlighted, 12 | * in dp. 13 | * 14 | * @param width 15 | */ 16 | void setHighlightCircleWidth(float width); 17 | 18 | float getMaxSize(); 19 | 20 | boolean isNormalizeSizeEnabled(); 21 | 22 | /** 23 | * Returns the width of the highlight-circle that surrounds the bubble 24 | * @return 25 | */ 26 | float getHighlightCircleWidth(); 27 | } 28 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ICandleDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import android.graphics.Paint; 4 | 5 | import com.github.mikephil.charting.data.CandleEntry; 6 | 7 | /** 8 | * Created by philipp on 21/10/15. 9 | */ 10 | public interface ICandleDataSet extends ILineScatterCandleRadarDataSet { 11 | 12 | /** 13 | * Returns the space that is left out on the left and right side of each 14 | * candle. 15 | * 16 | * @return 17 | */ 18 | float getBarSpace(); 19 | 20 | /** 21 | * Returns whether the candle bars should show? 22 | * When false, only "ticks" will show 23 | * 24 | * - default: true 25 | * 26 | * @return 27 | */ 28 | boolean getShowCandleBar(); 29 | 30 | /** 31 | * Returns the width of the candle-shadow-line in pixels. 32 | * 33 | * @return 34 | */ 35 | float getShadowWidth(); 36 | 37 | /** 38 | * Returns shadow color for all entries 39 | * 40 | * @return 41 | */ 42 | int getShadowColor(); 43 | 44 | /** 45 | * Returns the neutral color (for open == close) 46 | * 47 | * @return 48 | */ 49 | int getNeutralColor(); 50 | 51 | /** 52 | * Returns the increasing color (for open < close). 53 | * 54 | * @return 55 | */ 56 | int getIncreasingColor(); 57 | 58 | /** 59 | * Returns the decreasing color (for open > close). 60 | * 61 | * @return 62 | */ 63 | int getDecreasingColor(); 64 | 65 | /** 66 | * Returns paint style when open < close 67 | * 68 | * @return 69 | */ 70 | Paint.Style getIncreasingPaintStyle(); 71 | 72 | /** 73 | * Returns paint style when open > close 74 | * 75 | * @return 76 | */ 77 | Paint.Style getDecreasingPaintStyle(); 78 | 79 | /** 80 | * Is the shadow color same as the candle color? 81 | * 82 | * @return 83 | */ 84 | boolean getShadowColorSameAsCandle(); 85 | } 86 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import android.graphics.DashPathEffect; 4 | 5 | import com.github.mikephil.charting.data.Entry; 6 | import com.github.mikephil.charting.data.LineDataSet; 7 | import com.github.mikephil.charting.formatter.IFillFormatter; 8 | 9 | /** 10 | * Created by Philpp Jahoda on 21/10/15. 11 | */ 12 | public interface ILineDataSet extends ILineRadarDataSet { 13 | 14 | /** 15 | * Returns the drawing mode for this line dataset 16 | * 17 | * @return 18 | */ 19 | LineDataSet.Mode getMode(); 20 | 21 | /** 22 | * Returns the intensity of the cubic lines (the effect intensity). 23 | * Max = 1f = very cubic, Min = 0.05f = low cubic effect, Default: 0.2f 24 | * 25 | * @return 26 | */ 27 | float getCubicIntensity(); 28 | 29 | @Deprecated 30 | boolean isDrawCubicEnabled(); 31 | 32 | @Deprecated 33 | boolean isDrawSteppedEnabled(); 34 | 35 | /** 36 | * Returns the size of the drawn circles. 37 | */ 38 | float getCircleRadius(); 39 | 40 | /** 41 | * Returns the hole radius of the drawn circles. 42 | */ 43 | float getCircleHoleRadius(); 44 | 45 | /** 46 | * Returns the color at the given index of the DataSet's circle-color array. 47 | * Performs a IndexOutOfBounds check by modulus. 48 | * 49 | * @param index 50 | * @return 51 | */ 52 | int getCircleColor(int index); 53 | 54 | /** 55 | * Returns the number of colors in this DataSet's circle-color array. 56 | * 57 | * @return 58 | */ 59 | int getCircleColorCount(); 60 | 61 | /** 62 | * Returns true if drawing circles for this DataSet is enabled, false if not 63 | * 64 | * @return 65 | */ 66 | boolean isDrawCirclesEnabled(); 67 | 68 | /** 69 | * Returns the color of the inner circle (the circle-hole). 70 | * 71 | * @return 72 | */ 73 | int getCircleHoleColor(); 74 | 75 | /** 76 | * Returns true if drawing the circle-holes is enabled, false if not. 77 | * 78 | * @return 79 | */ 80 | boolean isDrawCircleHoleEnabled(); 81 | 82 | /** 83 | * Returns the DashPathEffect that is used for drawing the lines. 84 | * 85 | * @return 86 | */ 87 | DashPathEffect getDashPathEffect(); 88 | 89 | /** 90 | * Returns true if the dashed-line effect is enabled, false if not. 91 | * If the DashPathEffect object is null, also return false here. 92 | * 93 | * @return 94 | */ 95 | boolean isDashedLineEnabled(); 96 | 97 | /** 98 | * Returns the IFillFormatter that is set for this DataSet. 99 | * 100 | * @return 101 | */ 102 | IFillFormatter getFillFormatter(); 103 | } -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineRadarDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import android.graphics.drawable.Drawable; 4 | 5 | import com.github.mikephil.charting.data.Entry; 6 | 7 | /** 8 | * Created by Philipp Jahoda on 21/10/15. 9 | */ 10 | public interface ILineRadarDataSet extends ILineScatterCandleRadarDataSet { 11 | 12 | /** 13 | * Returns the color that is used for filling the line surface area. 14 | * 15 | * @return 16 | */ 17 | int getFillColor(); 18 | 19 | /** 20 | * Returns the drawable used for filling the area below the line. 21 | * 22 | * @return 23 | */ 24 | Drawable getFillDrawable(); 25 | 26 | /** 27 | * Returns the alpha value that is used for filling the line surface, 28 | * default: 85 29 | * 30 | * @return 31 | */ 32 | int getFillAlpha(); 33 | 34 | /** 35 | * Returns the stroke-width of the drawn line 36 | * 37 | * @return 38 | */ 39 | float getLineWidth(); 40 | 41 | /** 42 | * Returns true if filled drawing is enabled, false if not 43 | * 44 | * @return 45 | */ 46 | boolean isDrawFilledEnabled(); 47 | 48 | /** 49 | * Set to true if the DataSet should be drawn filled (surface), and not just 50 | * as a line, disabling this will give great performance boost. Please note that this method 51 | * uses the canvas.clipPath(...) method for drawing the filled area. 52 | * For devices with API level < 18 (Android 4.3), hardware acceleration of the chart should 53 | * be turned off. Default: false 54 | * 55 | * @param enabled 56 | */ 57 | void setDrawFilled(boolean enabled); 58 | } 59 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/ILineScatterCandleRadarDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import android.graphics.DashPathEffect; 4 | 5 | import com.github.mikephil.charting.data.Entry; 6 | 7 | /** 8 | * Created by Philipp Jahoda on 21/10/15. 9 | */ 10 | public interface ILineScatterCandleRadarDataSet extends IBarLineScatterCandleBubbleDataSet { 11 | 12 | /** 13 | * Returns true if vertical highlight indicator lines are enabled (drawn) 14 | * @return 15 | */ 16 | boolean isVerticalHighlightIndicatorEnabled(); 17 | 18 | /** 19 | * Returns true if vertical highlight indicator lines are enabled (drawn) 20 | * @return 21 | */ 22 | boolean isHorizontalHighlightIndicatorEnabled(); 23 | 24 | /** 25 | * Returns the line-width in which highlight lines are to be drawn. 26 | * @return 27 | */ 28 | float getHighlightLineWidth(); 29 | 30 | /** 31 | * Returns the DashPathEffect that is used for highlighting. 32 | * @return 33 | */ 34 | DashPathEffect getDashPathEffectHighlight(); 35 | } 36 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IPieDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import com.github.mikephil.charting.data.PieDataSet; 4 | import com.github.mikephil.charting.data.PieEntry; 5 | 6 | /** 7 | * Created by Philipp Jahoda on 03/11/15. 8 | */ 9 | public interface IPieDataSet extends IDataSet { 10 | 11 | /** 12 | * Returns the space that is set to be between the piechart-slices of this 13 | * DataSet, in pixels. 14 | * 15 | * @return 16 | */ 17 | float getSliceSpace(); 18 | 19 | /** 20 | * When enabled, slice spacing will be 0.0 when the smallest value is going to be 21 | * smaller than the slice spacing itself. 22 | * 23 | * @return 24 | */ 25 | boolean isAutomaticallyDisableSliceSpacingEnabled(); 26 | 27 | /** 28 | * Returns the distance a highlighted piechart slice is "shifted" away from 29 | * the chart-center in dp. 30 | * 31 | * @return 32 | */ 33 | float getSelectionShift(); 34 | 35 | PieDataSet.ValuePosition getXValuePosition(); 36 | PieDataSet.ValuePosition getYValuePosition(); 37 | 38 | /** 39 | * When valuePosition is OutsideSlice, use slice colors as line color if true 40 | * */ 41 | boolean isUsingSliceColorAsValueLineColor(); 42 | 43 | /** 44 | * When valuePosition is OutsideSlice, indicates line color 45 | * */ 46 | int getValueLineColor(); 47 | 48 | /** 49 | * When valuePosition is OutsideSlice, indicates line width 50 | * */ 51 | float getValueLineWidth(); 52 | 53 | /** 54 | * When valuePosition is OutsideSlice, indicates offset as percentage out of the slice size 55 | * */ 56 | float getValueLinePart1OffsetPercentage(); 57 | 58 | /** 59 | * When valuePosition is OutsideSlice, indicates length of first half of the line 60 | * */ 61 | float getValueLinePart1Length(); 62 | 63 | /** 64 | * When valuePosition is OutsideSlice, indicates length of second half of the line 65 | * */ 66 | float getValueLinePart2Length(); 67 | 68 | /** 69 | * When valuePosition is OutsideSlice, this allows variable line length 70 | * */ 71 | boolean isValueLineVariableLength(); 72 | 73 | } 74 | 75 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IRadarDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import com.github.mikephil.charting.data.RadarEntry; 4 | 5 | /** 6 | * Created by Philipp Jahoda on 03/11/15. 7 | */ 8 | public interface IRadarDataSet extends ILineRadarDataSet { 9 | 10 | /// flag indicating whether highlight circle should be drawn or not 11 | boolean isDrawHighlightCircleEnabled(); 12 | 13 | /// Sets whether highlight circle should be drawn or not 14 | void setDrawHighlightCircleEnabled(boolean enabled); 15 | 16 | int getHighlightCircleFillColor(); 17 | 18 | /// The stroke color for highlight circle. 19 | /// If Utils.COLOR_NONE, the color of the dataset is taken. 20 | int getHighlightCircleStrokeColor(); 21 | 22 | int getHighlightCircleStrokeAlpha(); 23 | 24 | float getHighlightCircleInnerRadius(); 25 | 26 | float getHighlightCircleOuterRadius(); 27 | 28 | float getHighlightCircleStrokeWidth(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IScatterDataSet.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.interfaces.datasets; 2 | 3 | import com.github.mikephil.charting.data.Entry; 4 | import com.github.mikephil.charting.renderer.scatter.IShapeRenderer; 5 | 6 | /** 7 | * Created by philipp on 21/10/15. 8 | */ 9 | public interface IScatterDataSet extends ILineScatterCandleRadarDataSet { 10 | 11 | /** 12 | * Returns the currently set scatter shape size 13 | * 14 | * @return 15 | */ 16 | float getScatterShapeSize(); 17 | 18 | /** 19 | * Returns radius of the hole in the shape 20 | * 21 | * @return 22 | */ 23 | float getScatterShapeHoleRadius(); 24 | 25 | /** 26 | * Returns the color for the hole in the shape 27 | * 28 | * @return 29 | */ 30 | int getScatterShapeHoleColor(); 31 | 32 | /** 33 | * Returns the IShapeRenderer responsible for rendering this DataSet. 34 | * 35 | * @return 36 | */ 37 | IShapeRenderer getShapeRenderer(); 38 | } 39 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/jobs/AnimatedMoveViewJob.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.jobs; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.annotation.SuppressLint; 5 | import android.view.View; 6 | 7 | import com.github.mikephil.charting.utils.ObjectPool; 8 | import com.github.mikephil.charting.utils.Transformer; 9 | import com.github.mikephil.charting.utils.ViewPortHandler; 10 | 11 | /** 12 | * Created by Philipp Jahoda on 19/02/16. 13 | */ 14 | @SuppressLint("NewApi") 15 | public class AnimatedMoveViewJob extends AnimatedViewPortJob { 16 | 17 | private static ObjectPool pool; 18 | 19 | static { 20 | pool = ObjectPool.create(4, new AnimatedMoveViewJob(null,0,0,null,null,0,0,0)); 21 | pool.setReplenishPercentage(0.5f); 22 | } 23 | 24 | public static AnimatedMoveViewJob getInstance(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v, float xOrigin, float yOrigin, long duration){ 25 | AnimatedMoveViewJob result = pool.get(); 26 | result.mViewPortHandler = viewPortHandler; 27 | result.xValue = xValue; 28 | result.yValue = yValue; 29 | result.mTrans = trans; 30 | result.view = v; 31 | result.xOrigin = xOrigin; 32 | result.yOrigin = yOrigin; 33 | //result.resetAnimator(); 34 | result.animator.setDuration(duration); 35 | return result; 36 | } 37 | 38 | public static void recycleInstance(AnimatedMoveViewJob instance){ 39 | pool.recycle(instance); 40 | } 41 | 42 | 43 | public AnimatedMoveViewJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v, float xOrigin, float yOrigin, long duration) { 44 | super(viewPortHandler, xValue, yValue, trans, v, xOrigin, yOrigin, duration); 45 | } 46 | 47 | @Override 48 | public void onAnimationUpdate(ValueAnimator animation) { 49 | 50 | pts[0] = xOrigin + (xValue - xOrigin) * phase; 51 | pts[1] = yOrigin + (yValue - yOrigin) * phase; 52 | 53 | mTrans.pointValuesToPixel(pts); 54 | mViewPortHandler.centerViewPort(pts, view); 55 | } 56 | 57 | public void recycleSelf(){ 58 | recycleInstance(this); 59 | } 60 | 61 | @Override 62 | protected ObjectPool.Poolable instantiate() { 63 | return new AnimatedMoveViewJob(null,0,0,null,null,0,0,0); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/jobs/AnimatedViewPortJob.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.jobs; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ObjectAnimator; 5 | import android.animation.ValueAnimator; 6 | import android.annotation.SuppressLint; 7 | import android.view.View; 8 | 9 | import com.github.mikephil.charting.utils.Transformer; 10 | import com.github.mikephil.charting.utils.ViewPortHandler; 11 | 12 | /** 13 | * Created by Philipp Jahoda on 19/02/16. 14 | */ 15 | @SuppressLint("NewApi") 16 | public abstract class AnimatedViewPortJob extends ViewPortJob implements ValueAnimator.AnimatorUpdateListener, Animator.AnimatorListener { 17 | 18 | protected ObjectAnimator animator; 19 | 20 | protected float phase; 21 | 22 | protected float xOrigin; 23 | protected float yOrigin; 24 | 25 | public AnimatedViewPortJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v, float xOrigin, float yOrigin, long duration) { 26 | super(viewPortHandler, xValue, yValue, trans, v); 27 | this.xOrigin = xOrigin; 28 | this.yOrigin = yOrigin; 29 | animator = ObjectAnimator.ofFloat(this, "phase", 0f, 1f); 30 | animator.setDuration(duration); 31 | animator.addUpdateListener(this); 32 | animator.addListener(this); 33 | } 34 | 35 | @SuppressLint("NewApi") 36 | @Override 37 | public void run() { 38 | animator.start(); 39 | } 40 | 41 | public float getPhase() { 42 | return phase; 43 | } 44 | 45 | public void setPhase(float phase) { 46 | this.phase = phase; 47 | } 48 | 49 | public float getXOrigin() { 50 | return xOrigin; 51 | } 52 | 53 | public float getYOrigin() { 54 | return yOrigin; 55 | } 56 | 57 | public abstract void recycleSelf(); 58 | 59 | protected void resetAnimator(){ 60 | animator.removeAllListeners(); 61 | animator.removeAllUpdateListeners(); 62 | animator.reverse(); 63 | animator.addUpdateListener(this); 64 | animator.addListener(this); 65 | } 66 | 67 | @Override 68 | public void onAnimationStart(Animator animation) { 69 | 70 | } 71 | 72 | @Override 73 | public void onAnimationEnd(Animator animation) { 74 | try{ 75 | recycleSelf(); 76 | }catch (IllegalArgumentException e){ 77 | // don't worry about it. 78 | } 79 | } 80 | 81 | @Override 82 | public void onAnimationCancel(Animator animation) { 83 | try{ 84 | recycleSelf(); 85 | }catch (IllegalArgumentException e){ 86 | // don't worry about it. 87 | } 88 | } 89 | 90 | @Override 91 | public void onAnimationRepeat(Animator animation) { 92 | 93 | } 94 | 95 | @Override 96 | public void onAnimationUpdate(ValueAnimator animation) { 97 | 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/jobs/MoveViewJob.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.jobs; 3 | 4 | import android.view.View; 5 | 6 | import com.github.mikephil.charting.utils.ObjectPool; 7 | import com.github.mikephil.charting.utils.Transformer; 8 | import com.github.mikephil.charting.utils.ViewPortHandler; 9 | 10 | /** 11 | * Created by Philipp Jahoda on 19/02/16. 12 | */ 13 | public class MoveViewJob extends ViewPortJob { 14 | 15 | private static ObjectPool pool; 16 | 17 | static { 18 | pool = ObjectPool.create(2, new MoveViewJob(null,0,0,null,null)); 19 | pool.setReplenishPercentage(0.5f); 20 | } 21 | 22 | public static MoveViewJob getInstance(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v){ 23 | MoveViewJob result = pool.get(); 24 | result.mViewPortHandler = viewPortHandler; 25 | result.xValue = xValue; 26 | result.yValue = yValue; 27 | result.mTrans = trans; 28 | result.view = v; 29 | return result; 30 | } 31 | 32 | public static void recycleInstance(MoveViewJob instance){ 33 | pool.recycle(instance); 34 | } 35 | 36 | public MoveViewJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v) { 37 | super(viewPortHandler, xValue, yValue, trans, v); 38 | } 39 | 40 | @Override 41 | public void run() { 42 | 43 | pts[0] = xValue; 44 | pts[1] = yValue; 45 | 46 | mTrans.pointValuesToPixel(pts); 47 | mViewPortHandler.centerViewPort(pts, view); 48 | 49 | this.recycleInstance(this); 50 | } 51 | 52 | @Override 53 | protected ObjectPool.Poolable instantiate() { 54 | return new MoveViewJob(mViewPortHandler, xValue, yValue, mTrans, view); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/jobs/ViewPortJob.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.jobs; 3 | 4 | import android.view.View; 5 | 6 | import com.github.mikephil.charting.utils.ObjectPool; 7 | import com.github.mikephil.charting.utils.Transformer; 8 | import com.github.mikephil.charting.utils.ViewPortHandler; 9 | 10 | /** 11 | * Runnable that is used for viewport modifications since they cannot be 12 | * executed at any time. This can be used to delay the execution of viewport 13 | * modifications until the onSizeChanged(...) method of the chart-view is called. 14 | * This is especially important if viewport modifying methods are called on the chart 15 | * directly after initialization. 16 | * 17 | * @author Philipp Jahoda 18 | */ 19 | public abstract class ViewPortJob extends ObjectPool.Poolable implements Runnable { 20 | 21 | protected float[] pts = new float[2]; 22 | 23 | protected ViewPortHandler mViewPortHandler; 24 | protected float xValue = 0f; 25 | protected float yValue = 0f; 26 | protected Transformer mTrans; 27 | protected View view; 28 | 29 | public ViewPortJob(ViewPortHandler viewPortHandler, float xValue, float yValue, 30 | Transformer trans, View v) { 31 | 32 | this.mViewPortHandler = viewPortHandler; 33 | this.xValue = xValue; 34 | this.yValue = yValue; 35 | this.mTrans = trans; 36 | this.view = v; 37 | 38 | } 39 | 40 | public float getXValue() { 41 | return xValue; 42 | } 43 | 44 | public float getYValue() { 45 | return yValue; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/jobs/ZoomJob.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.jobs; 3 | 4 | import android.graphics.Matrix; 5 | import android.view.View; 6 | 7 | import com.github.mikephil.charting.charts.BarLineChartBase; 8 | import com.github.mikephil.charting.components.YAxis; 9 | import com.github.mikephil.charting.utils.ObjectPool; 10 | import com.github.mikephil.charting.utils.Transformer; 11 | import com.github.mikephil.charting.utils.ViewPortHandler; 12 | 13 | /** 14 | * Created by Philipp Jahoda on 19/02/16. 15 | */ 16 | public class ZoomJob extends ViewPortJob { 17 | 18 | private static ObjectPool pool; 19 | 20 | static { 21 | pool = ObjectPool.create(1, new ZoomJob(null, 0, 0, 0, 0, null, null, null)); 22 | pool.setReplenishPercentage(0.5f); 23 | } 24 | 25 | public static ZoomJob getInstance(ViewPortHandler viewPortHandler, float scaleX, float scaleY, float xValue, float yValue, 26 | Transformer trans, YAxis.AxisDependency axis, View v) { 27 | ZoomJob result = pool.get(); 28 | result.xValue = xValue; 29 | result.yValue = yValue; 30 | result.scaleX = scaleX; 31 | result.scaleY = scaleY; 32 | result.mViewPortHandler = viewPortHandler; 33 | result.mTrans = trans; 34 | result.axisDependency = axis; 35 | result.view = v; 36 | return result; 37 | } 38 | 39 | public static void recycleInstance(ZoomJob instance) { 40 | pool.recycle(instance); 41 | } 42 | 43 | protected float scaleX; 44 | protected float scaleY; 45 | 46 | protected YAxis.AxisDependency axisDependency; 47 | 48 | public ZoomJob(ViewPortHandler viewPortHandler, float scaleX, float scaleY, float xValue, float yValue, Transformer trans, 49 | YAxis.AxisDependency axis, View v) { 50 | super(viewPortHandler, xValue, yValue, trans, v); 51 | 52 | this.scaleX = scaleX; 53 | this.scaleY = scaleY; 54 | this.axisDependency = axis; 55 | } 56 | 57 | protected Matrix mRunMatrixBuffer = new Matrix(); 58 | 59 | @Override 60 | public void run() { 61 | 62 | Matrix save = mRunMatrixBuffer; 63 | mViewPortHandler.zoom(scaleX, scaleY, save); 64 | mViewPortHandler.refresh(save, view, false); 65 | 66 | float yValsInView = ((BarLineChartBase) view).getAxis(axisDependency).mAxisRange / mViewPortHandler.getScaleY(); 67 | float xValsInView = ((BarLineChartBase) view).getXAxis().mAxisRange / mViewPortHandler.getScaleX(); 68 | 69 | pts[0] = xValue - xValsInView / 2f; 70 | pts[1] = yValue + yValsInView / 2f; 71 | 72 | mTrans.pointValuesToPixel(pts); 73 | 74 | mViewPortHandler.translate(pts, save); 75 | mViewPortHandler.refresh(save, view, false); 76 | 77 | ((BarLineChartBase) view).calculateOffsets(); 78 | view.postInvalidate(); 79 | 80 | recycleInstance(this); 81 | } 82 | 83 | @Override 84 | protected ObjectPool.Poolable instantiate() { 85 | return new ZoomJob(null, 0, 0, 0, 0, null, null, null); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/listener/OnChartGestureListener.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.listener; 2 | 3 | import android.view.MotionEvent; 4 | 5 | /** 6 | * Listener for callbacks when doing gestures on the chart. 7 | * 8 | * @author Philipp Jahoda 9 | */ 10 | public interface OnChartGestureListener { 11 | 12 | /** 13 | * Callbacks when a touch-gesture has started on the chart (ACTION_DOWN) 14 | * 15 | * @param me 16 | * @param lastPerformedGesture 17 | */ 18 | void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture); 19 | 20 | /** 21 | * Callbacks when a touch-gesture has ended on the chart (ACTION_UP, ACTION_CANCEL) 22 | * 23 | * @param me 24 | * @param lastPerformedGesture 25 | */ 26 | void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture); 27 | 28 | /** 29 | * Callbacks when the chart is longpressed. 30 | * 31 | * @param me 32 | */ 33 | void onChartLongPressed(MotionEvent me); 34 | 35 | /** 36 | * Callbacks when the chart is double-tapped. 37 | * 38 | * @param me 39 | */ 40 | void onChartDoubleTapped(MotionEvent me); 41 | 42 | /** 43 | * Callbacks when the chart is single-tapped. 44 | * 45 | * @param me 46 | */ 47 | void onChartSingleTapped(MotionEvent me); 48 | 49 | /** 50 | * Callbacks then a fling gesture is made on the chart. 51 | * 52 | * @param me1 53 | * @param me2 54 | * @param velocityX 55 | * @param velocityY 56 | */ 57 | void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY); 58 | 59 | /** 60 | * Callbacks when the chart is scaled / zoomed via pinch zoom gesture. 61 | * 62 | * @param me 63 | * @param scaleX scalefactor on the x-axis 64 | * @param scaleY scalefactor on the y-axis 65 | */ 66 | void onChartScale(MotionEvent me, float scaleX, float scaleY); 67 | 68 | /** 69 | * Callbacks when the chart is moved / translated via drag gesture. 70 | * 71 | * @param me 72 | * @param dX translation distance on the x-axis 73 | * @param dY translation distance on the y-axis 74 | */ 75 | void onChartTranslate(MotionEvent me, float dX, float dY); 76 | } 77 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/listener/OnChartValueSelectedListener.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.listener; 2 | 3 | import com.github.mikephil.charting.data.Entry; 4 | import com.github.mikephil.charting.highlight.Highlight; 5 | 6 | /** 7 | * Listener for callbacks when selecting values inside the chart by 8 | * touch-gesture. 9 | * 10 | * @author Philipp Jahoda 11 | */ 12 | public interface OnChartValueSelectedListener { 13 | 14 | /** 15 | * Called when a value has been selected inside the chart. 16 | * 17 | * @param e The selected Entry 18 | * @param h The corresponding highlight object that contains information 19 | * about the highlighted position such as dataSetIndex, ... 20 | */ 21 | void onValueSelected(Entry e, Highlight h); 22 | 23 | /** 24 | * Called when nothing has been selected or an "un-select" has been made. 25 | */ 26 | void onNothingSelected(); 27 | } 28 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/listener/OnDrawLineChartTouchListener.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.listener; 2 | 3 | import android.view.GestureDetector.SimpleOnGestureListener; 4 | import android.view.MotionEvent; 5 | import android.view.View; 6 | import android.view.View.OnTouchListener; 7 | 8 | public class OnDrawLineChartTouchListener extends SimpleOnGestureListener implements OnTouchListener { 9 | 10 | @Override 11 | public boolean onTouch(View v, MotionEvent event) { 12 | return false; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/listener/OnDrawListener.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.listener; 2 | 3 | import com.github.mikephil.charting.data.DataSet; 4 | import com.github.mikephil.charting.data.Entry; 5 | 6 | /** 7 | * Listener for callbacks when drawing on the chart. 8 | * 9 | * @author Philipp 10 | * 11 | */ 12 | public interface OnDrawListener { 13 | 14 | /** 15 | * Called whenever an entry is added with the finger. Note this is also called for entries that are generated by the 16 | * library, when the touch gesture is too fast and skips points. 17 | * 18 | * @param entry 19 | * the last drawn entry 20 | */ 21 | void onEntryAdded(Entry entry); 22 | 23 | /** 24 | * Called whenever an entry is moved by the user after beeing highlighted 25 | * 26 | * @param entry 27 | */ 28 | void onEntryMoved(Entry entry); 29 | 30 | /** 31 | * Called when drawing finger is lifted and the draw is finished. 32 | * 33 | * @param dataSet 34 | * the last drawn DataSet 35 | */ 36 | void onDrawFinished(DataSet dataSet); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/model/GradientColor.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.model; 2 | 3 | public class GradientColor { 4 | 5 | private int startColor; 6 | private int endColor; 7 | 8 | public GradientColor(int startColor, int endColor) { 9 | this.startColor = startColor; 10 | this.endColor = endColor; 11 | } 12 | 13 | public int getStartColor() { 14 | return startColor; 15 | } 16 | 17 | public void setStartColor(int startColor) { 18 | this.startColor = startColor; 19 | } 20 | 21 | public int getEndColor() { 22 | return endColor; 23 | } 24 | 25 | public void setEndColor(int endColor) { 26 | this.endColor = endColor; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/newchart/BarChartEntity.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.newchart; 2 | 3 | import android.graphics.Color; 4 | 5 | 6 | import com.github.mikephil.charting.charts.BarChart; 7 | import com.github.mikephil.charting.charts.BarLineChartBase; 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 | import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * 柱状图 18 | * Created by jin 19 | */ 20 | 21 | public class BarChartEntity extends BaseChartEntity { 22 | public BarChartEntity(BarLineChartBase chart, List[] entries, String[] labels, int[] chartColor, int valueColor, float textSize) { 23 | super(chart, entries, labels, chartColor, valueColor, textSize); 24 | } 25 | 26 | @Override 27 | protected void initChart() { 28 | super.initChart(); 29 | mChart.getAxisLeft().setDrawGridLines(true); 30 | mChart.getAxisLeft().enableGridDashedLine(10f, 15f, 0f); 31 | mChart.getAxisLeft().setGridLineWidth(0.5f); 32 | mChart.getAxisLeft().setGridColor(Color.parseColor("#f5f5f5")); 33 | mChart.getAxisLeft().setDrawZeroLine(false); 34 | mChart.getAxisRight().setDrawZeroLine(false); 35 | mChart.getAxisRight().setZeroLineWidth(0f); 36 | mChart.getAxisLeft().setZeroLineWidth(0f); 37 | mChart.getAxisLeft().setDrawAxisLine(false); 38 | mChart.getXAxis().setDrawAxisLine(false); 39 | mChart.getXAxis().setAxisMinimum(0); 40 | 41 | } 42 | 43 | @Override 44 | protected void setChartData() { 45 | BarDataSet barDataSet; 46 | if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) { 47 | barDataSet = (BarDataSet) mChart.getData().getDataSetByIndex(0); 48 | barDataSet.setValues(mEntries[0]); 49 | mChart.getData().notifyDataChanged(); 50 | mChart.notifyDataSetChanged(); 51 | } else { 52 | barDataSet = new BarDataSet(mEntries[0], labels == null ? "" : labels[0]); 53 | barDataSet.setColors(mChartColors); 54 | List colors = new ArrayList<>(); 55 | for (int color : mChartColors) { 56 | colors.add(color); 57 | } 58 | barDataSet.setValueTextColors(colors); 59 | ArrayList dataSets = new ArrayList<>(); 60 | dataSets.add(barDataSet); 61 | BarData data = new BarData(dataSets); 62 | data.setValueTextSize(mTextSize); 63 | data.setBarWidth(0.9f); 64 | mChart.setData(data); 65 | } 66 | } 67 | 68 | 69 | 70 | public void setDrawValueAboveBar(boolean aboveBar) { 71 | ((BarChart)mChart).setDrawValueAboveBar(aboveBar); 72 | } 73 | 74 | /** 75 | *

设置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 { 21 | 22 | public GroupBarChartEntity(BarLineChartBase chart, List[] entries, String[] labels, int[] chartColor, int valueColor, float textSize) { 23 | super(chart, entries, labels, chartColor, valueColor, textSize); 24 | 25 | } 26 | 27 | @Override 28 | protected void setChartData() { 29 | 30 | BarDataSet[] barDataSets = new BarDataSet[mEntries.length]; 31 | if (mChart.getData() != null && mChart.getData().getDataSetCount() == mEntries.length) { 32 | for(int index = 0, len = mEntries.length; index < len; index ++) { 33 | List list = mEntries[index]; 34 | barDataSets[index] = (BarDataSet) mChart.getData().getDataSetByIndex(index); 35 | barDataSets[index].setValues(list); 36 | } 37 | mChart.getData().notifyDataChanged(); 38 | mChart.notifyDataSetChanged(); 39 | } else { 40 | for (int index = 0, len = mEntries.length; index < len; index ++) { 41 | barDataSets[index] = new BarDataSet(mEntries[index], labels[index]); 42 | barDataSets[index].setAxisDependency(YAxis.AxisDependency.LEFT); 43 | barDataSets[index].setColor(mChartColors[index]); 44 | barDataSets[index].setValueTextColor(mValueColor); 45 | barDataSets[index].setValueTextSize(mTextSize); 46 | } 47 | } 48 | 49 | float groupSpace = 0.45f; 50 | float barSpace = 0.0f; // x2 dataset 51 | float barWidth = 0.45f; // x2 dataset 52 | 53 | BarData data = new BarData(barDataSets); 54 | data.setBarWidth(barWidth); 55 | // make this BarData object grouped 56 | data.groupBars(0, groupSpace, barSpace); 57 | mChart.setData(data); 58 | } 59 | /** 60 | *

设置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 { 20 | public StackBarChartEntry(BarLineChartBase chart, List[] entries, String[] labels, int[] chartColor, int valueColor, float textSize) { 21 | super(chart, entries, labels, chartColor, valueColor, textSize); 22 | } 23 | @Override 24 | protected void setChartData() { 25 | BarDataSet barDataSet; 26 | if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) { 27 | barDataSet = (BarDataSet) mChart.getData().getDataSetByIndex(0); 28 | barDataSet.setValues(mEntries[0]); 29 | mChart.getData().notifyDataChanged(); 30 | mChart.notifyDataSetChanged(); 31 | } else { 32 | barDataSet = new BarDataSet(mEntries[0], ""); 33 | barDataSet.setStackLabels(labels); 34 | barDataSet.setColors(mChartColors); 35 | barDataSet.setValueTextColor(mValueColor); 36 | barDataSet.setValueTextSize(mTextSize); 37 | barDataSet.setAxisDependency(YAxis.AxisDependency.LEFT); 38 | 39 | ArrayList dataSets = new ArrayList<>(); 40 | dataSets.add(barDataSet); 41 | 42 | BarData data = new BarData(dataSets); 43 | data.setValueTextSize(mTextSize); 44 | 45 | data.setBarWidth(0.9f); 46 | 47 | ((BarChart) mChart).setFitBars(true); 48 | ((BarChart) mChart).setDrawValueAboveBar(false); 49 | ((BarChart) mChart).setHighlightFullBarEnabled(false); 50 | mChart.setData(data); 51 | } 52 | } 53 | 54 | 55 | /** 56 | *

设置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 Comparator { 12 | @Override 13 | public int compare(Entry entry1, Entry entry2) { 14 | float diff = entry1.getX() - entry2.getX(); 15 | 16 | if (diff == 0f) return 0; 17 | else { 18 | if (diff > 0f) return 1; 19 | else return -1; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/utils/FSize.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.utils; 3 | 4 | import java.util.List; 5 | 6 | /** 7 | * Class for describing width and height dimensions in some arbitrary 8 | * unit. Replacement for the android.Util.SizeF which is available only on API >= 21. 9 | */ 10 | public final class FSize extends ObjectPool.Poolable{ 11 | 12 | // TODO : Encapsulate width & height 13 | 14 | public float width; 15 | public float height; 16 | 17 | private static ObjectPool pool; 18 | 19 | static { 20 | pool = ObjectPool.create(256, new FSize(0,0)); 21 | pool.setReplenishPercentage(0.5f); 22 | } 23 | 24 | 25 | protected ObjectPool.Poolable instantiate(){ 26 | return new FSize(0,0); 27 | } 28 | 29 | public static FSize getInstance(final float width, final float height){ 30 | FSize result = pool.get(); 31 | result.width = width; 32 | result.height = height; 33 | return result; 34 | } 35 | 36 | public static void recycleInstance(FSize instance){ 37 | pool.recycle(instance); 38 | } 39 | 40 | public static void recycleInstances(List instances){ 41 | pool.recycle(instances); 42 | } 43 | 44 | public FSize() { 45 | } 46 | 47 | public FSize(final float width, final float height) { 48 | this.width = width; 49 | this.height = height; 50 | } 51 | 52 | @Override 53 | public boolean equals(final Object obj) { 54 | if (obj == null) { 55 | return false; 56 | } 57 | if (this == obj) { 58 | return true; 59 | } 60 | if (obj instanceof FSize) { 61 | final FSize other = (FSize) obj; 62 | return width == other.width && height == other.height; 63 | } 64 | return false; 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return width + "x" + height; 70 | } 71 | 72 | /** 73 | * {@inheritDoc} 74 | */ 75 | @Override 76 | public int hashCode() { 77 | return Float.floatToIntBits(width) ^ Float.floatToIntBits(height); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/utils/HorizontalViewPortHandler.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.utils; 3 | 4 | /** 5 | * ViewPortHandler for HorizontalBarChart. 6 | */ 7 | public class HorizontalViewPortHandler extends ViewPortHandler { 8 | 9 | 10 | // @Override 11 | // public void setMinimumScaleX(float xScale) { 12 | // setMinimumScaleY(xScale); 13 | // } 14 | // 15 | // @Override 16 | // public void setMinimumScaleY(float yScale) { 17 | // setMinimumScaleX(yScale); 18 | // } 19 | // 20 | // @Override 21 | // public void setMinMaxScaleX(float minScaleX, float maxScaleX) { 22 | // setMinMaxScaleY(minScaleX, maxScaleX); 23 | // } 24 | // 25 | // @Override 26 | // public void setMinMaxScaleY(float minScaleY, float maxScaleY) { 27 | // setMinMaxScaleX(minScaleY, maxScaleY); 28 | // } 29 | } 30 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/utils/MPPointD.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.mikephil.charting.utils; 3 | 4 | import java.util.List; 5 | 6 | /** 7 | * Point encapsulating two double values. 8 | * 9 | * @author Philipp Jahoda 10 | */ 11 | public class MPPointD extends ObjectPool.Poolable { 12 | 13 | private static ObjectPool pool; 14 | 15 | static { 16 | pool = ObjectPool.create(64, new MPPointD(0,0)); 17 | pool.setReplenishPercentage(0.5f); 18 | } 19 | 20 | public static MPPointD getInstance(double x, double y){ 21 | MPPointD result = pool.get(); 22 | result.x = x; 23 | result.y = y; 24 | return result; 25 | } 26 | 27 | public static void recycleInstance(MPPointD instance){ 28 | pool.recycle(instance); 29 | } 30 | 31 | public static void recycleInstances(List instances){ 32 | pool.recycle(instances); 33 | } 34 | 35 | public double x; 36 | public double y; 37 | 38 | protected ObjectPool.Poolable instantiate(){ 39 | return new MPPointD(0,0); 40 | } 41 | 42 | private MPPointD(double x, double y) { 43 | this.x = x; 44 | this.y = y; 45 | } 46 | 47 | /** 48 | * returns a string representation of the object 49 | */ 50 | public String toString() { 51 | return "MPPointD, x: " + x + ", y: " + y; 52 | } 53 | } -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/utils/MPPointF.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.utils; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Tony Patino on 6/24/16. 10 | */ 11 | public class MPPointF extends ObjectPool.Poolable { 12 | 13 | private static ObjectPool pool; 14 | 15 | public float x; 16 | public float y; 17 | 18 | static { 19 | pool = ObjectPool.create(32, new MPPointF(0,0)); 20 | pool.setReplenishPercentage(0.5f); 21 | } 22 | 23 | public MPPointF() { 24 | } 25 | 26 | public MPPointF(float x, float y) { 27 | this.x = x; 28 | this.y = y; 29 | } 30 | 31 | public static MPPointF getInstance(float x, float y) { 32 | MPPointF result = pool.get(); 33 | result.x = x; 34 | result.y = y; 35 | return result; 36 | } 37 | 38 | public static MPPointF getInstance() { 39 | return pool.get(); 40 | } 41 | 42 | public static MPPointF getInstance(MPPointF copy) { 43 | MPPointF result = pool.get(); 44 | result.x = copy.x; 45 | result.y = copy.y; 46 | return result; 47 | } 48 | 49 | public static void recycleInstance(MPPointF instance){ 50 | pool.recycle(instance); 51 | } 52 | 53 | public static void recycleInstances(List instances){ 54 | pool.recycle(instances); 55 | } 56 | 57 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 58 | /** 59 | * Return a new point from the data in the specified parcel. 60 | */ 61 | public MPPointF createFromParcel(Parcel in) { 62 | MPPointF r = new MPPointF(0,0); 63 | r.my_readFromParcel(in); 64 | return r; 65 | } 66 | 67 | /** 68 | * Return an array of rectangles of the specified size. 69 | */ 70 | public MPPointF[] newArray(int size) { 71 | return new MPPointF[size]; 72 | } 73 | }; 74 | 75 | /** 76 | * Set the point's coordinates from the data stored in the specified 77 | * parcel. To write a point to a parcel, call writeToParcel(). 78 | * Provided to support older Android devices. 79 | * 80 | * @param in The parcel to read the point's coordinates from 81 | */ 82 | public void my_readFromParcel(Parcel in) { 83 | x = in.readFloat(); 84 | y = in.readFloat(); 85 | } 86 | 87 | public float getX(){ 88 | return this.x; 89 | } 90 | 91 | public float getY(){ 92 | return this.y; 93 | } 94 | 95 | @Override 96 | protected ObjectPool.Poolable instantiate() { 97 | return new MPPointF(0,0); 98 | } 99 | } -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/utils/ParseUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.utils; 2 | 3 | import org.json.JSONException; 4 | import org.json.JSONObject; 5 | 6 | /** 7 | * @author 张海洋 8 | * @Date on 2018/09/26. 9 | * @org 上海..科技有限公司 10 | * @describe 11 | */ 12 | 13 | 14 | public class ParseUtils { 15 | public void getData(String data) { 16 | try { 17 | JSONObject jsonObject=new JSONObject(data); 18 | } catch (JSONException e) { 19 | e.printStackTrace(); 20 | } 21 | 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/utils/SPoolUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.utils; 2 | 3 | import android.graphics.Color; 4 | 5 | /** 6 | * @author 张海洋 7 | * @Date on 2018/09/14. 8 | * @org 上海相舆科技有限公司 9 | * @describe 10 | */ 11 | 12 | 13 | public class SPoolUtils { 14 | 15 | 16 | /** 17 | * X Y 轴 默认字体的大小 18 | */ 19 | public static float mNomalTextSize = 11f; 20 | /** 21 | * X 轴字体的颜色 默认 22 | */ 23 | public static int mXTvColor = Color.parseColor("#5fd1cc"); 24 | /** 25 | * Y轴字体的颜色 默认 26 | */ 27 | public static int mYTvColor = Color.parseColor("#5fd1cc"); 28 | 29 | 30 | /** 31 | * 图例 字体的大小 和 字体颜色 32 | */ 33 | 34 | public static float mLegendTvSize=18f; 35 | public static int mLegendTvColor=Color.parseColor("#5fd1cc"); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /MPChartLib/src/main/java/com/github/mikephil/charting/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.mikephil.charting.utils; 2 | 3 | /** 4 | *
 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 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 values1 = new ArrayList<>(); 26 | List values2 = new ArrayList<>(); 27 | 28 | for(int i = 0; i < 5; i++) { 29 | values1.add(new BarEntry(i, 50)); 30 | values2.add(new BarEntry(i, 60)); 31 | } 32 | 33 | BarDataSet barDataSet1 = new BarDataSet(values1, "Set1"); 34 | BarDataSet barDataSet2 = new BarDataSet(values2, "Set2"); 35 | 36 | BarData data = new BarData(barDataSet1, barDataSet2); 37 | data.setBarWidth(10f); 38 | 39 | float groupWidth = data.getGroupWidth(groupSpace, barSpace); 40 | assertEquals(27f, groupWidth, 0.01f); 41 | 42 | assertEquals(0f, values1.get(0).getX(), 0.01f); 43 | assertEquals(1f, values1.get(1).getX(), 0.01f); 44 | 45 | data.groupBars(1000, groupSpace, barSpace); 46 | 47 | // 1000 + 2.5 + 0.5 + 5 48 | assertEquals(1008f, values1.get(0).getX(), 0.01f); 49 | assertEquals(1019f, values2.get(0).getX(), 0.01f); 50 | assertEquals(1035f, values1.get(1).getX(), 0.01f); 51 | assertEquals(1046f, values2.get(1).getX(), 0.01f); 52 | 53 | data.groupBars(-1000, groupSpace, barSpace); 54 | 55 | assertEquals(-992f, values1.get(0).getX(), 0.01f); 56 | assertEquals(-981f, values2.get(0).getX(), 0.01f); 57 | assertEquals(-965f, values1.get(1).getX(), 0.01f); 58 | assertEquals(-954f, values2.get(1).getX(), 0.01f); 59 | 60 | data.setBarWidth(20f); 61 | groupWidth = data.getGroupWidth(groupSpace, barSpace); 62 | assertEquals(47f, groupWidth, 0.01f); 63 | 64 | data.setBarWidth(10f); 65 | data.groupBars(-20, groupSpace, barSpace); 66 | 67 | assertEquals(-12f, values1.get(0).getX(), 0.01f); 68 | assertEquals(-1f, values2.get(0).getX(), 0.01f); 69 | assertEquals(15f, values1.get(1).getX(), 0.01f); 70 | assertEquals(26f, values2.get(1).getX(), 0.01f); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | defaultConfig { 6 | applicationId "com.smartchart.cn.mpandroidchart" 7 | minSdkVersion 19 8 | targetSdkVersion 27 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | javaCompileOptions { 13 | annotationProcessorOptions { 14 | includeCompileClasspath = true 15 | } 16 | } 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(dir: 'libs', include: ['*.jar']) 28 | implementation 'com.android.support:appcompat-v7:27.1.1' 29 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 30 | testImplementation 'junit:junit:4.12' 31 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 33 | 34 | implementation project(':MPChartLib') 35 | implementation 'com.jakewharton:butterknife:7.0.1' 36 | implementation 'com.google.code.gson:gson:2.2.1' 37 | 38 | } 39 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/smartchart/cn/mpandroidchart/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.smartchart.cn.mpandroidchart; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.smartchart.cn.mpandroidchart", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/assets/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "errCode": 0, 3 | "errDesc": "ok", 4 | "rsp": [{ 5 | "month": "2018-09", 6 | "electricity": "100" 7 | }, { 8 | "month": "2018-08", 9 | "electricity": "83" 10 | }, { 11 | "month": "2018-07", 12 | "electricity": "49" 13 | }, { 14 | "month": "2018-06", 15 | "electricity": "22" 16 | }, { 17 | "month": "2018-05", 18 | "electricity": "83" 19 | }, { 20 | "month": "2018-4", 21 | "electricity": "0.0" 22 | }, { 23 | "month": "2017-03", 24 | "electricity": "0" 25 | }, { 26 | "month": "2018-2", 27 | "electricity": "2" 28 | }, { 29 | "month": "2018-1", 30 | "electricity": "8" 31 | }, { 32 | "month": "2017-12", 33 | "electricity": "6" 34 | }, { 35 | "month": "2017-11", 36 | "electricity": "5" 37 | }, { 38 | "month": "2017-10", 39 | "electricity": "4" 40 | }] 41 | } -------------------------------------------------------------------------------- /app/src/main/assets/test1.json: -------------------------------------------------------------------------------- 1 | { 2 | "errCode": 0, 3 | "errDesc": "ok", 4 | "rsp": [{ 5 | "month": "2018-09", 6 | "electricity": "70" 7 | }, { 8 | "month": "2018-08", 9 | "electricity": "56" 10 | }, { 11 | "month": "2018-07", 12 | "electricity": "69" 13 | }, { 14 | "month": "2018-06", 15 | "electricity": "32" 16 | }, { 17 | "month": "2018-05", 18 | "electricity": "83" 19 | }, { 20 | "month": "2018-4", 21 | "electricity": "0.0" 22 | }, { 23 | "month": "2017-03", 24 | "electricity": "0" 25 | }, { 26 | "month": "2018-2", 27 | "electricity": "2" 28 | }, { 29 | "month": "2018-1", 30 | "electricity": "8" 31 | }, { 32 | "month": "2017-12", 33 | "electricity": "6" 34 | }, { 35 | "month": "2017-11", 36 | "electricity": "89" 37 | }, { 38 | "month": "2017-10", 39 | "electricity": "45" 40 | }] 41 | } -------------------------------------------------------------------------------- /app/src/main/java/com/smartchart/cn/mpandroidchart/bean/YomthEnity.java: -------------------------------------------------------------------------------- 1 | package com.smartchart.cn.mpandroidchart.bean; 2 | 3 | /** 4 | * @author 张海洋 5 | * @Date on 2018/09/13. 6 | * @org 上海相舆科技有限公司 7 | * @describe 8 | */ 9 | 10 | 11 | public class YomthEnity { 12 | private String month; 13 | private String electricity; 14 | 15 | public YomthEnity(String month, String electricity) { 16 | this.month = month; 17 | this.electricity = electricity; 18 | } 19 | 20 | public String getMonth() { 21 | return month; 22 | } 23 | 24 | public void setMonth(String month) { 25 | this.month = month; 26 | } 27 | 28 | public String getElectricity() { 29 | return electricity; 30 | } 31 | 32 | public void setElectricity(String electricity) { 33 | this.electricity = electricity; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/smartchart/cn/mpandroidchart/utils/BaseUtils.java: -------------------------------------------------------------------------------- 1 | package com.smartchart.cn.mpandroidchart.utils; 2 | 3 | import android.util.Log; 4 | 5 | import java.io.IOException; 6 | import java.net.DatagramPacket; 7 | import java.net.DatagramSocket; 8 | import java.net.InetSocketAddress; 9 | import java.net.SocketException; 10 | 11 | /** 12 | * @author 张海洋 13 | * @Date on 2018/09/27. 14 | * @org 上海..科技有限公司 15 | * @describe 16 | */ 17 | 18 | 19 | public class BaseUtils { 20 | 21 | 22 | /** 23 | * 获得UDP 发送数据 24 | */ 25 | public static String getUDPSendData(String wifiName, String wifiPwd) { 26 | return "sjap=" + '"' + wifiName + '"' + ',' + '"' + wifiPwd + '"'; 27 | } 28 | public static void sendUdp(final String message, final String ipAdrress, final int mPort, final DatagramSocket dataSocket, final X3ck call) { 29 | new Thread(new Runnable() { 30 | @Override 31 | public void run() { 32 | Log.i("GGG", "发送的数据---message-> " + message); 33 | try { 34 | byte[] buffer = message.getBytes("UTF-8"); 35 | //将要发送的数据、要发送到什么地址设置好并打成一个 DatagramPacket 包 36 | DatagramPacket sendPack = new DatagramPacket(buffer, buffer.length, new InetSocketAddress(ipAdrress, mPort)); 37 | dataSocket.send(sendPack); 38 | byte[] by = new byte[4096]; 39 | DatagramPacket dataPacket2 = new DatagramPacket(by, by.length); 40 | dataSocket.receive(dataPacket2); 41 | String mRevicedata = new String(by, 0, dataPacket2.getLength()); 42 | call.onSuccess(mRevicedata); 43 | } catch (IOException e) { 44 | e.printStackTrace(); 45 | } 46 | } 47 | }).start(); 48 | 49 | } 50 | 51 | 52 | public interface X3ck { 53 | 54 | 55 | void onSuccess(String result); 56 | } 57 | 58 | public static DatagramSocket initUdpSocket(int port) { 59 | DatagramSocket dataSocket = null; 60 | try { 61 | dataSocket = new DatagramSocket(8266); 62 | Log.i("NNN", "初始化socket 端口 8266"); 63 | } catch (SocketException e) { 64 | e.printStackTrace(); 65 | } 66 | return dataSocket; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/smartchart/cn/mpandroidchart/view/MyMarkerView.java: -------------------------------------------------------------------------------- 1 | package com.smartchart.cn.mpandroidchart.view; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | import android.widget.TextView; 6 | 7 | import com.github.mikephil.charting.components.NomalMarkerView; 8 | import com.github.mikephil.charting.data.CandleEntry; 9 | import com.github.mikephil.charting.data.Entry; 10 | import com.github.mikephil.charting.highlight.Highlight; 11 | import com.github.mikephil.charting.utils.MPPointF; 12 | import com.smartchart.cn.mpandroidchart.R; 13 | 14 | import java.text.DecimalFormat; 15 | 16 | /** 17 | * @author 张海洋 18 | * @Date on 2018/09/27. 19 | * @org 上海..科技有限公司 20 | * @describe 21 | */ 22 | 23 | 24 | public class MyMarkerView extends NomalMarkerView { 25 | 26 | private TextView tvContent; 27 | 28 | public MyMarkerView(Context context, int layoutResource) { 29 | 30 | super(context, layoutResource); 31 | tvContent = (TextView) findViewById(R.id.tvContent); 32 | } 33 | 34 | // callbacks everytime the MarkerView is redrawn, can be used to update the 35 | // content (user-interface) 36 | @Override 37 | public void refreshContent(Entry e, Highlight highlight) { 38 | DecimalFormat df = new DecimalFormat("##0.000"); 39 | if (e instanceof CandleEntry) { 40 | Log.i("NNN", e.getY() + "-------11--------"); 41 | Log.i("NNN", e.getX() + "-------22--------"); 42 | CandleEntry ce = (CandleEntry) e; 43 | Log.i("NNN", "CandleEntry" + ce.getHigh() + "---------------"); 44 | // tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true)); 45 | tvContent.setText(df.format(ce.getHigh())); 46 | } else { 47 | Log.i("NNN", e.getX() + "------33---------"); 48 | Log.i("NNN", e.getY() + "--------44-------"); 49 | tvContent.setText(df.format(e.getY())); 50 | // tvContent.setText("" + Utils.formatNumber(e.getY(), 0, true)); 51 | } 52 | 53 | super.refreshContent(e, highlight); 54 | } 55 | 56 | @Override 57 | public MPPointF getOffset() { 58 | return new MPPointF(-(getWidth() / 2), -getHeight()); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/smartchart/cn/mpandroidchart/view/NewMarkerView.java: -------------------------------------------------------------------------------- 1 | package com.smartchart.cn.mpandroidchart.view; 2 | 3 | /** 4 | * 5 | * Created by 坚果-王健(wangjian3@kuyumall.com) on 2016/12/14. 6 | */ 7 | 8 | 9 | import android.content.Context; 10 | import android.widget.TextView; 11 | 12 | import com.github.mikephil.charting.components.MarkerView; 13 | import com.github.mikephil.charting.data.CandleEntry; 14 | import com.github.mikephil.charting.data.Entry; 15 | import com.github.mikephil.charting.highlight.Highlight; 16 | import com.github.mikephil.charting.utils.MPPointF; 17 | import com.github.mikephil.charting.utils.Utils; 18 | import com.smartchart.cn.mpandroidchart.R; 19 | 20 | 21 | /** 22 | * Custom implementation of the MarkerView. 23 | * 24 | * @author Philipp Jahoda 25 | */ 26 | public class NewMarkerView extends MarkerView { 27 | 28 | private TextView tvContent; 29 | private CallBack mCallBack; 30 | private Boolean needFormat=true; 31 | public NewMarkerView(Context context, int layoutResource) { 32 | super(context, layoutResource); 33 | tvContent = (TextView) findViewById(R.id.tvContent); 34 | } 35 | 36 | /*部分数据不需要格式化处理*/ 37 | public NewMarkerView(Context context, int layoutResource,boolean needFormat) { 38 | super(context, layoutResource); 39 | this.needFormat = needFormat; 40 | tvContent = (TextView) findViewById(R.id.tvContent); 41 | } 42 | 43 | // callbacks everytime the MarkerView is redrawn, can be used to update the 44 | // content (user-interface) 45 | @Override 46 | public void refreshContent(Entry e, Highlight highlight) { 47 | 48 | String values; 49 | if (e instanceof CandleEntry) { 50 | CandleEntry ce = (CandleEntry) e; 51 | values = "" + Utils.formatNumber(ce.getHigh(), 0, true); 52 | } else { 53 | if(!needFormat){ 54 | values=""+e.getY(); 55 | }else{ 56 | values = "" + Utils.formatNumber(e.getY(), 0, true); 57 | } 58 | } 59 | 60 | if (mCallBack != null) { 61 | mCallBack.onCallBack(e.getX(), values); 62 | } 63 | super.refreshContent(e, highlight); 64 | } 65 | 66 | @Override 67 | public MPPointF getOffset() { 68 | tvContent.setBackgroundResource(R.drawable.chart_popu); 69 | return new MPPointF(0, -getHeight()); 70 | } 71 | 72 | @Override 73 | public MPPointF getOffsetRight() { 74 | tvContent.setBackgroundResource(R.drawable.chart_popu_right); 75 | return new MPPointF(-getWidth(), -getHeight()); 76 | } 77 | 78 | public void setCallBack (CallBack callBack) { 79 | this.mCallBack = callBack; 80 | } 81 | public interface CallBack { 82 | void onCallBack(float x, String value); 83 | } 84 | 85 | public TextView getTvContent() { 86 | return tvContent; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangi789/MPAndroidChart/3de0d767490665353603bb8745e25e8a1bb04580/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/view_dash_line.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/chart_callserice_call_casecount.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/chart_popu.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangi789/MPAndroidChart/3de0d767490665353603bb8745e25e8a1bb04580/app/src/main/res/drawable-xhdpi/chart_popu.9.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/chart_popu_right.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangi789/MPAndroidChart/3de0d767490665353603bb8745e25e8a1bb04580/app/src/main/res/drawable-xhdpi/chart_popu_right.9.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/chart_thisyear_blue.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangi789/MPAndroidChart/3de0d767490665353603bb8745e25e8a1bb04580/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ac_bg_oval.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_null.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangi789/MPAndroidChart/3de0d767490665353603bb8745e25e8a1bb04580/app/src/main/res/drawable/bg_null.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/chart_view_selector_line.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/jfdfdj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangi789/MPAndroidChart/3de0d767490665353603bb8745e25e8a1bb04580/app/src/main/res/drawable/jfdfdj.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/line_bg_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangi789/MPAndroidChart/3de0d767490665353603bb8745e25e8a1bb04580/app/src/main/res/drawable/line_bg_pressed.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/marker3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangi789/MPAndroidChart/3de0d767490665353603bb8745e25e8a1bb04580/app/src/main/res/drawable/marker3.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_a.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_line.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 12 | 13 | 14 | 15 | 16 |