mpaandroidchart 오픈 소스 차트 라이브러리 파이 차트
아이콘 오픈 소스 라이브러리 Mpaandroidchart를 소개하겠습니다. 안드로이드 장치에 다양한 통계 차트를 그릴 수있을뿐만 아니라 차트를 드래그하고 축소 할 수 있습니다. Mpandroidchart에는 라인 차트, 파이 차트, 막대 차트 및 산란 차트와 같은 공통 차트 유형이 있습니다.
mpandroidchartlibrary.jar 패키지 다운로드 주소 :
https://github.com/philjay/mpandroidchart/releases
다음은 주로 다음 파이 차트를 구현합니다.
1. 위의 주소에서 최신 mpandroidchartlibrary-2-0-8.jar 패키지를 다운로드하여 프로젝트의 Libs에 복사하십시오.
2. XML 파일을 정의합니다
3. 기본 Java 논리 코드는 다음과 같습니다.
importjava.util.arraylist; importcom.github.mikephil.charting.charts.piechart; importcom.github.mikephil.charting.components.legend; importcom.github.mikephil.charting.components.legend; importcom.github.mikephil.charting.data.entry; importcom.github.mikephil.charting.data.piedataset; indroid.support.v7.app.actionbaractivity import; importandroid.graphics.color; importandroid.os.bundle; importandroid.util.displaymetrics; 공개 클래스 Mainactivity는 ActionBaractivity {privatepiechartmchart; @override protected void onecreate (Bundle SavedInstancestate) {super.oncreate (savedinstancestate); setContentView (R.Layout.Activity_Main); MCHART = (PIECHART) FINDVIEWBYID (r.id.spread_pie_chart); piedatampiedata = getpiedata (4, 100); Showchart (McHart, Mpiedata); } private void showchart (piechartpiechart, piedatapiedata) {piechart.setholecolortransparent (true); Piechart.Setholeradius (60f); //radiuspiechart.settransparentCircleradius(64f); // 반투명 원 // piechart.setholeradius (0) // solid circle piechart.setdescription ( "테스트 프리 차트"); // mCHART.SETDAWYVALUES (true); piechart.setDrawCenterText (true); // 텍스트는 원형 차트 중간에 추가 할 수 있습니다. piechart.setrotationangle (90); // 초기 회전 각도 // 해당 설명 값을 슬라이스에 그립니다. // touch piechart.setRotationEnabled (true)로 차트 회전을 활성화합니다. // 수동으로 회전 할 수 있습니다 // 디스플레이 백분율 값 piechart.setUseperCentValues (true); // 디스플레이 백분율 // mCHART.SETUNIT ( "); // 디스플레이 백분율 // mCHART.SETUNIT ("); // mChart.setDrawUnitsinChart (true); // 선택 리스너 추가 // mCHART.SETONCHARTVALUESELECTERLISTERE (this); // mChart.setTouchEnabled (false); // mChart.setonAnimationListener (this); piechart.setCenterText ( "Quarterly Revenue"); // 파이 차트 중간에있는 텍스트 // 데이터 설정 piechart.setdata (piedata); // 모든 하이라이트를 취소 // piechart.highlightValues (null); // piechart.invalidate (); 전설 mlegend = piechart.getlegend (); // 스케일 그래프 설정 mlegend.SetPosition (LEGENDPOSITION.RIGHT_OF_CHART); // 가장 오른쪽에 표시 // mlegend.setform (relendform.line); // 스케일 그래프의 모양을 설정하면 기본값은 square mlegend.setxentryspace (7f)입니다. mlegend.setyentryspace (5f); piechart.animatexy (1000, 1000); // 애니메이션을 설정 // mCHART.spin (2000, 0, 360); } / ** * * @param count 여러 부분으로 나뉘어져 있습니다 * @param 범위 * / privatePiedatagetPiedata (int count, float 범위) {arraylist <string> xvalues = new arraylist <string> (); // xvals는 (inti = 0; i <count; i ++) {xvalues.add ( "Quarterly" + (i + 1))에 대한 각 파이의 내용을 나타내는 데 사용됩니다. // PIE의 디스플레이는 Quarterly1, Quarterly2, Quarterly3, Quarterly4} arraylist <entylist> yvalues = new ArrayList <ETCTER> ()입니다. // yvals는 각 파이 블록을 캡슐화하는 실제 데이터를 나타내는 데 사용됩니다. // 파이 차트 데이터/** * 파이 차트를 네 부분으로 나누고 네 부분의 숫자 비율은 14 : 14 : 34 : 38 *이므로 14로 표시되는 비율은 14% */float Quarterly1 = 14입니다. float Quarterly2 = 14; float Quarterly3 = 34; float Quarterly4 = 38; yvalues.add (새 항목 (Quarterly1, 0)); yvalues.add (새 항목 (Quarterly2, 1)); yvalues.add (새 항목 (Quarterly3, 2)); yvalues.add (새 항목 (Quarterly4, 3)); // y 축소 컬렉션 Piedatasetpiedataset = New Piedataset (yvalues, "Quarterly Revenue 2014"/*척도 차트*/); piedataset.setslicespace (0f); // PIE 차트 사이의 거리를 설정합니다. arraylist <integer> colors = new ArrayList <integer> (); // 파이 차트 색상 .add (color.rgb (205, 205, 205)); colors.add (color.rgb (114, 188, 223)); colors.add (color.rgb (255, 123, 124)); colors.add (color.rgb (57, 135, 200)); piedataset.setColors (색상); DisplayMetrics Metrics = getResources (). getDisplayMetrics (); floatpx = 5 * (metrics.densitydpi / 160f); piedataset.setSelectionshift (px); // 선택한 상태의 길이 piedatapiedata = new piedata (xvalues, piedataset); returnpiedata; }} 렌더링은 다음과 같습니다.
mpaandroidchart 오픈 소스 차트 라이브러리 라인 차트
1. Mandroidchartlibrary-2-0-8.jar 패키지를 프로젝트의 LIB에 복사하십시오
2. XML 파일을 정의합니다
3. 기본 Java 논리 코드는 다음과 같습니다.
packagecom.example.mpandroidlinechart; importjava.util.arraylist; importcom.github.mikephil.charting.charts.linechart; importcom.github.mikephil.charting.components.legend; importcom.github.mikephil.charting.components.legend; importcom.github.mikephil.charting.components.legendform; importcom.github.mikephil.charting.data.entry; importcom.github.mikephil.charting.data.linedataset; importcom.github.mikephil.charting.data.linedataset; indroid.support.v7.app.actionbaractivity import; importandroid.graphics.color; importandroid.os.bundle; 공개 클래스 Mainactivity는 ActionBaractivity {privatelinechartmlinechart; // 개인 서체 MTF; @override protected void onecreate (Bundle SavedInstancestate) {super.oncreate (savedinstancestate); setContentView (R.Layout.Activity_Main); mlinechart = (Linechart) findViewById (r.id.spread_line_chart); // mtf = saperface.createfromasset (getAssets (), "opensans-bold.ttf"); linedatamlinedata = getLineData (36, 100); showchart (mlinechart, mlinedata, color.rgb (114, 188, 223)); } // 디스플레이 스타일을 설정하여 개인 void showchart (LinechartLinechart, linedatalinedata, int color) {linechart.setDrawBorders (false); // 라인 차트에 경계를 추가 할 위치 // 설명 없음 텍스트 linechart.setDescription ( ""); // 데이터 설명 // 데이터가없는 경우 ListView emtpyViewLinechart.setNodatatextDescription과 유사하게 표시됩니다 ( "차트에 데이터를 제공해야합니다."); // 그리드 배경 활성화 / 비활성화 Linechart.setDrawGridbackground (false); // 테이블을 표시할지 여부 컬러 Linechart.setGridbackgroundColor (Color.white & 0x70fffff); // 테이블의 색상, 여기에 색상의 투명성을 설정하는 것입니다. // 터치 기어 활성화 Linechart.setTouchEnabled (true); // 터치 할 수 있는지 여부를 설정하십시오. // linechart.setdragenabled (true) 스케일링 및 드래그 활성화; // linechart.setscaleenabled (true)를 드래그 앤 드롭 할 수 있습니까? // 비활성화 된 경우 스케일을 할 수 있습니까? X- 및 y 축에서 스케일링을 수행 할 수 있습니다. // linechart.setbackgroundcolor (color); // 배경 설정 // 데이터 추가 linechart.setdata (linedata); // 데이터 설정 // 범례 가져 오기 (데이터를 설정 한 후에 만 가능) 범례 mlegend = linechart.getlegend (); // y // 범례 그룹의 값인 스케일 아이콘을 설정합니다 ... // mlegend.setPosition (LEGENDPOSITION.LEFT_OF_CHART); mlegend.setform (Legendform.circle); // style mlegend.setformsize (6f); // font mlegend.settextColor (color.white); // mlegend.settypeface (mtf); // font linechart.animatex (2500); // 애니메이션의 즉각적인 실행, x 축}/ *** 데이터 생성* @param count 차트에 얼마나 많은 좌표 지점이 있는지 @param 범위에 사용되는 조정 지점* @return*/ privatelinedatagetlinedata (int count, float 범위) {arraylist <strang> xvalues = new arraylist> (); for (inti = 0; i <count; i ++) {// x 축에 표시되는 데이터는 기본적으로 숫자 첨자가 xvalues.add ( ""+i)를 표시하는 데 사용됩니다. } // y axis data arraylist <ETCTE> yvalues = new ArrayList <ETCTER> (); for (inti = 0; i <count; i ++) {float value = (float) (math.random () * 범위)+3; yvalues.add (새 항목 (값, i)); } // 데이터 세트를 생성하고 유형을 만듭니다. // y 축 데이터 세트 linedatasetlinedataset = new linedataset (yvalues, "테스트 라인 차트" /*척도 차트* /); // mlinedataset.setfillalpha (110); // mlinedataset.setfillcolor (color.red); // 설정된 y 축을 사용하여 매개 변수 linedataset.setlinewidth (1.75f)를 설정합니다. // linewidth linedataset.setcirclesize (3f); // 원 크기를 표시하는 linedataset.setColor (color.white); // 색상 linedataset.setCircleColor (color.white)를 표시합니다. // 원의 색상 Linedataset.SethighlightColor (Color.white); // 강조 표시된 라인 arraylist의 색상 <Linedataset> linedatasets = new ArrayList <Linedataset> (); linedatasets.add (linedataset); // 데이터 세트 추가 // 데이터 세트로 데이터 객체 생성 LinedAnAnedata = new linedata (xvalues, linedatasets); returnlinedata; }} 렌더링은 다음과 같습니다.
mpaandroidchart 오픈 소스 차트 라이브러리 막대 차트
1. Mandroidchartlibrary-2-0-8.jar 패키지를 프로젝트의 LIB에 복사하십시오
2. XML 파일을 정의합니다
3. 기본 Java 논리 코드는 다음과 같습니다.
PackageCom.jackie.mpandoidbarchart; importjava.util.arraylist; importcom.github.mikephil.charting.charts.barchart; importcom.github.mikep hil.charting.charts.linechart; importcom.github.mikephil.charting.components.legend; importcom.github.mikephil.charting.components.legend 양식; importcom.github.mikephil.charting.components.xaxis; importcom.github.mikephil.charting.components.xaxis.xaxisposition; importcom.githu B.mikephil.charting.data.bardata; importcom.github.github.mikephil.charting.data.bardataset; importcom.github.mikephil.charting.data.barentry; import Android.support.v7.app.ActionBaractivity; importAndroid.graphics.color; importandroid.os.bundle; public class mainactivity 확장 actionbaractivity {privatebarchartmbarchart; privateBardatambardata; @Overrideprotected void onecreate (Bundle SavedInstancestate). {super.oncreate (savedinstancestate); setContentView (r.layout.Activity_Main); mbarchart = (Barchart) findViewById (r.id.spread_bar_chart); mbardata = getBardata (4, 100); showbarchart (mbarchart, mbardata);} private void showbarchart (barchartbarchart, bardatabardata) {barchart.setdrawborders (false); /// 라인 차트에 테두리를 추가 할 위치 barchart.setDescription ( ""); // 데이터 설명 // 데이터가 없으면 ListView의 EmallViewBarchArt.setNodatateXtDescription과 유사하게 표시됩니다 ( "차트에 데이터를 제공해야합니다."); Barchart.setDrawGridbackground (false); // 테이블을 표시할지 여부 컬러 Barchart.setGridbackgroundColor (Color.white & 0x70fffff); // 테이블의 색상, 여기에 색상 barchart.setTouchEnabled (true)의 투명성을 설정하는 것입니다. // barchart.setDragEnabled (true)를 설정합니다. // barchart.setscaleenabled (true) 여부; // barchart.setpinchzoom (false) 여부; // // barchart.setbackgroundcolor (); // 배경 설정 barchart.setDrawBarshadow (true); barchart.setdata (bardata); // 데이터 범례 설정 mlegend = barchart.getlegend (); // 스케일 세트 아이콘 mlegend.setform (legendform.circle); // style mlegend.setformsize (6f); // font mlegend.settextColor (color.black); // 색상 // x- 축 설정 // xaxisxaxis = barchart.getxaxis (); // xaxis.setposition (xaxisposition.bottom); barchart.animatex (2500); // 애니메이션, x- 축} privateBardatagetBardata (int count, float 범위) {arraylist <strange> xvalues = new arraylist <string> (); for (inti = 0; i <count; i ++) {xvalues.add ( "th" + (i + 1) + "Quarter";} arraylist <arraylist ArrayList <Barentry> (); for (inti = 0; i <count; i ++) {float value = (float) (math.random ()*범위 내에서 무작위 번호/*100*/)+3; yvalues.add (new Barentry (value, i)); } // y 축 바다 타사 바다 타타 세트의 데이터 세트 = new Bardataset (yvalues, "테스트 프리 차트"); bardataset.setColor (color.rgb (114, 188, 223)); arraylist <Bardataset> bardatasets = new ArrayList <Bardataset> (); bardatasets.add (bardataset); // 데이터 세트 추가 bardatabardata = new Bardata (xvalues, bardatasets); returnbardata;}} packagecom.jackie.mpandoidbarchart; importjava.util.arraylist; importcom.github.mikephil.charting.charts.barchart; importcom.github.mikephil.chart ing.charts.linechart; importcom.github.mikephil.charting.components.legend; importcom.github.mikephil.charting.components.legend; importcom.github.mikephil.charting.components. .legend.legendform; importcom.github.mikephil.charting.components.xaxis; importcom.github.mikephil.charting.components.xaxis.xaxisPosition; importco m.github.mikephil.charting.data.bardata; importcom.github.mikephil.charting.data.bardataset; importcom.github.mikephil.charting.data.barentry; import Android.support.v7.app.ActionBaractivity; importAndroid.graphics.color; importandroid.os.bundle; public class mainactivity 확장 actionbaractivity {privatebarchartmbarchart; privateBardatambardata; @Overrideprotected void onecreate (Bundle SavedInstancestate). {super.oncreate (savedinstancestate); setContentView (r.layout.Activity_Main); mbarchart = (Barchart) findViewById (r.id.spread_bar_chart); mbardata = getBardata (4, 100); showbarchart (mbarchart, mbardata);} private void showbarchart (barchartbarchart, bardatabardata) {barchart.setdrawborders (false); /// 라인 차트에 테두리를 추가 할 위치 barchart.setDescription ( ""); // 데이터 설명 // 데이터가 없으면 ListView의 EmallViewBarchArt.setNodatateXtDescription과 유사하게 표시됩니다 ( "차트에 데이터를 제공해야합니다."); Barchart.setDrawGridbackground (false); // 테이블을 표시할지 여부 컬러 Barchart.setGridbackgroundColor (Color.white & 0x70fffff); // 테이블의 색상, 여기에 색상 barchart.setTouchEnabled (true)의 투명성을 설정하는 것입니다. // barchart.setDragEnabled (true)를 설정합니다. // barchart.setscaleenabled (true) 여부; // barchart.setpinchzoom (false) 여부; // // barchart.setbackgroundcolor (); // 배경 설정 barchart.setDrawBarshadow (true); barchart.setdata (bardata); // 데이터 범례 설정 mlegend = barchart.getlegend (); // 스케일 세트 아이콘 mlegend.setform (legendform.circle); // style mlegend.setformsize (6f); // font mlegend.settextColor (color.black); // 색상 // x- 축 설정 // xaxisxaxis = barchart.getxaxis (); // xaxis.setposition (xaxisposition.bottom); barchart.animatex (2500); // 애니메이션, x- 축} privateBardatagetBardata (int count, float 범위) {arraylist <strange> xvalues = new arraylist <string> (); for (inti = 0; i <count; i ++) {xvalues.add ( "th" + (i + 1) + "Quarter";} arraylist <arraylist ArrayList <Barentry> (); for (inti = 0; i <count; i ++) {float value = (float) (math.random ()*범위 내에서 무작위 번호/*100*/)+3; yvalues.add (new Barentry (value, i)); } // y 축 바다 타사 바다 타타 세트의 데이터 세트 = new Bardataset (yvalues, "테스트 프리 차트"); bardataset.setColor (color.rgb (114, 188, 223)); arraylist <Bardataset> bardatasets = new ArrayList <Bardataset> (); bardatasets.add (bardataset); // 데이터 세트 추가 bardatabardata = new Bardata (xvalues, bardatasets); returnbardata;}} 렌더링은 다음과 같습니다.
위의 것은 PIE 차트, 라인 차트 및 막대 차트와 관련된 Mpaandroidchart 오픈 소스 차트 라이브러리 사용에 대한 소개입니다. 모든 사람에게 도움이되기를 바랍니다.