Closed maffbm closed 5 years ago
val graph = view.findViewById(R.id.graph) as GraphView
graph.title = "title"
graph.titleTextSize = 55f
graph.titleColor = ContextCompat.getColor(context!!,R.color.colorPrimary)
val series = LineGraphSeries<DataPoint>(
arrayOf(
DataPoint(0.toDouble(), 9.toDouble()),
DataPoint(10.toDouble(), 5.toDouble()),
DataPoint(20.toDouble(), 8.toDouble()),
DataPoint(30.toDouble(), 9.toDouble())
)
)
series.color = ContextCompat.getColor(context!!, R.color.colorPrimary)
series.isDrawDataPoints = true
series.thickness = 10
series.dataPointsRadius = 5f
var renderer = graph.gridLabelRenderer
graph.gridLabelRenderer.labelFormatter = object : DefaultLabelFormatter() {
override fun formatLabel(value: Double, isValueX: Boolean): String {
if (isValueX) {
val v = value.toLong()
val date = Date(v)
var label: String? = null
label = DateFormat.format("MM.dd", date).toString()
return label
}else{
return super.formatLabel(value, isValueX)
}
}
}
graph.addSeries(series)
thank you very much!
I've just started writing Android apps, so I'm very new, but my latest project requires 3 graphs, but I'm learning Kotlin, not Java, and all the examples and tutorials online for GraphView are using Java, can anyone show me the HelloWorld Graph example in Kotlin so I can go from there?
Thanks