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