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
15 changes: 5 additions & 10 deletions app/src/main/java/info/appdev/chartexample/AnotherBarActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.content.pm.PackageManager
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
Expand All @@ -31,24 +30,20 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
setContentView(R.layout.activity_barchart)

title = "AnotherBarActivity"

tvX = findViewById<TextView>(R.id.tvXMax)
tvY = findViewById<TextView>(R.id.tvYMax)
tvX = findViewById(R.id.tvXMax)
tvY = findViewById(R.id.tvYMax)

seekBarX = findViewById<SeekBar>(R.id.seekBarX)
seekBarX = findViewById(R.id.seekBarX)
seekBarX!!.setOnSeekBarChangeListener(this)

seekBarY = findViewById<SeekBar>(R.id.seekBarY)
seekBarY = findViewById(R.id.seekBarY)
seekBarY!!.setOnSeekBarChangeListener(this)

chart = findViewById<BarChart>(R.id.chart1)
chart = findViewById(R.id.chart1)

chart!!.description.isEnabled = false

Expand Down
20 changes: 8 additions & 12 deletions app/src/main/java/info/appdev/chartexample/BarChartActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.net.toUri
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.components.Legend
Expand Down Expand Up @@ -45,24 +45,20 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
setContentView(R.layout.activity_barchart)

title = "BarChartActivity"

tvX = findViewById<TextView>(R.id.tvXMax)
tvY = findViewById<TextView>(R.id.tvYMax)
tvX = findViewById(R.id.tvXMax)
tvY = findViewById(R.id.tvYMax)

seekBarX = findViewById<SeekBar>(R.id.seekBarX)
seekBarY = findViewById<SeekBar>(R.id.seekBarY)
seekBarX = findViewById(R.id.seekBarX)
seekBarY = findViewById(R.id.seekBarY)

seekBarY!!.setOnSeekBarChangeListener(this)
seekBarX!!.setOnSeekBarChangeListener(this)

chart = findViewById<BarChart>(R.id.chart1)
chart = findViewById(R.id.chart1)
chart!!.setOnChartValueSelectedListener(this)
chart!!.setRoundedBarRadius(50f)

Expand Down Expand Up @@ -141,7 +137,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect
val `val` = (sampleValues[i]!!.toFloat() * (range + 1))

if (`val` * 100 < 25) {
values.add(BarEntry(i.toFloat(), `val`, getResources().getDrawable(R.drawable.star)))
values.add(BarEntry(i.toFloat(), `val`, ResourcesCompat.getDrawable(resources, R.drawable.star, null)))
} else {
values.add(BarEntry(i.toFloat(), `val`))
}
Expand Down Expand Up @@ -173,7 +169,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect
val endColor4 = ContextCompat.getColor(this, android.R.color.holo_red_dark)
val endColor5 = ContextCompat.getColor(this, android.R.color.holo_orange_dark)

val gradientFills: MutableList<Fill?> = ArrayList<Fill?>()
val gradientFills: MutableList<Fill?> = ArrayList()
gradientFills.add(Fill(startColor1, endColor1))
gradientFills.add(Fill(startColor2, endColor2))
gradientFills.add(Fill(startColor3, endColor3))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
Expand Down Expand Up @@ -39,26 +38,22 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
setContentView(R.layout.activity_barchart)

title = "BarChartActivityMultiDataset"

tvX = findViewById<TextView>(R.id.tvXMax)
tvX = findViewById(R.id.tvXMax)
tvX!!.textSize = 10f
tvY = findViewById<TextView>(R.id.tvYMax)
tvY = findViewById(R.id.tvYMax)

seekBarX = findViewById<SeekBar>(R.id.seekBarX)
seekBarX = findViewById(R.id.seekBarX)
seekBarX!!.max = 50
seekBarX!!.setOnSeekBarChangeListener(this)

seekBarY = findViewById<SeekBar>(R.id.seekBarY)
seekBarY = findViewById(R.id.seekBarY)
seekBarY!!.setOnSeekBarChangeListener(this)

chart = findViewById<BarChart>(R.id.chart1)
chart = findViewById(R.id.chart1)
chart!!.setOnChartValueSelectedListener(this)
chart!!.description.isEnabled = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.graphics.Color
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
Expand All @@ -31,21 +30,17 @@ class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
setContentView(R.layout.activity_barchart_sinus)

title = "BarChartActivitySinus"

data = FileUtils.loadBarEntriesFromAssets(assets, "othersine.txt")

tvX = findViewById<TextView>(R.id.tvValueCount)
tvX = findViewById(R.id.tvValueCount)

seekBarX = findViewById<SeekBar>(R.id.seekbarValues)
seekBarX = findViewById(R.id.seekbarValues)

chart = findViewById<BarChart>(R.id.chart1)
chart = findViewById(R.id.chart1)

