Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 39 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[![](https://jitpack.io/v/furkanaskin/ClickablePieChart.svg)](https://jitpack.io/#furkanaskin/ClickablePieChart)
[![](https://jitpack.io/v/gsotti/ClickablePieChart.svg)](https://jitpack.io/#gsotti/ClickablePieChart)

# ClickablePieChart
Android Pie Chart library, supported with **Kotlin DSL**.
Android Chart library, supported with **Kotlin DSL**.

<img height="500" src="https://user-images.githubusercontent.com/22769589/93264550-f467c400-f7af-11ea-8d76-78fb0163fd04.jpg" alt="PieChart"/>
<img height="500" src="/assets/device-2020-11-12-104411.png" alt="PieChart"/>

## Installation
Step 1. Add the JitPack repository to your build file
Expand All @@ -18,7 +18,7 @@ allprojects {
Step 2. Add the dependency
```gradle
dependencies {
implementation 'com.github.furkanaskin:ClickablePieChart:1.0.7'
implementation 'com.github.gsotti:ClickablePieChart:1.0.13'
}
```

Expand All @@ -31,6 +31,17 @@ dependencies {

chart.setPieChart(pieChart)
```

Or create a BarChart

```kotlin
val barChart = BarChart(
slices = provideSlices(), clickListener = null
).build()

chart.setBarChart(barChart)
```

Also you can use **Kotlin DSL** for building your chart.
```kotlin
val pieChartDSL = buildChart {
Expand All @@ -43,6 +54,20 @@ Also you can use **Kotlin DSL** for building your chart.
}
chart.setPieChart(pieChartDSL)
```

Or create a BarChart

```kotlin
val barChartDSL = buildBarChart {
slices { provideSlices() }
clickListener { percentage, index ->
// ...
}
}
chart.setBarChart(barChartDSL)
```


To setup with legend you need an root layout for legend.
```kotlin
chart.showLegend(legendLayout)
Expand All @@ -52,6 +77,11 @@ Or use with custom legend adapter by inheriting from LegendAdapter
chart.showLegend(legendLayout, CustomLegendAdapter())
```

Or if you use a barChart you can also change the orientation of the legendAdapter
```kotlin
chart4.showLegend(rootLayout = legendLayout, orientation = LinearLayoutManager.HORIZONTAL or LinearLayoutManager.VERTICAL)
```

## XML Attributes
<table>
<thead>
Expand Down Expand Up @@ -87,5 +117,10 @@ chart.showLegend(legendLayout, CustomLegendAdapter())
<td>integer</td>
<td>Animation duration with milliseconds.</td>
</tr>
<tr>
<td>app:orientation</td>
<td>string</td>
<td>Orientation of BarChart (horizontal/vertical)</td>
</tr>
</tbody>
</table>
43 changes: 32 additions & 11 deletions app/src/main/java/com/faskn/clickablepiechart/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package com.faskn.clickablepiechart

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.faskn.lib.PieChart
import com.faskn.lib.Slice
import com.faskn.lib.buildChart
import androidx.recyclerview.widget.LinearLayoutManager
import com.faskn.lib.*
import kotlinx.android.synthetic.main.activity_main.*
import kotlin.random.Random


class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -17,7 +16,7 @@ class MainActivity : AppCompatActivity() {
val pieChartDSL = buildChart {
slices { provideSlices() }
sliceWidth { 80f }
sliceStartPoint { 0f }
sliceStartPoint { -90f }
clickListener { angle, index ->
// ...
}
Expand All @@ -34,29 +33,51 @@ class MainActivity : AppCompatActivity() {
chart.showLegend(legendLayout)

//OR SET WITH CUSTOMER LEGEND ADAPTER
chart2.setPieChart(pieChart)
chart2.showLegend(legendLayout2,CustomLegendAdapter())
//chart2.setPieChart(pieChart)
//chart2.showLegend(legendLayout2,CustomLegendAdapter())


val barChart = BarChart(
slices = provideSlices(), clickListener = null
).build()

val barChartDSL = buildBarChart {
slices { provideSlices() }
clickListener { percentage, index ->
// ...
}
}

chart3.setBarChart(barChart)
chart3.showLegend(legendLayout3)


chart4.setBarChart(barChartDSL)
chart4.showLegend(
rootLayout = legendLayout4,
layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
)
}

private fun provideSlices(): ArrayList<Slice> {
return arrayListOf(
Slice(
Random.nextInt(1000, 3000).toFloat(),
2F,
R.color.colorPrimary,
"Google"
),
Slice(
Random.nextInt(1000, 2000).toFloat(),
2F,
R.color.colorPrimaryDark,
"Facebook"
),
Slice(
Random.nextInt(1000, 5000).toFloat(),
1F,
R.color.materialIndigo600,
"Twitter"
),
Slice(
Random.nextInt(1000, 10000).toFloat(),
4F,
R.color.colorAccent,
"Other"
)
Expand Down
146 changes: 103 additions & 43 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,63 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2"
tools:context=".MainActivity">
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:layout_weight="1"
android:orientation="horizontal">
android:orientation="vertical"
tools:context=".MainActivity">

<com.faskn.lib.ClickablePieChart
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:animationDuration="2000"
app:centerColor="@color/white"
app:popupText="Ziyaret"
app:showPercentage="true"
app:showPopup="true" />

<FrameLayout
android:id="@+id/legendLayout"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.5" />
</LinearLayout>
android:layout_margin="24dp"
android:weightSum="2"
android:orientation="horizontal">

<com.faskn.lib.ClickablePieChart
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1"
app:animationDuration="2000"
app:centerColor="@color/white"
app:popupText="Ziyaret"
app:showPopup="true" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
<FrameLayout
android:id="@+id/legendLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:weightSum="1"
android:orientation="horizontal">

<com.faskn.lib.ClickablePieChart
android:id="@+id/chart2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:animationDuration="2000"
app:centerColor="@color/white"
app:popupText="Ziyaret"
app:showPercentage="true"
app:showPopup="true" />

android:layout_weight="1"
android:orientation="horizontal">
<FrameLayout
android:id="@+id/legendLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>

<com.faskn.lib.ClickablePieChart
android:id="@+id/chart2"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:animationDuration="2000"
app:centerColor="@color/white"
app:popupText="Ziyaret"
app:showPercentage="true"
app:showPopup="true" />

<FrameLayout
android:id="@+id/legendLayout2"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:weightSum="2"
android:orientation="vertical">


<com.faskn.lib.ClickableBarChart
android:id="@+id/chart4"
android:layout_marginStart="5dp"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="1"
app:orientation="horizontal"
app:animationDuration="2000"
app:popupText="Ziyaret"
app:showPercentage="true"
app:showPopup="true" />

<FrameLayout
android:id="@+id/legendLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.5" />
android:layout_margin="24dp"
android:weightSum="2"
android:orientation="horizontal">

<com.faskn.lib.ClickableBarChart
android:id="@+id/chart3"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1"
app:animationDuration="2000"
app:popupText="Ziyaret"
app:showPercentage="true"
app:showPopup="true" />

<FrameLayout
android:id="@+id/legendLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />

</LinearLayout>



</LinearLayout>

</LinearLayout>
</ScrollView>
Binary file added assets/device-2020-11-12-104411.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading