Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<activity android:name="info.appdev.chartexample.StackedBarActivityNegative" />
<activity android:name="info.appdev.chartexample.BarChartPositiveNegative" />
<activity android:name="info.appdev.chartexample.FilledLineActivity" />
<activity android:name="info.appdev.chartexample.GradientActivity" />
<activity android:name="info.appdev.chartexample.HalfPieChartActivity" />
<activity android:name="info.appdev.chartexample.SpecificPositionsLineChartActivity" />
</application>
Expand Down
78 changes: 78 additions & 0 deletions app/src/main/kotlin/info/appdev/chartexample/GradientActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package info.appdev.chartexample

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import info.appdev.chartexample.notimportant.DemoBase
import info.appdev.charting.charts.LineChart
import info.appdev.charting.data.Entry
import info.appdev.charting.data.LineData
import info.appdev.charting.data.LineDataSet
import info.appdev.charting.formatter.IFillFormatter
import info.appdev.charting.interfaces.dataprovider.LineDataProvider
import info.appdev.charting.interfaces.datasets.ILineDataSet
import info.appdev.charting.utils.Utils

class GradientActivity : DemoBase() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_gradient)

ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}

Utils.init(this)

val chart: LineChart = findViewById(R.id.chart)

// Minimal chart setup
chart.description?.isEnabled = false
chart.legend?.isEnabled = false
chart.axisRight.isEnabled = false
chart.setDrawGridBackground(false)

// -----------------------------
// Linear function
// y = k * x
// -----------------------------
val entries = kotlin.collections.ArrayList<Entry>(200)
val k = 2.5f

for (i in 0 until 200) {
entries.add(Entry(i.toFloat(), i * k))
}

val dataSet = LineDataSet(entries, "Linear").apply {
isDrawValues = false
isDrawCirclesEnabled = false
lineWidth = 2f

isDrawFilledEnabled = true
fillAlpha = 255
fillDrawable = ContextCompat.getDrawable(
this@GradientActivity,
R.drawable.gradient_drawable_precipitation
)

fillFormatter = object : IFillFormatter {
override fun getFillLinePosition(
dataSet: ILineDataSet?,
dataProvider: LineDataProvider
): Float = chart.axisLeft.axisMinimum
}
}

chart.axisLeft.axisMinimum = 0f
chart.setData(LineData(dataSet))
chart.invalidate()
}

override fun saveToGallery() = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import info.appdev.chartexample.CombinedChartActivity
import info.appdev.chartexample.CubicLineChartActivity
import info.appdev.chartexample.DynamicalAddingActivity
import info.appdev.chartexample.FilledLineActivity
import info.appdev.chartexample.GradientActivity
import info.appdev.chartexample.HalfPieChartActivity
import info.appdev.chartexample.HorizontalBarChartActivity
import info.appdev.chartexample.InvertedLineChartActivity
Expand Down Expand Up @@ -208,6 +209,9 @@ class MainActivity : ComponentActivity() {

add(ContentItem("Compose Horizontal"))
add(ComposeItem("Horizontal", "Render bar chart horizontally.", HorizontalBarComposeActivity::class.java).toDemoBase())

add(ContentItem("Demonstrate and fix issues"))
add(ContentItem("Gradient", "Show a gradient edge case", GradientActivity::class.java))
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/gradient_drawable_precipitation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:type="linear"
android:angle="-90"
android:endColor="#005183F0"
android:startColor="#5923BAFF" />
</shape>
22 changes: 22 additions & 0 deletions app/src/main/res/layout/activity_gradient.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GradientActivity">


<info.appdev.charting.charts.LineChart
android:id="@+id/chart"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading