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
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener {
val set = data.getDataSetByIndex(0)

if (set != null) {
val e = set.getEntryForXValue((set.entryCount - 1).toFloat(), Float.NaN)
set.getEntryForXValue((set.entryCount - 1).toFloat(), Float.NaN)?.let { entry ->
data.removeEntry(entry, 0)
// or remove by index
// mData.removeEntryByXValue(xIndex, dataSetIndex);
data.notifyDataChanged()
}

data.removeEntry(e, 0)
// or remove by index
// mData.removeEntryByXValue(xIndex, dataSetIndex);
data.notifyDataChanged()
binding.chart1.notifyDataSetChanged()
binding.chart1.invalidate()
}
Expand Down
11 changes: 3 additions & 8 deletions chartLib/src/main/kotlin/info/appdev/charting/data/ChartData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,9 @@ abstract class ChartData<T : IDataSet<out Entry>> : Serializable {
* Removes the given Entry object from the DataSet at the specified index.
*/
@Suppress("UNCHECKED_CAST")
open fun removeEntry(entry: Entry?, dataSetIndex: Int): Boolean {
open fun removeEntry(entry: Entry, dataSetIndex: Int): Boolean {
// entry null, out of bounds

if (entry == null || dataSetIndex >= dataSets!!.size) {
if (dataSetIndex >= dataSets!!.size) {
return false
}

Expand Down Expand Up @@ -464,11 +463,7 @@ abstract class ChartData<T : IDataSet<out Entry>> : Serializable {
* Returns the DataSet that contains the provided Entry, or null, if no
* DataSet contains this Entry.
*/
fun getDataSetForEntry(e: Entry?): T? {
if (e == null) {
return null
}

fun getDataSetForEntry(e: Entry): T? {
for (i in dataSets!!.indices) {
val set = dataSets!![i]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class CombinedData : BarLineScatterCandleBubbleData<IBarLineScatterCandleBubbleD
}

@Deprecated("removeEntry(...) not supported for CombinedData")
override fun removeEntry(entry: Entry?, dataSetIndex: Int): Boolean {
override fun removeEntry(entry: Entry, dataSetIndex: Int): Boolean {
Timber.e("removeEntry(...) not supported for CombinedData")
return false
}
Expand Down
Loading