원 그래프 만들기 (MpAndroidChart) :: 안드로이드 설치 및 개발[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

안드로이드 설치 및 개발
[1]
등록일:2018-10-15 17:38:50 (0%)
작성자:
제목:원 그래프 만들기 (MpAndroidChart)

개발도중 차트를 만들일이 있어 쉽게 만드는 방법을 알아보다가 재미있는 라이브러리를 발견하였습니다. 바로 MpAndroidChart이라는 라이브러리인데요 이 라이브러리를 사용하면 차트를 굉장히 쉽게 만들 수 있습니다. 이번 포스팅에서는 MpAndroidChart를 이용하여 원그래프(PieChart)를 만드는 방법에 대해 알아보겠습니다.



안드로이드 원 그래프 만들기


build.gradle

repositories{
    maven {url "https://jitpack.io"}
}
dependencies {
    compile 'com.github.PhilJay:MpAndroidChart:v3.0.2'
}

라이브러리 사용을 위해 build.gradle에서 아래에 있는 두줄을 추가해주도록 하겠습니다.


XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context="org.androidtown.graph.MainActivity">

    <com.github.mikephil.charting.charts.PieChart
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/piechart">

    </com.github.mikephil.charting.charts.PieChart>

</RelativeLayout>

Java

public class MainActivity extends AppCompatActivity {

    PieChart pieChart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        pieChart = (PieChart)findViewById(R.id.piechart);

        pieChart.setUsePercentValues(true);
        pieChart.getDescription().setEnabled(false);
        pieChart.setExtraOffsets(5,10,5,5);

        pieChart.setDragDecelerationFrictionCoef(0.95f);

        pieChart.setDrawHoleEnabled(false);
        pieChart.setHoleColor(Color.WHITE);
        pieChart.setTransparentCircleRadius(61f);

        ArrayList<PieEntry> yValues = new ArrayList<PieEntry>();

        yValues.add(new PieEntry(34f,"Japen"));
        yValues.add(new PieEntry(23f,"USA"));
        yValues.add(new PieEntry(14f,"UK"));
        yValues.add(new PieEntry(35f,"India"));
        yValues.add(new PieEntry(40f,"Russia"));
        yValues.add(new PieEntry(40f,"Korea"));

        Description description = new Description();
        description.setText("세계 국가"); //라벨
        description.setTextSize(15);
        pieChart.setDescription(description);

        pieChart.animateY(1000, Easing.EasingOption.EaseInOutCubic); //애니메이션

        PieDataSet dataSet = new PieDataSet(yValues,"Countries");
        dataSet.setSliceSpace(3f);
        dataSet.setSelectionShift(5f);
        dataSet.setColors(ColorTemplate.JOYFUL_COLORS);

        PieData data = new PieData((dataSet));
        data.setValueTextSize(10f);
        data.setValueTextColor(Color.YELLOW);

        pieChart.setData(data);

    }
}


메서드 참고 URL



완성본

MpAndroidChart



[Android] 꺽은선 그래프 만들기 (MpAndroidChart)

[본문링크] 원 그래프 만들기 (MpAndroidChart)
[1]
코멘트(이글의 트랙백 주소:/cafe/tb_receive.php?no=34872
작성자
비밀번호

 

SSISOCommunity

[이전]

Copyright byCopyright ⓒ2005, SSISO Community All Rights Reserved.