-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fill animation and PieChart instance
- Loading branch information
1 parent
02e2580
commit e756245
Showing
4 changed files
with
161 additions
and
81 deletions.
There are no files selected for viewing
47 changes: 29 additions & 18 deletions
47
app/src/main/java/com/faskn/clickablepiechart/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,49 @@ | ||
package com.faskn.clickablepiechart | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.faskn.lib.PieChart | ||
import com.faskn.lib.Slice | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
import kotlin.random.Random | ||
|
||
class MainActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
chart.setCenterColor(R.color.white) | ||
/* chart.setStartPoint(-90f)*/ | ||
chart.setSliceWidth(250f) | ||
chart.setListener { data, index -> | ||
/* Toast.makeText(this, index.toString(), Toast.LENGTH_SHORT).show()*/ | ||
} | ||
|
||
// Example | ||
var pieChart = PieChart.Builder(arrayOf( | ||
Slice(30f, R.color.brown700), | ||
Slice(60f, R.color.materialRed700), | ||
Slice(120f, R.color.materialIndigo600), | ||
Slice(150f, R.color.materialRed400) | ||
)) | ||
val pieChart0 = PieChart.Builder( | ||
arrayOf( | ||
Slice(30f, R.color.brown700), | ||
Slice(60f, R.color.materialRed700), | ||
Slice(120f, R.color.materialIndigo600), | ||
Slice(150f, R.color.materialRed400) | ||
) | ||
) | ||
.setClickListener { string, float -> | ||
Log.d("ses", "s " + string) | ||
Log.d("ses", "f " + float.toString()) | ||
} | ||
.build() | ||
|
||
chart.setSliceColor( | ||
intArrayOf( | ||
R.color.brown700, | ||
R.color.materialRed700, | ||
R.color.materialIndigo600, | ||
R.color.materialRed400 | ||
// Example 2 | ||
val pieChart1 = PieChart.Builder( | ||
arrayOf( | ||
Slice(Random.nextInt(0, 100).toFloat(), R.color.brown700), | ||
Slice(Random.nextInt(0, 100).toFloat(), R.color.materialRed700), | ||
Slice(Random.nextInt(0, 100).toFloat(), R.color.materialIndigo600), | ||
Slice(Random.nextInt(0, 100).toFloat(), R.color.materialRed400) | ||
) | ||
) | ||
chart.setDataPoints(floatArrayOf(30f, 60f, 120f, 150f)) | ||
.setClickListener { string, float -> | ||
Log.d("ses", "s " + string) | ||
Log.d("ses", "f " + float.toString()) | ||
} | ||
.build() | ||
|
||
chart.setPieChart(pieChart0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.