'The mp android chart does not work correctly when first installing the application on the device
When first installing the application on the device, the mp android chart does not show correctly, what is the reason ?
Here is my code:
viewModel.weekRead( ( calender.get(Calendar.DAY_OF_MONTH) - 7 ) , ( calender.get(Calendar.MONTH) + 1 ) ).observe(viewLifecycleOwner) {
val weekList = ArrayList<BarEntry>()
for (i in it) {
weekList.add ( BarEntry ( i.day.toFloat() , i.step_value.toFloat() ) )
}
val barDataSet = BarDataSet ( weekList , " " )
barDataSet.setColors(ColorTemplate.COLORFUL_COLORS, 250)
barDataSet.valueTextSize = 12F
val barData = BarData(barDataSet)
binding.weekChart.setFitBars(true)
binding.weekChart.data = barData
binding.weekChart.animateY(2000)
binding.weekChart.setTouchEnabled(false)
binding.weekChart.description = null
binding.weekChart.xAxis.apply {
setDrawGridLines(false)
setDrawLabels(false)
}
binding.weekChart.axisLeft.axisMinimum = 0f
binding.weekChart.axisRight.axisMinimum = 0f
binding.weekChart.refreshDrawableState()
binding.weekChart.invalidate()
}
For more details, I'm throwing the layout part in addition.
Here is my XML codes :
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Aylık Adım Sayısı"
app:layout_constraintEnd_toEndOf="@+id/mount_chart"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/mount_chart"
app:layout_constraintTop_toTopOf="parent" />
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/mount_chart"
android:layout_width="336dp"
android:layout_height="254dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
</androidx.constraintlayout.widget.ConstraintLayout>
Finally, the image of the error :
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|