Skip to content

Instantly share code, notes, and snippets.

@CMyae
Last active September 18, 2019 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMyae/d625405d4225c3feda004ba8429988ee to your computer and use it in GitHub Desktop.
Save CMyae/d625405d4225c3feda004ba8429988ee to your computer and use it in GitHub Desktop.
Code snippet for calculating data points for bezier curve
//Sample Data points -> 50,25,100,80,...(your data to be represented in graph)
private fun calculatePointsForData() {
val bottomY = getLargeBarHeight() - CURVE_BOTTOM_MARGIN
val xDiff = width.toFloat() / data.size
val maxData = data.maxBy { it.amount }!!.amount
for (i in 0 until data.size) {
val y = bottomY - (data[i].amount / maxData * bottomY)
points.add(PointF(xDiff * i, y))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment