XFree-MPAndroidChart is based on MPAndroidChart 3.1.0, The purpose of this library is to solve the problem that the LineChart of MPAndroidChart can't add unsorted entries. When adding unsorted entries to MPAndroidChart, it will crash and the following error is displayed
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.acorn.myframeapp, PID: 13758
java.lang.NegativeArraySizeException: -2
at com.github.mikephil.charting.utils.Transformer.generateTransformedValuesLine(Transformer.java:178)
at com.github.mikephil.charting.renderer.LineChartRenderer.drawValues(LineChartRenderer.java:567)
at com.github.mikephil.charting.charts.BarLineChartBase.onDraw(BarLineChartBase.java:297)
Note that the performance of XFree-MPAndroidChart is slightly inferior to that of MPAndroidChart
Sorted data
Unsorted data
use XFreeLineDataSet.mPointVisibleThreshold to determined whether the circles are displayed
//when mPointVisibleThreshold<=0 the circles on the lines will always displayed.
//when mPointVisibleThreshold>0,
//Whether the circles are displayed or not is determined by the number of entries which simultaneously shown on the screen
//When the number of entries shown on the screen is less than the mPointVisibleThreshold, those circles will be displayed.
mXFreeLineDataSet.mPointVisibleThreshold = 100
Select Area
Add it in your root build.gradle at the end of the repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.oneAcorn:XFree-MPAndroidChart:v1.0.10'
}
Most of the usages for XFree-MPAndroidChart are the same as for MPAndroidChart.
The differences are shown below.
- Create the instance object of chart view:
AAChartView
<com.acorn.xfreechart.library.XFreeLineChart
android:id="@+id/lineChart"
android:layout_width="match_parent"
android:layout_height="match_parent" />
- Create a LineDataSet
//In XFree-MPAndroidChart we use the XFreeLineDataSet instead of the LineDataSet
val set = XFreeLineDataSet(binding.lineChart, null, "Test Data")
3 Create the Highlighter
//In XFree-MPAndroidChart we use the XFreeHighlighter instead of the ChartHighlighter
xFreeChart.highlighter = XFreeHighlighter(this)