diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/HorizontalBarChart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/HorizontalBarChart.java index cc1ac21f7..93c78295d 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/HorizontalBarChart.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/HorizontalBarChart.java @@ -224,11 +224,6 @@ public void getBarBounds(BarEntry barEntry, RectF outputRect) { RectF bounds = outputRect; IBarDataSet set = mData.getDataSetForEntry(barEntry); - if (set == null) { - outputRect.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE); - return; - } - float y = barEntry.getY(); float x = barEntry.getX(); diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/Legend.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/components/Legend.kt index a8596b132..4b0d4b9f5 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/Legend.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/Legend.kt @@ -18,7 +18,6 @@ import kotlin.collections.MutableList import kotlin.collections.toTypedArray import kotlin.math.max import kotlin.math.min -import kotlin.requireNotNull /** * Class representing the legend of the chart. The legend will contain one entry @@ -87,10 +86,6 @@ class Legend() : ComponentBase() { var extraEntries: Array = arrayOf() private set - /** - * @return true if a custom legend entries has been set default - * false (automatic legend) - */ /** * Are the legend labels/colors a custom value or auto calculated? If false, * then it's auto, if true, then custom. default false (automatic legend) @@ -98,23 +93,14 @@ class Legend() : ComponentBase() { var isLegendCustom: Boolean = false private set - /** - * returns the horizontal alignment of the legend - */ /** * sets the horizontal alignment of the legend */ - var horizontalAlignment: LegendHorizontalAlignment? = LegendHorizontalAlignment.LEFT - /** - * returns the vertical alignment of the legend - */ + var horizontalAlignment: LegendHorizontalAlignment = LegendHorizontalAlignment.LEFT /** * sets the vertical alignment of the legend */ - var verticalAlignment: LegendVerticalAlignment? = LegendVerticalAlignment.BOTTOM - /** - * returns the orientation of the legend - */ + var verticalAlignment: LegendVerticalAlignment = LegendVerticalAlignment.BOTTOM /** * sets the orientation of the legend */ @@ -126,93 +112,41 @@ class Legend() : ComponentBase() { var isDrawInsideEnabled: Boolean = false private set - /** - * returns the text direction of the legend - */ - /** - * sets the text direction of the legend - */ /** * the text direction for the legend */ - var direction: LegendDirection? = LegendDirection.LEFT_TO_RIGHT + var direction: LegendDirection = LegendDirection.LEFT_TO_RIGHT - /** - * returns the current form/shape that is set for the legend - */ - /** - * sets the form/shape of the legend forms - */ /** * the shape/form the legend colors are drawn in */ - var form: LegendForm? = LegendForm.SQUARE + var form: LegendForm = LegendForm.SQUARE - /** - * returns the size in dp of the legend forms - */ - /** - * sets the size in dp of the legend forms, default 8f - */ /** * the size of the legend forms/shapes */ var formSize: kotlin.Float = 8f - /** - * returns the line width in dp for drawing forms that consist of lines - */ - /** - * sets the line width in dp for forms that consist of lines, default 3f - */ /** * the size of the legend forms/shapes */ var formLineWidth: kotlin.Float = 3f - /** - * @return The line dash path effect used for shapes that consist of lines. - */ - /** - * Sets the line dash path effect used for shapes that consist of lines. - */ /** * Line dash path effect used for shapes that consist of lines. */ var formLineDashEffect: DashPathEffect? = null - /** - * returns the space between the legend entries on a horizontal axis in - * pixels - */ - /** - * sets the space between the legend entries on a horizontal axis in pixels, - * converts to dp internally - */ /** * the space between the legend entries on a horizontal axis, default 6f */ var xEntrySpace: kotlin.Float = 6f - /** - * returns the space between the legend entries on a vertical axis in pixels - */ - /** - * sets the space between the legend entries on a vertical axis in pixels, - * converts to dp internally - */ /** * the space between the legend entries on a vertical axis, default 5f */ var yEntrySpace: kotlin.Float = 0f - /** - * returns the space between the form and the actual label/text - */ - /** - * sets the space between the form and the actual label/text, converts to dp - * internally - */ /** * the space between the legend entries on a vertical axis, default 2f * private float mYEntrySpace = 2f; / ** the space between the form and the @@ -220,12 +154,6 @@ class Legend() : ComponentBase() { */ var formToTextSpace: kotlin.Float = 5f - /** - * returns the space that is left out between stacked forms (with no label) - */ - /** - * sets the space that is left out between stacked forms (with no label) - */ /** * the space that should be left between stacked forms */ @@ -239,23 +167,12 @@ class Legend() : ComponentBase() { * piechart, then this defines the size of the rectangular bounds out of the * size of the "hole". / default: 0.95f (95%) */ - /** - * The maximum relative size out of the whole chart view. / If - * the legend is to the right/left of the chart, then this affects the width - * of the legend. / If the legend is to the top/bottom of the chart, then - * this affects the height of the legend. / default: 0.95f (95%) - */ - /** - * the maximum relative size out of the whole chart view in percent - */ var maxSizePercent: kotlin.Float = 0.95f /** * Constructor. Provide entries for the legend. */ constructor(entries: Array) : this() { - requireNotNull(entries) { "entries array is NULL" } - this.entries = entries } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/LegendEntry.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/components/LegendEntry.kt index c435a1d2c..c0aafe36b 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/LegendEntry.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/LegendEntry.kt @@ -19,7 +19,7 @@ class LegendEntry { */ constructor( label: String?, - form: LegendForm?, + form: LegendForm, formSize: Float, formLineWidth: Float, formLineDashEffect: DashPathEffect?, @@ -46,7 +46,7 @@ class LegendEntry { * `EMPTY` will avoid drawing a form, but keep its space. * `DEFAULT` will use the Legend's default. */ - var form: LegendForm? = LegendForm.DEFAULT + var form: LegendForm = LegendForm.DEFAULT /** * Form size will be considered except for when .None is used diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/listener/PieRadarChartTouchListener.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/listener/PieRadarChartTouchListener.kt index 8fcae2d89..2b127de47 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/listener/PieRadarChartTouchListener.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/listener/PieRadarChartTouchListener.kt @@ -65,7 +65,7 @@ class PieRadarChartTouchListener(chart: PieRadarChartBase<*>?) : ChartTouchListe chart!!.disableScroll() } else if (touchMode == ROTATE) { updateGestureRotation(x, y) - chart!!.invalidate() + chart?.invalidate() } endAction(event) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LegendRenderer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LegendRenderer.kt index 2799b6c96..7d9e190af 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LegendRenderer.kt +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LegendRenderer.kt @@ -4,7 +4,6 @@ import android.graphics.Canvas import android.graphics.Paint import android.graphics.Paint.Align import android.graphics.Path -import android.util.Log import androidx.core.graphics.withSave import com.github.mikephil.charting.components.Legend import com.github.mikephil.charting.components.Legend.LegendDirection @@ -228,7 +227,7 @@ open class LegendRenderer( val yOffset = legend.yOffset val xOffset = legend.xOffset - var originPosX = 0f + var originPosX: Float when (horizontalAlignment) { LegendHorizontalAlignment.LEFT -> { @@ -266,8 +265,6 @@ open class LegendRenderer( legend.mNeededWidth / 2.0 - xOffset).toFloat() } } - - null -> Log.e("Chart", "Legend horizontalAlignment is null") } when (orientation) { @@ -282,10 +279,6 @@ open class LegendRenderer( LegendVerticalAlignment.TOP -> yOffset LegendVerticalAlignment.BOTTOM -> viewPortHandler.chartHeight - yOffset - legend.mNeededHeight LegendVerticalAlignment.CENTER -> (viewPortHandler.chartHeight - legend.mNeededHeight) / 2f + yOffset - else -> { - Log.w("Chart", "Legend verticalAlignment not set") - 0f - } } var lineIndex = 0 @@ -344,7 +337,7 @@ open class LegendRenderer( // contains the stacked legend size in pixels var stack = 0f var wasStacked = false - var posY = 0f + var posY: Float when (verticalAlignment) { LegendVerticalAlignment.TOP -> { @@ -366,8 +359,6 @@ open class LegendRenderer( LegendVerticalAlignment.CENTER -> posY = (viewPortHandler.chartHeight / 2f - legend.mNeededHeight / 2f + legend.yOffset) - - null -> Log.w("Chart", "Legend verticalAlignment is null") } var i = 0 @@ -496,9 +487,6 @@ open class LegendRenderer( mLineFormPath.lineTo(x + formSize, y) canvas.drawPath(mLineFormPath, formPaint) } - - null -> Log.w( "Chart", "Legend form is null") - } } diff --git a/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt index 4e67247fe..75c3e7c12 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/AnotherBarActivity.kt @@ -92,7 +92,7 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener { set1 = chart!!.data!!.getDataSetByIndex(0) as BarDataSet set1.entries = values chart!!.data!!.notifyDataChanged() - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } else { set1 = BarDataSet(values, "Data Set") set1.setColors(*ColorTemplate.VORDIPLOM_COLORS) @@ -106,7 +106,7 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener { chart!!.setFitBars(true) } - chart!!.invalidate() + chart?.invalidate() } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -128,13 +128,13 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener { it?.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlight -> { if (chart!!.data != null) { chart!!.data!!.isHighlightEnabled = !chart!!.data!!.isHighlightEnabled() - chart!!.invalidate() + chart?.invalidate() } } @@ -142,18 +142,18 @@ class AnotherBarActivity : DemoBase(), OnSeekBarChangeListener { if (chart!!.isPinchZoomEnabled) chart!!.setPinchZoom(false) else chart!!.setPinchZoom(true) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleAutoScaleMinMax -> { chart!!.isAutoScaleMinMaxEnabled = !chart!!.isAutoScaleMinMaxEnabled - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } R.id.actionToggleBarBorders -> { for (set in chart!!.data!!.dataSets) (set as BarDataSet).barBorderWidth = if (set.barBorderWidth == 1f) 0f else 1f - chart!!.invalidate() + chart?.invalidate() } R.id.animateX -> { diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt index 661c0f064..9cde1a234 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivity.kt @@ -115,7 +115,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect val mv = XYMarkerView(this, xAxisFormatter) mv.chartView = chart // For bounds control - chart!!.setMarker(mv) // Set the marker to the chart + chart?.setMarker(mv) // Set the marker to the chart // setting data seekBarY!!.progress = 50 @@ -150,7 +150,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect set1 = chart!!.data!!.getDataSetByIndex(0) as BarDataSet set1.entries = values chart!!.data!!.notifyDataChanged() - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } else { set1 = BarDataSet(values, "The year 2017") @@ -184,7 +184,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect data.setValueTypeface(tfLight) data.barWidth = 0.9f - chart!!.setData(data) + chart?.setData(data) } } @@ -206,20 +206,20 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect it?.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleIcons -> { for (set in chart!!.data!!.dataSets) set?.isDrawIcons = !set.isDrawIcons - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlight -> { if (chart!!.data != null) { chart!!.data!!.isHighlightEnabled = !chart!!.data!!.isHighlightEnabled() - chart!!.invalidate() + chart?.invalidate() } } @@ -227,12 +227,12 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect if (chart!!.isPinchZoomEnabled) chart!!.setPinchZoom(false) else chart!!.setPinchZoom(true) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleAutoScaleMinMax -> { chart!!.isAutoScaleMinMaxEnabled = !chart!!.isAutoScaleMinMaxEnabled - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } R.id.actionToggleBarBorders -> { @@ -242,7 +242,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect else 1f - chart!!.invalidate() + chart?.invalidate() } R.id.animateX -> { @@ -267,8 +267,8 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect R.id.actionRotateXAxisLabelsBy45Deg -> { chart!!.xAxis.labelRotationAngle = 45f - chart!!.notifyDataSetChanged() - chart!!.invalidate() + chart?.notifyDataSetChanged() + chart?.invalidate() } } return true @@ -279,7 +279,7 @@ class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect tvY!!.text = seekBarY!!.progress.toString() setData(seekBarX!!.progress, seekBarY!!.progress.toFloat()) - chart!!.invalidate() + chart?.invalidate() } override fun saveToGallery() { diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt index 0d6cc3a33..209f4c2b0 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt @@ -147,7 +147,7 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar set3.entries = values3 set4.entries = values4 chart!!.data!!.notifyDataChanged() - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } else { // create 4 DataSets set1 = BarDataSet(values1, "Company A") @@ -175,7 +175,7 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar // barData.getGroupWith(...) is a helper that calculates the width each group needs based on the provided parameters chart!!.xAxis.axisMaximum = startYear + chart!!.barData.getGroupWidth(groupSpace, barSpace) * groupCount chart!!.groupBars(startYear.toFloat(), groupSpace, barSpace) - chart!!.invalidate() + chart?.invalidate() } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -197,31 +197,31 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar it?.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionTogglePinch -> { if (chart!!.isPinchZoomEnabled) chart!!.setPinchZoom(false) else chart!!.setPinchZoom(true) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleAutoScaleMinMax -> { chart!!.isAutoScaleMinMaxEnabled = !chart!!.isAutoScaleMinMaxEnabled - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } R.id.actionToggleBarBorders -> { for (set in chart!!.data!!.dataSets) (set as BarDataSet).barBorderWidth = if (set.barBorderWidth == 1f) 0f else 1f - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlight -> { if (chart!!.data != null) { chart!!.data!!.isHighlightEnabled = !chart!!.data!!.isHighlightEnabled() - chart!!.invalidate() + chart?.invalidate() } } diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt index 2689fb268..78b511c1b 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt @@ -110,7 +110,7 @@ class BarChartPositiveNegative : DemoBase() { set = chart!!.data!!.getDataSetByIndex(0) as BarDataSet set.entries = values chart!!.data!!.notifyDataChanged() - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } else { set = BarDataSet(values, "Values") set.setColors(colors) @@ -123,7 +123,7 @@ class BarChartPositiveNegative : DemoBase() { data.barWidth = 0.8f chart!!.setData(data) - chart!!.invalidate() + chart?.invalidate() } } diff --git a/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt index 16388d3be..9c0a70d42 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BubbleChartActivity.kt @@ -150,7 +150,7 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel data.setHighlightCircleWidth(1.5f) chart!!.setData(data) - chart!!.invalidate() + chart?.invalidate() } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -170,19 +170,19 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel chart!!.data!!.dataSets.forEach { it?.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleIcons -> { for (set in chart!!.data!!.dataSets) set?.isDrawIcons = !set.isDrawIcons - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlight -> { if (chart!!.data != null) { chart!!.data!!.isHighlightEnabled = !chart!!.data!!.isHighlightEnabled() - chart!!.invalidate() + chart?.invalidate() } } @@ -190,12 +190,12 @@ class BubbleChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSel if (chart!!.isPinchZoomEnabled) chart!!.setPinchZoom(false) else chart!!.setPinchZoom(true) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleAutoScaleMinMax -> { chart!!.isAutoScaleMinMaxEnabled = !chart!!.isAutoScaleMinMaxEnabled - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } R.id.actionSave -> { diff --git a/app/src/main/kotlin/info/appdev/chartexample/CandleStickChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/CandleStickChartActivity.kt index 412f83ca2..da76c3a35 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/CandleStickChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/CandleStickChartActivity.kt @@ -130,7 +130,7 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener { val data = CandleData(set1) chart!!.setData(data) - chart!!.invalidate() + chart?.invalidate() } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -151,19 +151,19 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener { chart!!.data!!.dataSets.forEach { it?.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleIcons -> { for (set in chart!!.data!!.dataSets) set?.isDrawIcons = !set.isDrawIcons - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlight -> { if (chart!!.data != null) { chart!!.data!!.isHighlightEnabled = !chart!!.data!!.isHighlightEnabled() - chart!!.invalidate() + chart?.invalidate() } } @@ -171,12 +171,12 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener { if (chart!!.isPinchZoomEnabled) chart!!.setPinchZoom(false) else chart!!.setPinchZoom(true) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleAutoScaleMinMax -> { chart!!.isAutoScaleMinMaxEnabled = !chart!!.isAutoScaleMinMaxEnabled - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } R.id.actionToggleMakeShadowSameColorAsCandle -> { @@ -184,7 +184,7 @@ class CandleStickChartActivity : DemoBase(), OnSeekBarChangeListener { (set as CandleDataSet).shadowColorSameAsCandle = !set.shadowColorSameAsCandle } - chart!!.invalidate() + chart?.invalidate() } R.id.animateX -> { diff --git a/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt index 7871e499f..83a5a6d27 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/CombinedChartActivity.kt @@ -93,7 +93,7 @@ class CombinedChartActivity : DemoBase() { xAxis.axisMaximum = data.xMax + 0.25f chart!!.setData(data) - chart!!.invalidate() + chart?.invalidate() } private fun generateLineData(): LineData { @@ -242,7 +242,7 @@ class CombinedChartActivity : DemoBase() { if (it is LineDataSet) it.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleBarValues -> { @@ -250,15 +250,15 @@ class CombinedChartActivity : DemoBase() { if (it is BarDataSet) it.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionRemoveDataSet -> { val rnd = values[sampleCount]!!.toFloat().toInt() * chart!!.data!!.getDataSetCount() chart!!.data!!.removeDataSet(chart!!.data!!.getDataSetByIndex(rnd)) chart!!.data!!.notifyDataChanged() - chart!!.notifyDataSetChanged() - chart!!.invalidate() + chart?.notifyDataSetChanged() + chart?.invalidate() } } return true diff --git a/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt index 3c82c0222..7ac0a78e2 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/DynamicalAddingActivity.kt @@ -37,7 +37,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { // chart.getXAxis().setDrawLabels(false); // chart.getXAxis().setDrawGridLines(false); - chart!!.invalidate() + chart?.invalidate() } private val colors: IntArray = ColorTemplate.VORDIPLOM_COLORS @@ -69,7 +69,7 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { data.notifyDataChanged() // let the chart know it's data has changed - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() chart!!.setVisibleXRangeMaximum(6f) //chart.setVisibleYRangeMaximum(15, AxisDependency.LEFT); @@ -92,8 +92,8 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { // or remove by index // mData.removeEntryByXValue(xIndex, dataSetIndex); data.notifyDataChanged() - chart!!.notifyDataSetChanged() - chart!!.invalidate() + chart?.notifyDataSetChanged() + chart?.invalidate() } } } @@ -129,8 +129,8 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { data.addDataSet(set) data.notifyDataChanged() - chart!!.notifyDataSetChanged() - chart!!.invalidate() + chart?.notifyDataSetChanged() + chart?.invalidate() } } @@ -140,8 +140,8 @@ class DynamicalAddingActivity : DemoBase(), OnChartValueSelectedListener { if (data != null) { data.removeDataSet(data.getDataSetByIndex(data.getDataSetCount() - 1)) - chart!!.notifyDataSetChanged() - chart!!.invalidate() + chart?.notifyDataSetChanged() + chart?.invalidate() } } diff --git a/app/src/main/kotlin/info/appdev/chartexample/HalfPieChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/HalfPieChartActivity.kt index c9e984bfd..9dfa6cd91 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/HalfPieChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/HalfPieChartActivity.kt @@ -102,7 +102,7 @@ class HalfPieChartActivity : DemoBase() { data.setValueTypeface(tfLight) chart!!.setData(data) - chart!!.invalidate() + chart?.invalidate() } private fun generateCenterSpannableText(): SpannableString { diff --git a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt index c9300b99b..0b6171ddc 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/HorizontalBarNegativeChartActivity.kt @@ -128,7 +128,7 @@ class HorizontalBarNegativeChartActivity : DemoBase(), OnSeekBarChangeListener, set1 = chart!!.data!!.getDataSetByIndex(0) as BarDataSet set1.entries = values chart!!.data!!.notifyDataChanged() - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } else { set1 = BarDataSet(values, "DataSet 1") @@ -163,7 +163,7 @@ class HorizontalBarNegativeChartActivity : DemoBase(), OnSeekBarChangeListener, chart!!.data!!.dataSets.forEach { it?.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleIcons -> { @@ -171,31 +171,31 @@ class HorizontalBarNegativeChartActivity : DemoBase(), OnSeekBarChangeListener, iSet.isDrawIcons = !iSet.isDrawIcons } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlight -> { if (chart!!.data != null) { chart!!.data!!.isHighlightEnabled = !chart!!.data!!.isHighlightEnabled() - chart!!.invalidate() + chart?.invalidate() } } R.id.actionTogglePinch -> { chart!!.setPinchZoom(!chart!!.isPinchZoomEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleAutoScaleMinMax -> { chart!!.isAutoScaleMinMaxEnabled = !chart!!.isAutoScaleMinMaxEnabled - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } R.id.actionToggleBarBorders -> { for (set in chart!!.data!!.dataSets) (set as BarDataSet).barBorderWidth = if (set.barBorderWidth == 1f) 0f else 1f - chart!!.invalidate() + chart?.invalidate() } R.id.animateX -> { @@ -227,7 +227,7 @@ class HorizontalBarNegativeChartActivity : DemoBase(), OnSeekBarChangeListener, setData(seekBarX!!.progress, seekBarY!!.progress.toFloat()) chart!!.setFitBars(true) - chart!!.invalidate() + chart?.invalidate() } override fun saveToGallery() { diff --git a/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt index f4b4bfcbd..72635d44b 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/InvertedLineChartActivity.kt @@ -99,7 +99,7 @@ class InvertedLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa l.form = LegendForm.LINE // don't forget to refresh the drawing - chart!!.invalidate() + chart?.invalidate() } private fun setData(count: Int, range: Float) { @@ -146,13 +146,13 @@ class InvertedLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa chart!!.data!!.dataSets.forEach { it?.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlight -> { if (chart!!.data != null) { chart!!.data!!.isHighlightEnabled = !chart!!.data!!.isHighlightEnabled() - chart!!.invalidate() + chart?.invalidate() } } @@ -160,7 +160,7 @@ class InvertedLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa chart!!.data!!.dataSets.forEach { set -> set?.setDrawFilled(!set.isDrawFilledEnabled) } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleCircles -> { @@ -170,7 +170,7 @@ class InvertedLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa val set = iSet as LineDataSet set.isDrawCirclesEnabled = !set.isDrawCirclesEnabled } - chart!!.invalidate() + chart?.invalidate() } R.id.animateX -> { @@ -188,12 +188,12 @@ class InvertedLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa R.id.actionTogglePinch -> { chart!!.setPinchZoom(!chart!!.isPinchZoomEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleAutoScaleMinMax -> { chart!!.isAutoScaleMinMaxEnabled = !chart!!.isAutoScaleMinMaxEnabled - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } R.id.actionSave -> { @@ -214,7 +214,7 @@ class InvertedLineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa setData(seekBarX!!.progress, seekBarY!!.progress.toFloat()) // redraw - chart!!.invalidate() + chart?.invalidate() } override fun saveToGallery() { diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt index 311fa7cb6..2a161d1e6 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartDualAxisActivity.kt @@ -157,7 +157,7 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa set2.entries = values2 set3.entries = values3 chart!!.data!!.notifyDataChanged() - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } else { // create a dataset and give it a type set1 = LineDataSet(values1, "DataSet 1") @@ -229,13 +229,13 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa chart!!.data!!.dataSets.forEach { set -> set?.isDrawValues = !set.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlight -> { if (chart!!.data != null) { chart!!.data!!.isHighlightEnabled = !chart!!.data!!.isHighlightEnabled() - chart!!.invalidate() + chart?.invalidate() } } @@ -243,7 +243,7 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa chart!!.data!!.dataSets.forEach { set -> set?.setDrawFilled(!set.isDrawFilledEnabled) } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleCircles -> { @@ -253,7 +253,7 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa val set = iSet as LineDataSet set.isDrawCirclesEnabled = !set.isDrawCirclesEnabled } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleCubic -> { @@ -266,7 +266,7 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa else LineDataSet.Mode.CUBIC_BEZIER } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleStepped -> { @@ -279,7 +279,7 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa else LineDataSet.Mode.STEPPED } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHorizontalCubic -> { @@ -292,18 +292,18 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa else LineDataSet.Mode.HORIZONTAL_BEZIER } - chart!!.invalidate() + chart?.invalidate() } R.id.actionTogglePinch -> { chart!!.setPinchZoom(!chart!!.isPinchZoomEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleAutoScaleMinMax -> { chart!!.isAutoScaleMinMaxEnabled = !chart!!.isAutoScaleMinMaxEnabled - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } R.id.animateX -> { @@ -336,7 +336,7 @@ class LineChartDualAxisActivity : DemoBase(), OnSeekBarChangeListener, OnChartVa setData(seekBarX!!.progress, seekBarY!!.progress.toFloat()) // redraw - chart!!.invalidate() + chart?.invalidate() } override fun saveToGallery() { diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt index 160bc0067..b4fe5ef94 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt @@ -166,13 +166,13 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { chart!!.data!!.dataSets.forEach { set -> set?.isDrawValues = !set.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlight -> { if (chart!!.data != null) { chart!!.data!!.isHighlightEnabled = !chart!!.data!!.isHighlightEnabled() - chart!!.invalidate() + chart?.invalidate() } } @@ -185,7 +185,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { set.setDrawFilled(true) } } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleCircles -> { @@ -195,7 +195,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { val set = iSet as LineDataSet set.isDrawCirclesEnabled = !set.isDrawCirclesEnabled } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleCubic -> { @@ -208,7 +208,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { else set.lineMode = LineDataSet.Mode.CUBIC_BEZIER } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleStepped -> { @@ -221,19 +221,19 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { else set.lineMode = LineDataSet.Mode.STEPPED } - chart!!.invalidate() + chart?.invalidate() } R.id.actionTogglePinch -> { if (chart!!.isPinchZoomEnabled) chart!!.setPinchZoom(false) else chart!!.setPinchZoom(true) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleAutoScaleMinMax -> { chart!!.isAutoScaleMinMaxEnabled = !chart!!.isAutoScaleMinMaxEnabled - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } R.id.animateX -> { @@ -265,7 +265,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { setData(seekBarX!!.progress) // redraw - chart!!.invalidate() + chart?.invalidate() } override fun saveToGallery() { diff --git a/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt b/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt index 0ff8d20d0..77f5f73e6 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/PerformanceLineChart.kt @@ -53,7 +53,7 @@ class PerformanceLineChart : DemoBase(), OnSeekBarChangeListener { seekBarValues!!.progress = 9000 // don't forget to refresh the drawing - chart!!.invalidate() + chart?.invalidate() } private fun setData(count: Int, range: Float) { @@ -113,7 +113,7 @@ class PerformanceLineChart : DemoBase(), OnSeekBarChangeListener { setData(count, 500f) // redraw - chart!!.invalidate() + chart?.invalidate() } public override fun saveToGallery() { /* Intentionally left empty */ diff --git a/app/src/main/kotlin/info/appdev/chartexample/PieChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/PieChartActivity.kt index fc135c24d..976fc8ccc 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/PieChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/PieChartActivity.kt @@ -159,7 +159,7 @@ class PieChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect // undo all highlights chart!!.highlightValues(null) - chart!!.invalidate() + chart?.invalidate() } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -180,26 +180,26 @@ class PieChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect chart!!.data!!.dataSets.forEach { it?.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleIcons -> { for (set in chart!!.data!!.getDataSets()) set?.isDrawIcons = !set.isDrawIcons - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHole -> { chart!!.isDrawHoleEnabled = !chart!!.isDrawHoleEnabled - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleMinAngles -> { if (chart!!.minAngleForSlices == 0f) chart!!.setMinAngleForSlices(36f) else chart!!.setMinAngleForSlices(0f) - chart!!.notifyDataSetChanged() - chart!!.invalidate() + chart?.notifyDataSetChanged() + chart?.invalidate() } R.id.actionToggleCurvedSlices -> { @@ -211,22 +211,22 @@ class PieChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelect if (toSet && chart!!.isDrawSlicesUnderHoleEnabled) { chart!!.setDrawSlicesUnderHole(false) } - chart!!.invalidate() + chart?.invalidate() } R.id.actionDrawCenter -> { chart!!.setDrawCenterText(!chart!!.isDrawCenterTextEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleXValues -> { chart!!.setDrawEntryLabels(!chart!!.isDrawEntryLabelsEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.actionTogglePercent -> { chart!!.setUsePercentValues(!chart!!.isUsePercentValuesEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.animateX -> { diff --git a/app/src/main/kotlin/info/appdev/chartexample/PieChartRoundedActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/PieChartRoundedActivity.kt index bbf691e50..696768d54 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/PieChartRoundedActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/PieChartRoundedActivity.kt @@ -165,7 +165,7 @@ class PieChartRoundedActivity : DemoBase(), OnSeekBarChangeListener, OnChartValu renderer.roundedCornerRadius = 30f dataSet.sliceSpace = renderer.roundedCornerRadius / 2 - chart!!.invalidate() + chart?.invalidate() } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -185,26 +185,26 @@ class PieChartRoundedActivity : DemoBase(), OnSeekBarChangeListener, OnChartValu chart!!.data!!.dataSets.forEach { it?.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleIcons -> { for (set in chart!!.data!!.getDataSets()) set?.isDrawIcons = !set.isDrawIcons - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHole -> { chart!!.isDrawHoleEnabled = !chart!!.isDrawHoleEnabled - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleMinAngles -> { if (chart!!.minAngleForSlices == 0f) chart!!.setMinAngleForSlices(36f) else chart!!.setMinAngleForSlices(0f) - chart!!.notifyDataSetChanged() - chart!!.invalidate() + chart?.notifyDataSetChanged() + chart?.invalidate() } R.id.actionToggleCurvedSlices -> { @@ -216,22 +216,22 @@ class PieChartRoundedActivity : DemoBase(), OnSeekBarChangeListener, OnChartValu if (toSet && chart!!.isDrawSlicesUnderHoleEnabled) { chart!!.setDrawSlicesUnderHole(false) } - chart!!.invalidate() + chart?.invalidate() } R.id.actionDrawCenter -> { chart!!.setDrawCenterText(!chart!!.isDrawCenterTextEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleXValues -> { chart!!.setDrawEntryLabels(!chart!!.isDrawEntryLabelsEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.actionTogglePercent -> { chart!!.setUsePercentValues(!chart!!.isUsePercentValuesEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.animateX -> { diff --git a/app/src/main/kotlin/info/appdev/chartexample/PiePolylineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/PiePolylineChartActivity.kt index a850c6ea6..9d4bb5949 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/PiePolylineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/PiePolylineChartActivity.kt @@ -154,7 +154,7 @@ class PiePolylineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVal // undo all highlights chart!!.highlightValues(null) - chart!!.invalidate() + chart?.invalidate() } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -174,19 +174,19 @@ class PiePolylineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVal chart!!.data!!.dataSets.forEach { it?.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHole -> { chart!!.isDrawHoleEnabled = !chart!!.isDrawHoleEnabled - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleMinAngles -> { if (chart!!.minAngleForSlices == 0f) chart!!.setMinAngleForSlices(36f) else chart!!.setMinAngleForSlices(0f) - chart!!.notifyDataSetChanged() - chart!!.invalidate() + chart?.notifyDataSetChanged() + chart?.invalidate() } R.id.actionToggleCurvedSlices -> { @@ -198,22 +198,22 @@ class PiePolylineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartVal if (toSet && chart!!.isDrawSlicesUnderHoleEnabled) { chart!!.setDrawSlicesUnderHole(false) } - chart!!.invalidate() + chart?.invalidate() } R.id.actionDrawCenter -> { chart!!.setDrawCenterText(!chart!!.isDrawCenterTextEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleXValues -> { chart!!.setDrawEntryLabels(!chart!!.isDrawEntryLabelsEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.actionTogglePercent -> { chart!!.setUsePercentValues(!chart!!.isUsePercentValuesEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.animateX -> { diff --git a/app/src/main/kotlin/info/appdev/chartexample/RadarChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/RadarChartActivity.kt index eccadb908..d72faf595 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/RadarChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/RadarChartActivity.kt @@ -139,7 +139,7 @@ class RadarChartActivity : DemoBase() { colorList.add(Color.rgb(240, 255, 240)) colorList.add(Color.rgb(250, 255, 250)) chart!!.setLayerColorList(colorList) - chart!!.invalidate() + chart?.invalidate() } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -160,44 +160,44 @@ class RadarChartActivity : DemoBase() { it?.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlight -> { if (chart!!.data != null) { chart!!.data!!.isHighlightEnabled = !chart!!.data!!.isHighlightEnabled() - chart!!.invalidate() + chart?.invalidate() } } R.id.actionToggleRotate -> { chart!!.isRotationEnabled = !chart!!.isRotationEnabled - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleFilled -> { chart!!.data!!.dataSets.forEach { set -> set?.setDrawFilled(!set.isDrawFilledEnabled) } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlightCircle -> { chart!!.data!!.dataSets.forEach { set -> set.isDrawHighlightCircleEnabled = !set.isDrawHighlightCircleEnabled } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleXLabels -> { chart!!.xAxis.isEnabled = !chart!!.xAxis.isEnabled - chart!!.notifyDataSetChanged() - chart!!.invalidate() + chart?.notifyDataSetChanged() + chart?.invalidate() } R.id.actionToggleYLabels -> { chart!!.yAxis.isEnabled = !chart!!.yAxis.isEnabled - chart!!.invalidate() + chart?.invalidate() } R.id.animateX -> { diff --git a/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt index fa6435822..37ab52739 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/RealtimeLineChartActivity.kt @@ -100,7 +100,7 @@ class RealtimeLineChartActivity : DemoBase(), OnChartValueSelectedListener { data.notifyDataChanged() // let the chart know it's data has changed - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() // limit the number of visible entries chart!!.setVisibleXRangeMaximum(120f) diff --git a/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt index 9641236e1..74f06d356 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/ScatterChartActivity.kt @@ -133,7 +133,7 @@ class ScatterChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSe data.setValueTypeface(tfLight) chart!!.setData(data) - chart!!.invalidate() + chart?.invalidate() } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -153,25 +153,25 @@ class ScatterChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSe chart!!.data!!.dataSets.forEach { set -> set?.isDrawValues = !set.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlight -> { if (chart!!.data != null) { chart!!.data!!.isHighlightEnabled = !chart!!.data!!.isHighlightEnabled() - chart!!.invalidate() + chart?.invalidate() } } R.id.actionTogglePinch -> { chart!!.setPinchZoom(!chart!!.isPinchZoomEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleAutoScaleMinMax -> { chart!!.isAutoScaleMinMaxEnabled = !chart!!.isAutoScaleMinMaxEnabled - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } R.id.animateX -> { diff --git a/app/src/main/kotlin/info/appdev/chartexample/ScrollViewActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/ScrollViewActivity.kt index 1c51ba1c5..dfde6c005 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/ScrollViewActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/ScrollViewActivity.kt @@ -59,7 +59,7 @@ class ScrollViewActivity : DemoBase() { val data = BarData(set) chart!!.setData(data) - chart!!.invalidate() + chart?.invalidate() chart!!.animateY(800) } diff --git a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt index fa05b1968..430a952aa 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivity.kt @@ -125,7 +125,7 @@ class StackedBarActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSele set1 = chart!!.data!!.getDataSetByIndex(0) as BarDataSet set1.entries = values chart!!.data!!.notifyDataChanged() - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } else { set1 = BarDataSet(values, "Statistics Vienna 2014") set1.isDrawIcons = false @@ -143,7 +143,7 @@ class StackedBarActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSele } chart!!.setFitBars(true) - chart!!.invalidate() + chart?.invalidate() } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -163,38 +163,38 @@ class StackedBarActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSele chart!!.data!!.dataSets.forEach { it?.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleIcons -> { chart!!.data!!.dataSets.forEach { set -> set?.isDrawIcons = !set.isDrawIcons } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlight -> { if (chart!!.data != null) { chart!!.data!!.isHighlightEnabled = !chart!!.data!!.isHighlightEnabled() - chart!!.invalidate() + chart?.invalidate() } } R.id.actionTogglePinch -> { chart!!.setPinchZoom(!chart!!.isPinchZoomEnabled) - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleAutoScaleMinMax -> { chart!!.isAutoScaleMinMaxEnabled = !chart!!.isAutoScaleMinMaxEnabled - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } R.id.actionToggleBarBorders -> { for (set in chart!!.data!!.dataSets) (set as BarDataSet).barBorderWidth = if (set.barBorderWidth == 1f) 0f else 1f - chart!!.invalidate() + chart?.invalidate() } R.id.animateX -> { diff --git a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt index baf8dd1a0..e3d1d74b5 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt @@ -110,7 +110,7 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { val data = BarData(set) data.barWidth = 8.5f chart!!.setData(data) - chart!!.invalidate() + chart?.invalidate() } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -131,7 +131,7 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { chart!!.data!!.dataSets.forEach { it?.isDrawValues = !it.isDrawValues } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleIcons -> { @@ -139,13 +139,13 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { set?.isDrawIcons = !set.isDrawIcons } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleHighlight -> { if (chart!!.data != null) { chart!!.data!!.isHighlightEnabled = !chart!!.data!!.isHighlightEnabled() - chart!!.invalidate() + chart?.invalidate() } } @@ -156,12 +156,12 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { chart!!.setPinchZoom(true) } - chart!!.invalidate() + chart?.invalidate() } R.id.actionToggleAutoScaleMinMax -> { chart!!.isAutoScaleMinMaxEnabled = !chart!!.isAutoScaleMinMaxEnabled - chart!!.notifyDataSetChanged() + chart?.notifyDataSetChanged() } R.id.actionToggleBarBorders -> { @@ -169,7 +169,7 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { (set as BarDataSet).barBorderWidth = if (set.barBorderWidth == 1f) 0f else 1f } - chart!!.invalidate() + chart?.invalidate() } R.id.animateX -> { diff --git a/app/src/main/kotlin/info/appdev/chartexample/listviewitems/PieChartItem.kt b/app/src/main/kotlin/info/appdev/chartexample/listviewitems/PieChartItem.kt index 3a8fad1fd..2475f049e 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/listviewitems/PieChartItem.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/listviewitems/PieChartItem.kt @@ -64,17 +64,18 @@ class PieChartItem(cd: ChartData<*>, c: Context) : ChartItem(cd) { // set data holder.chart!!.setData(chartData as PieData?) - val l = holder.chart!!.legend - l.verticalAlignment = Legend.LegendVerticalAlignment.TOP - l.horizontalAlignment = Legend.LegendHorizontalAlignment.RIGHT - l.orientation = Legend.LegendOrientation.VERTICAL - l.setDrawInside(false) - l.yEntrySpace = 0f - l.yOffset = 0f + holder.chart?.legend?.apply { + verticalAlignment = Legend.LegendVerticalAlignment.TOP + horizontalAlignment = Legend.LegendHorizontalAlignment.RIGHT + orientation = Legend.LegendOrientation.VERTICAL + setDrawInside(false) + yEntrySpace = 0f + yOffset = 0f + } // do not forget to refresh the chart // holder.chart.invalidate(); - holder.chart!!.animateY(900) + holder.chart?.animateY(900) return convertView }