use now 2 graphs for the temp and hum instead of one with 2 lines
This commit is contained in:
parent
2ad850424d
commit
a3c02e28cb
@ -42,7 +42,8 @@ class MainActivity : AppCompatActivity() {
|
||||
private data class SensorReading(val secSinceStart: Long, val temperature: Float, val humidity: Float)
|
||||
private val sensorHistory = mutableListOf<SensorReading>()
|
||||
|
||||
private lateinit var lineChart: LineChart
|
||||
private lateinit var tempChart: LineChart
|
||||
private lateinit var humChart: LineChart
|
||||
|
||||
private lateinit var tempCircle: TextView
|
||||
private lateinit var humCircle: TextView
|
||||
@ -54,8 +55,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
val connectBtn = findViewById<Button>(R.id.connect_btn)
|
||||
|
||||
lineChart = findViewById(R.id.Chart)
|
||||
setupChart()
|
||||
tempChart = findViewById(R.id.temp_chart)
|
||||
humChart = findViewById(R.id.hum_chart)
|
||||
setupChart(tempChart)
|
||||
setupChart(humChart)
|
||||
|
||||
tempCircle = findViewById(R.id.temp_circle)
|
||||
humCircle = findViewById(R.id.hum_circle)
|
||||
@ -152,8 +155,8 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupChart() {
|
||||
lineChart.apply {
|
||||
private fun setupChart(chart: LineChart) {
|
||||
chart.apply {
|
||||
description.isEnabled = false
|
||||
setTouchEnabled(true)
|
||||
isDragEnabled = true
|
||||
@ -174,11 +177,7 @@ class MainActivity : AppCompatActivity() {
|
||||
setDrawGridLines(false)
|
||||
}
|
||||
axisRight.isEnabled = false
|
||||
|
||||
axisLeft.apply {
|
||||
setDrawGridLines(true)
|
||||
axisMaximum = 0f
|
||||
}
|
||||
axisLeft.setDrawGridLines(true)
|
||||
legend.isEnabled = true
|
||||
}
|
||||
}
|
||||
@ -210,9 +209,10 @@ class MainActivity : AppCompatActivity() {
|
||||
fillDrawable = ContextCompat.getDrawable(this@MainActivity, R.drawable.gradiant_hum)
|
||||
}
|
||||
|
||||
val data = LineData(tempSet, humSet)
|
||||
lineChart.data = data
|
||||
lineChart.invalidate()
|
||||
tempChart.data = LineData(tempSet)
|
||||
humChart.data = LineData(humSet)
|
||||
tempChart.invalidate()
|
||||
humChart.invalidate()
|
||||
}
|
||||
|
||||
}
|
||||
@ -59,16 +59,30 @@
|
||||
app:layout_constraintBottom_toBottomOf="@+id/temp_circle" />
|
||||
|
||||
<com.github.mikephil.charting.charts.LineChart
|
||||
android:id="@+id/Chart"
|
||||
android:id="@+id/temp_chart"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="@android:color/white"
|
||||
app:layout_constraintTop_toBottomOf="@id/temp_circle"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/hum_chart" />
|
||||
|
||||
<com.github.mikephil.charting.charts.LineChart
|
||||
android:id="@+id/hum_chart"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:background="@android:color/white"
|
||||
app:layout_constraintTop_toBottomOf="@id/temp_chart"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Loading…
Reference in New Issue
Block a user