MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

Does this library has built-in support to plot graph for days, weeks, months and years break down of input data.

Open pradeep-orbi opened this issue 2 years ago • 4 comments

Does this library has built-in support to plot graph for days, weeks, months and years break down of input data. Can we create graphs with daily, weekly, monthly and yearly tabs using this library ? I can't find graph with tabs in the demo app available in play store.

pradeep-orbi avatar May 29 '22 15:05 pradeep-orbi

No buildin support. But you can achieve it easily. Stackoverflow is your friend

mwiede avatar May 31 '22 18:05 mwiede

No buildin support. But you can achieve it easily. Stackoverflow is your friend

Could not find any references in stack overflow

pradeep-orbi avatar May 31 '22 19:05 pradeep-orbi

Not that there is answer on stackoverflow, but you can find how to plot by day/week/month/year, etc. For example

private val priceWeeks: ArrayList<String> = ArrayList()
private val weekFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd-yyyy")

inner class XFormatter : IAxisValueFormatter {
    override fun getFormattedValue(value: Float, axis: AxisBase?): String {
        val x = if(value.toInt() > 0) value.toInt() else 0
        return priceWeeks[x]
    }
}

...
for(n in 0..51){
    val wkDate = priceDate.plusDays((-7 * n).toLong())
    priceWeeks.add(0, wkDate.format(weekFormatter))    
}
...

Would make labels for the past year and display them on the X-Axis in ascending order. You can do similar to format the date by day, year, etc and display whatever number of values you need.

cmy82 avatar Jun 12 '22 17:06 cmy82

@cmy82, does the data need to be grouped up manually? Let's say I have one week data from sensor, which recorded the data every 1 minute (that is 10080 records). If I want to show hourly data, do I need to manually group up those those values to have a list of 24 values (corresponding to hours from 0 to 23)? Or this can be achieved in a better way using this library? Thanks.

cjacky475 avatar Jul 03 '22 17:07 cjacky475