Search code examples
androidandroid-studiographlinechartrealm-list

Is there a way to pass list of date from realm to graph chart axis?


I have been trying to add the date to my X-axis in my chart but changing the value of time into millisecond and then parsing to float type affects its precision eg: 43578934 it will be rounded to 4357999. Is there a way to solve this problem?

    val list = ArrayList<Entry>()
    var count = 0f
    for (item: Data in listData) {
        if (item.createdAt != null && item.pulse != null) {
            val milliSecond = item.createdAt!!.time
            val x = ((((milliSecond/1000)/60)/60)/24).toString()
            Log.d("TAG", "getGraphList: $x")
            val y = item.pulse!!.toFloat()
            val entry = Entry(x.toFloat(), y)
            list.add(entry)
        }
    }
    return list

Solution

  • I figured out a way through which we can pass float value, and we don't have to worry about auto rounding of the value and we can get the precise value of the current date.

    In order to do that we need to create our own date class where we can calculate the date using the method shown.

    It is a temporary fix but I am working on the code to be able to cover all