chart!!.setDrawBarShadow(false)
chart!!.setDrawValueAboveBar(true)
Expand Down Expand Up @@ -105,7 +100,7 @@ class BarChartActivitySinus : DemoBase(), OnSeekBarChangeListener {
val entries = ArrayList<BarEntry?>()

for (i in 0..<count) {
entries.add(data!!.get(i))
entries.add(data!![i])
}

val set: BarDataSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.graphics.Color
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import androidx.core.net.toUri
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.components.AxisBase
Expand All @@ -27,15 +26,11 @@ class BarChartPositiveNegative : DemoBase() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
setContentView(R.layout.activity_barchart_noseekbar)

title = "BarChartPositiveNegative"

chart = findViewById<BarChart>(R.id.chart1)
chart = findViewById(R.id.chart1)
chart!!.setBackgroundColor(Color.WHITE)
chart!!.extraTopOffset = -30f
chart!!.extraBottomOffset = 10f
Expand Down Expand Up @@ -76,7 +71,7 @@ class BarChartPositiveNegative : DemoBase() {
chart!!.legend.isEnabled = false

// THIS IS THE ORIGINAL DATA YOU WANT TO PLOT
val data: MutableList<Data> = ArrayList<Data>()
val data: MutableList<Data> = ArrayList()
data.add(Data(0f, -224.1f, "12-29"))
data.add(Data(1f, 238.5f, "12-30"))
data.add(Data(2f, 1280.1f, "12-31"))
Expand All @@ -85,7 +80,7 @@ class BarChartPositiveNegative : DemoBase() {

xAxis.valueFormatter = object : IAxisValueFormatter {
override fun getFormattedValue(value: Float, axis: AxisBase?): String? {
return data.get(min(max(value.toInt(), 0), data.size - 1)).xAxisValue
return data[min(max(value.toInt(), 0), data.size - 1)].xAxisValue
}
}

Expand All @@ -100,7 +95,7 @@ class BarChartPositiveNegative : DemoBase() {
val red = Color.rgb(211, 74, 88)

for (i in dataList.indices) {
val d = dataList.get(i)
val d = dataList[i]
val entry = BarEntry(d.xValue, d.yValue)
values.add(entry)

Expand Down Expand Up @@ -140,11 +135,7 @@ class BarChartPositiveNegative : DemoBase() {
private class Data(val xValue: Float, val yValue: Float, val xAxisValue: String?)

private class ValueFormatter : IValueFormatter {
private val mFormat: DecimalFormat

init {
mFormat = DecimalFormat("######.0")
}
private val mFormat: DecimalFormat = DecimalFormat("######.0")

override fun getFormattedValue(value: Float, entry: Entry?, dataSetIndex: Int, viewPortHandler: ViewPortHandler?): String {
return mFormat.format(value.toDouble())
Expand Down
20 changes: 8 additions & 12 deletions app/src/main/java/info/appdev/chartexample/BubbleChartActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.net.toUri
import com.github.mikephil.charting.charts.BubbleChart
import com.github.mikephil.charting.components.Legend
Expand All @@ -38,24 +38,20 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
setContentView(R.layout.activity_bubblechart)

title = "BubbleChartActivity"

tvX = findViewById<TextView>(R.id.tvXMax)
tvY = findViewById<TextView>(R.id.tvYMax)
tvX = findViewById(R.id.tvXMax)
tvY = findViewById(R.id.tvYMax)

seekBarX = findViewById<SeekBar>(R.id.seekBarX)
seekBarX = findViewById(R.id.seekBarX)
seekBarX!!.setOnSeekBarChangeListener(this)

seekBarY = findViewById<SeekBar>(R.id.seekBarY)
seekBarY = findViewById(R.id.seekBarY)
seekBarY!!.setOnSeekBarChangeListener(this)

chart = findViewById<BubbleChart>(R.id.chart1)
chart = findViewById(R.id.chart1)
chart!!.description.isEnabled = false

chart!!.setOnChartValueSelectedListener(this)
Expand Down Expand Up @@ -112,15 +108,15 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel
i.toFloat(),
(sampleValues[i + 1]!! * range).toFloat(),
(sampleValues[i]!!.toFloat() * range),
getResources().getDrawable(R.drawable.star)
ResourcesCompat.getDrawable(resources, R.drawable.star, null)
)
)
values2.add(
BubbleEntry(
i.toFloat(),
(sampleValues[i + 2]!! * range).toFloat(),
(sampleValues[i + 1]!!.toFloat() * range),
getResources().getDrawable(R.drawable.star)
ResourcesCompat.getDrawable(resources, R.drawable.star, null)
)
)
values3.add(BubbleEntry(i.toFloat(), (sampleValues[i]!! * range).toFloat(), (sampleValues[i + 2]!!.toFloat() * range)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import android.graphics.Paint
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import com.github.mikephil.charting.charts.CandleStickChart
import com.github.mikephil.charting.components.XAxis.XAxisPosition
import com.github.mikephil.charting.components.YAxis.AxisDependency
Expand All @@ -32,24 +32,20 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
setContentView(R.layout.activity_candlechart)

title = "CandleStickChartActivity"

tvX = findViewById<TextView>(R.id.tvXMax)
tvY = findViewById<TextView>(R.id.tvYMax)
tvX = findViewById(R.id.tvXMax)
tvY = findViewById(R.id.tvYMax)

seekBarX = findViewById<SeekBar>(R.id.seekBarX)
seekBarX = findViewById(R.id.seekBarX)
seekBarX!!.setOnSeekBarChangeListener(this)

seekBarY = findViewById<SeekBar>(R.id.seekBarY)
seekBarY = findViewById(R.id.seekBarY)
seekBarY!!.setOnSeekBarChangeListener(this)

chart = findViewById<CandleStickChart>(R.id.chart1)
chart = findViewById(R.id.chart1)
chart!!.setBackgroundColor(Color.WHITE)

chart!!.description.isEnabled = false
Expand Down Expand Up @@ -86,8 +82,7 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener {
}

override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
var progress: Int
progress = (seekBarX!!.progress)
val progress: Int = (seekBarX!!.progress)

tvX!!.text = progress.toString()
tvY!!.text = seekBarY!!.progress.toString()
Expand Down Expand Up @@ -115,7 +110,7 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener {
`val` - low,
if (even) `val` + open else `val` - open,
if (even) `val` - close else `val` + close,
getResources().getDrawable(R.drawable.star)
ResourcesCompat.getDrawable(resources, R.drawable.star, null)
)
)
}
Expand Down
Loading
Loading