Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static label only in y-axis #40

Open
joseRelvasF3m opened this issue Feb 18, 2019 · 0 comments
Open

Static label only in y-axis #40

joseRelvasF3m opened this issue Feb 18, 2019 · 0 comments

Comments

@joseRelvasF3m
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant