feat: Add Grouped Charts support (#17)

This commit is contained in:
2023-01-11 16:24:49 +01:00
committed by GitHub
parent e3d82026db
commit b1b209035c
7 changed files with 90 additions and 21 deletions

View File

@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.dzeio.charts.ChartType
import com.dzeio.charts.ChartView
import com.dzeio.charts.Entry
import com.dzeio.charts.series.BarSerie
@ -30,21 +31,27 @@ class MainFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.chart1.apply {
binding.chartGrouped.apply {
// setup the Serie
val serie = BarSerie(this)
val serie1 = BarSerie(this)
val serie2 = BarSerie(this)
// transform the chart into a grouped chart
type = ChartType.GROUPED
// utils function to use Material3 auto colors
materielTheme(this, requireView())
serie2.barPaint.color = Color.RED
// give the serie it's entries
serie.entries = generateRandomDataset(10)
serie1.entries = generateRandomDataset(10)
serie2.entries = generateRandomDataset(10)
// refresh the Chart
refresh()
}
binding.chart2.apply {
binding.chartLine.apply {
// setup the Serie
val serie = LineSerie(this)
@ -58,7 +65,21 @@ class MainFragment : Fragment() {
refresh()
}
binding.chart3.apply {
binding.chartBar.apply {
// setup the Serie
val serie = BarSerie(this)
// utils function to use Material3 auto colors
materielTheme(this, requireView())
// give the serie its entries
serie.entries = generateRandomDataset(10)
// refresh the Chart
refresh()
}
binding.chartCustomization.apply {
// setup the Series
val serie1 = BarSerie(this)
val serie2 = LineSerie(this)

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size
android:height="16dp"
android:width="0dp" />
</shape>

View File

@ -6,35 +6,39 @@
android:layout_height="match_parent"
tools:context=".ui.MainFragment">
<!-- <ScrollView-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent">-->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:showDividers="middle"
android:divider="@drawable/shape_divider"
android:padding="16dp">
<com.dzeio.charts.ChartView
android:id="@+id/chart1"
android:id="@+id/chart_grouped"
android:layout_width="match_parent"
android:layout_height="200dp" />
<com.dzeio.charts.ChartView
android:id="@+id/chart3"
android:layout_marginVertical="16dp"
android:id="@+id/chart_customization"
android:layout_width="match_parent"
android:layout_height="200dp" />
<com.dzeio.charts.ChartView
android:id="@+id/chart2"
android:id="@+id/chart_bar"
android:layout_width="match_parent"
android:layout_height="200dp" />
<com.dzeio.charts.ChartView
android:id="@+id/chart_line"
android:layout_width="match_parent"
android:layout_height="200dp" />
</LinearLayout>
<!-- </ScrollView>-->
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>