Guest User

Untitled

a guest
Jan 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. class MyChart(chart: LineChart?, val data: MyData) {
  2. private val startValue = data.start.toEpochSecond(ZoneOffset.UTC)
  3. init {
  4. chart?.run {
  5. setScaleEnabled(false)
  6. legend.isEnabled = false
  7. description.isEnabled = false
  8.  
  9. axisRight.run {
  10. setDrawGridLines(true)
  11. setDrawLabels(false)
  12. axisMinimum = 0.1f // hide 0.0 values
  13. }
  14. axisLeft.run {
  15. setDrawGridLines(true)
  16. axisMinimum = 0.1f // hide 0.0 values
  17. }
  18.  
  19. setupXAxis(xAxis)
  20.  
  21. Log.e("MPTEST, startValue: ", startValue.toString())
  22.  
  23. val entries = ArrayList<Entry>()
  24. data.list?.forEachIndexed { _, data ->
  25. val timeInSeconds = data.time.toEpochSecond(ZoneOffset.UTC)
  26. val xIndex = (timeInSeconds - startValue).toFloat()
  27. Log.e("MPTEST, xIndex: ", xIndex.toString())
  28.  
  29. entries.add(Entry(xIndex, data.value))
  30. }
  31.  
  32. val data = LineData(LineDataSet(entries, ""))
  33. setData(data)
  34.  
  35. invalidate()
  36. }}
  37.  
  38. private fun setupXAxis(xAxis: XAxis?) {
  39. xAxis?.run {
  40. position = XAxis.XAxisPosition.BOTTOM
  41.  
  42. val startInSeconds = data.start.toEpochSecond(ZoneOffset.UTC)
  43. axisMinimum = (startInSeconds - startValue).toFloat()
  44. Log.e("MPTEST, axisMinimum: ", axisMinimum.toString())
  45.  
  46. val endInSeconds = data.end.toEpochSecond(ZoneOffset.UTC)
  47. axisMaximum = (endInSeconds - startValue).toFloat()
  48. Log.e("MPTEST, axisMaximum: ", axisMaximum.toString())
  49.  
  50. setCenterAxisLabels(true)
  51. setDrawGridLines(false)
  52.  
  53. // I need to fix something here I think
  54. setLabelCount(7, true)
  55. valueFormatter = IndexAxisValueFormatter(data.labels)
  56. }
  57. } }
  58.  
  59. E/MPTEST, axisMinimum:: 0.0
  60. E/MPTEST, axisMaximum:: 604799.0
  61. E/MPTEST, startValue:: 1546732800
  62. E/MPTEST, xIndex:: 366180.0
  63. E/MPTEST, xIndex:: 467893.0
Add Comment
Please, Sign In to add comment