GraphView-Demos icon indicating copy to clipboard operation
GraphView-Demos copied to clipboard

Static label only in y-axis

Open joseRelvasF3m opened this issue 7 years ago • 0 comments

When I put static labels only in the y-axis, happens this: image

Well, I just want the date, and what seems to happen is that it puts the two values on the same axis (x-axis). Here's my code: ` class MainActivity : AppCompatActivity() {

private var mNumLabels: Int = 4

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    val graph = findViewById<GraphView>(R.id.graph)
    initGraph(graph)
}

fun initGraph(graph: GraphView) {
    // generate Dates
    val calendar = Calendar.getInstance()
    val d1 = calendar.time
    calendar.add(Calendar.DATE, 1)
    val d2 = calendar.time
    calendar.add(Calendar.DATE, 1)
    val d3 = calendar.time

    // you can directly pass Date objects to DataPoint-Constructor
    // this will convert the Date to double via Date#getTime()
    val series = LineGraphSeries(arrayOf<DataPoint>(DataPoint(d1, 2.0), DataPoint(d2, 5.0), DataPoint(d3, 3.0)))
    graph.addSeries(series)


    series.isDrawDataPoints = true
    series.isDrawBackground = true
    // set date label formatter
    graph.gridLabelRenderer.labelFormatter = DateAsXAxisLabelFormatter(graph.context)
    graph.gridLabelRenderer.numHorizontalLabels = mNumLabels


    // second series
    val series2 = LineGraphSeries(
        arrayOf(
            DataPoint(d1, 3.0),
            DataPoint(d2, 3.0),
            DataPoint(d3, 6.0)
        )
    )
    series2.title = "speed"
    series2.isDrawBackground = true
    series2.color = Color.argb(255, 255, 60, 60)
    series2.backgroundColor = Color.argb(100, 204, 119, 119)
    series2.isDrawDataPoints = true
    graph.addSeries(series2)

    // second series
    val series3 = LineGraphSeries(
        arrayOf(
            DataPoint(d1, 3.0),
            DataPoint(d3, 2.0)
        )
    )

    series2.title = "HEY"
    series2.isDrawBackground = true
    series2.color = Color.argb(255, 255, 60, 60)
    series2.backgroundColor = Color.argb(100, 204, 119, 119)
    series2.isDrawDataPoints = true
    graph.addSeries(series3)

    // legend
    graph.legendRenderer.isVisible = true
    graph.legendRenderer.align = LegendRenderer.LegendAlign.BOTTOM

    // set manual x bounds to have nice steps
    graph.viewport.setMinX(d1.time.toDouble())
    graph.viewport.setMaxX(d3.time.toDouble())
    graph.viewport.isXAxisBoundsManual = false

    graph.gridLabelRenderer.setHumanRounding(false)

    val staticLabelsFormatter = StaticLabelsFormatter(graph)
    staticLabelsFormatter.setVerticalLabels(arrayOf("low", "hey", "high", "wei", "wai"))
    graph.gridLabelRenderer.labelFormatter = staticLabelsFormatter
}

}

`

When I take this: val staticLabelsFormatter = StaticLabelsFormatter(graph) staticLabelsFormatter.setVerticalLabels(arrayOf("low", "hey", "high", "wei", "wai")) graph.gridLabelRenderer.labelFormatter = staticLabelsFormatter Everything works fine... but then I can't use static labels. Can you help me?

joseRelvasF3m avatar Feb 18 '19 15:02 joseRelvasF3m