val thelinechart = findViewById(R.id.lineChart) as LineChart
thelinechart.setOnClickListener {
thelinechart.viewTreeObserver.addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
override fun onGlobalLayout() {
thelinechart.viewTreeObserver.removeOnGlobalLayoutListener(this)
val b = Bitmap.createBitmap(
thelinechart.measuredWidth,
thelinechart.measuredHeight+57,
Bitmap.Config.RGB_565
)
val c = Canvas(b)
val backgroundColor = Color.argb(255, 200, 220, 255)
c.drawColor(backgroundColor)
val paint = Paint()
paint.color = Color.BLACK
paint.textSize = 19f
paint.setTextAlign(Paint.Align.CENTER)
val typeface = Typeface.DEFAULT_BOLD
paint.typeface = typeface
val current = Date()
c.drawText("Florida Transit - Trend Chart - $current",
(c.width/2).toFloat(), 25f, paint)
thelinechart.layout(thelinechart.left, thelinechart.top, thelinechart.right, thelinechart.bottom)
thelinechart.draw(c)
val filename = "thegraph.png"
val sd: String = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).toString()
val dest = File(sd, filename)
try {
val out = FileOutputStream(dest)
b.compress(Bitmap.CompressFormat.PNG, 90, out)
out.flush()
out.close()
} catch (e: Exception) {
e.printStackTrace()
}
}
})
}

РЕДАКТИРОВАТЬ: Вот R.id.lineChart
Подробнее здесь: https://stackoverflow.com/questions/793 ... -in-kotlin