PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.61k stars 9.02k forks source link

Bar height  not consitent with y value #4902

Open momo1986 opened 4 years ago

momo1986 commented 4 years ago

Hello, @PhilJay Hello, Philipp.

Thanks a lot for the sharing.

I used your framework of bar-chart to show my data query call-back result.

The data is between 0 and 1. It will be changed and refreshed in different Android thread, however, the bar height will only be changed when the data-change is detected.

My phenomenon is this.

If previous received data is 0.0, next data will only be showed in y-axis with the value 0 or 1. If the received data is smaller than 0.5, then the y-axis label is 0, if the received data is larger than 0.5, the y-axis label is 1.

Looks below example, the received data is 0.65, the bar height changed correctly while the y-axis label is showed in 1. Previous result is 0 and bar height is also 0. image

My code look like this. It is in Kotlin, but logic is similar with Java:

First, I declare and allocate a mutable list: private val wrapEntries: MutableList<BarEntry> = ArrayList()

Second, init the corresponding bar data set, it is only one diemsion:

     initXAxis(wrapFingerChart, false)
        for (i in 0..0) {
            wrapEntries.add(BarEntry(i.toFloat(), 0.000f))
        }
        val wrapSet = BarDataSet(wrapEntries, "折指")
        wrapSet.color = Color.YELLOW
        val wrapData = BarData(wrapSet)
        wrapFingerChart!!.data = wrapData

Third, the data will be refreshed, and has problem if previous value is 0.0:

for (i in wrapFingerProbabilities.indices - 1) {
                    val entry = wrapEntries[i]
                    val yValues:FloatArray = FloatArray(1)
                    yValues[0] = wrapFingerProbabilities[i + 1].toFloat()
                    entry.y = String.format("%.3f",wrapFingerProbabilities[i+1]).toFloat()
                    entry.setVals(yValues)

                }
                val wrapData = BarData(wrapSet)
                wrapFingerChart!!.data = wrapData
                wrapFingerChart!!.notifyDataSetChanged()
                wrapFingerChart!!.invalidate()

How can I resolve this problem?

It is my honor if there would be response.

Thanks & Regards! Momo

momo1986 commented 4 years ago

@PhilJay

Could you comment on this?

Thanks & Regards!