2

I'm trying to make a graph view with jjoe64's GraphView library with dates on the x-axis and numbers on the y-axis, but I'm getting some troubles...

  1. DataPoint wants Date or Double as input. The documentation says it automatically casts Dates do Doubles via Date#getTime(), but Date#getTime() (in Java) outputs Long. So I have to manually cast Long to Double for DataPoint...

  2. I set the number of horizontal labels to 3 and set MinX and MaxX, but only the first date get's displayed. Why don't get the other 2 dates get displayed?

  3. As soon as I set the HumanRounding to false as written in the documentation my app freezes until it get's terminated. Why is that happening?

  4. When I don't set xAxisBoundsManual to true there get displayed 3 dates, but the first one is a date that I have never set and the graph starts only at the second label and ends to early (it doesn't reach the last value, the whole graph is moved to much to the right instead of starting at 0). Where does that come from? (Screenshot)

Code:

val calendar: Calendar = Calendar.getInstance()
    val d1 = calendar.time.time.toDouble()
    calendar.add(Calendar.DATE, 1)
    val d2 = calendar.time.time.toDouble()
    calendar.add(Calendar.DATE, 1)
    val d3 = calendar.time.time.toDouble()
    calendar.add(Calendar.DATE, 1)
    val d4 = calendar.time.time.toDouble()
    calendar.add(Calendar.DATE, 1)
    val d5 = calendar.time.time.toDouble()

val series: LineGraphSeries<DataPoint> = LineGraphSeries(arrayOf(
        DataPoint(d1, 0.0),
        DataPoint(d2, 5.0),
        DataPoint(d3, 3.0),
        DataPoint(d4, 7.0),
        DataPoint(d5, 0.0)))

graph.addSeries(series)

graph.gridLabelRenderer.labelFormatter = DateAsXAxisLabelFormatter(this)
graph.gridLabelRenderer.numHorizontalLabels = 3
graph.viewport.setMinX(d1)
graph.viewport.setMaxX(d5)
graph.viewport.isXAxisBoundsManual = true
graph.gridLabelRenderer.isHumanRounding = false

Screenshot of the graph with xAxxisBoundsManial (false): screenshot:
screenshot

Zoe
  • 27,060
  • 21
  • 118
  • 148
Jannik
  • 43
  • 4

0 Answers0