-
Notifications
You must be signed in to change notification settings - Fork 369
Getting started
ArsenyMalkov edited this page Jul 28, 2023
·
12 revisions
You should have already set up the latest Android Studio.
Create a new project and select appropriate API level (AnyChart library for Android compatible with API 19+).
|
|
Add an empty Activity and put in layout and Activity name.
|
|
Add the repository to the project build.gradle at the end of repositories (WARNING: Make sure you add it under allprojects, not under the buildscript).
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Then add the dependency to the module build.gradle and synchronize project with Gradle.
dependencies {
implementation 'com.github.AnyChart:AnyChart-Android:1.1.5'
}
|
|
Add AnyChart view to the Activity layout.
<com.anychart.AnyChartView
android:id="@+id/any_chart_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
|
Add Java code to the Activity. For example, if you want to create pie chart:
Pie pie = AnyChart.pie();
List<DataEntry> data = new ArrayList<>();
data.add(new ValueDataEntry("John", 10000));
data.add(new ValueDataEntry("Jake", 12000));
data.add(new ValueDataEntry("Peter", 18000));
pie.data(data);
AnyChartView anyChartView = (AnyChartView) findViewById(R.id.any_chart_view);
anyChartView.setChart(pie);
|
Make sure you have these package imports at the top of your Activity file.
import com.anychart.AnyChart;
import com.anychart.AnyChartView;
import com.anychart.DataEntry;
import com.anychart.Pie;
import com.anychart.ValueDataEntry;
import java.util.ArrayList;
import java.util.List;
Build and run your app.
|
|