Adjust distance traveled graph.

This commit is contained in:
Danila Fedorin 2020-05-13 16:55:23 -07:00
parent 9ab9377201
commit 1cb22bf4a0

View File

@ -12,6 +12,7 @@ import com.android.volley.toolbox.Volley
import com.danilafe.fencelessgrazing.model.CollarDistance
import com.danilafe.fencelessgrazing.requests.DistanceTraveledRequest
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.components.XAxis
import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet
import com.github.mikephil.charting.data.BarEntry
@ -42,6 +43,7 @@ class DistanceTraveledGraph() : Fragment() {
): View? {
val view = inflater.inflate(R.layout.distance_traveled_layoyt, container, false)
distanceTraveledChart = view.findViewById(R.id.distanceTraveledChart)
setupChart()
return view
}
@ -49,7 +51,6 @@ class DistanceTraveledGraph() : Fragment() {
super.onCreate(savedInstanceState)
queue = Volley.newRequestQueue(requireActivity().applicationContext)
setupChart()
triggerRefresh()
}
@ -83,19 +84,20 @@ class DistanceTraveledGraph() : Fragment() {
val dataSet = BarDataSet(entries, "Distance Traveled")
dataSet.colors = ColorTemplate.PASTEL_COLORS.toList()
val data = BarData(dataSet)
data.barWidth = 0.9f
data.barWidth = 0.8f
distanceTraveledChart.data = data
distanceTraveledChart.xAxis.valueFormatter = IndexAxisValueFormatter(labels)
distanceTraveledChart.invalidate()
}
/**
* Configure the [distanceTraveledChart] with the proper visual settings.
*/
private fun setupChart() {
distanceTraveledChart.legend.textSize = 20.0f
distanceTraveledChart.setFitBars(true)
distanceTraveledChart.xAxis.granularity = 1.0f
distanceTraveledChart.xAxis.isGranularityEnabled = true
distanceTraveledChart.xAxis.position = XAxis.XAxisPosition.BOTTOM
distanceTraveledChart.invalidate()
}
}