mpaandroidchartオープンソースチャートライブラリパイチャート
アイコンオープンソースライブラリMPAANDROIDCHARTを紹介します。 Androidデバイスにさまざまな統計チャートを描画するだけでなく、使用が非常に柔軟なチャートをドラッグアンドズームすることもできます。 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; Android.support.v7.app.actionBaractivityをインポートします。 importandroid.graphics.color; importandroid.os.bundle; importandroid.util.displaymetrics;パブリッククラスのMainActivityはActionBaractivityを拡張します{privatePieChartMChart; @Override Protected void oncreate(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.sethoredius(60f); //RADIUSPIECHART.SETTRASSPARENTCIRCLERADIUS(64f); //半透明Circle // piechart.setholeradius(0)// Solid Circle piechart.setDescription( "Test Pie Chart"); // mchart.setdrawyvalues(true); piechart.setDrawCentertext(true); //テキストは、パイチャートpiechart.setdrawholeenabled(true)の中央に追加できます。 piechart.setRotationAngle(90); //初期回転角//対応する説明値をスライスに描画します// mchart.setDrawxValues(true); // touch piechart.setRotationEnabled(true)によってチャートの回転を有効にすること。 //手動で回転することができます//表示パーセント値piechart.setusepercentValues(true); //ディスプレイパーセンテージ// mchart.setunit( "); //ディスプレイパーセンテージ// mchart.setunit("); // mchart.setdrawunitsinchart(true); //選択リスナーの追加// mchart.settouchEnabled(false); // mchart.setonanimationlistener(this); piechart.setCentertext( "Quarterly Revenue"); //パイチャートの中央のテキスト//データを設定しますpiechart.setdata(piedata); //すべてのハイライトを元に戻す// piechart.highlightvalues(null); // piechart.invalidate(); Legend Mlegend = piechart.getLegend(); //スケールグラフを設定しますmlegend.setposition(ledgentposition.right_of_chart); //右端に表示// mlegend.setform(ledgentform.line); //スケールグラフの形状を設定すると、デフォルトはsquare mlegend.setxentryspace(7f)です。 mlegend.setyentryspace(5f); piechart.animatexy(1000、1000); //アニメーションを設定する// mchart.spin(2000、0、360); } / ** * * @paramカウントはいくつかの部分に分割されます * @param範囲 * / privatePiedatagetpiedata(int count、float range){arraylist <string> xvalues = new arraylist <string>(); // xvalsは、各パイのコンテンツを表すために使用されます(inti = 0; i <count; i ++){xvalues.add( "Quarterly" +(i + 1)); //パイのディスプレイはQuarterly1、Quarterly2、Quarterly3、Quarterly4} arrayList <Entry> yvalues = new ArrayList <Entry>();です。 // yvalsは、各パイブロックをカプセル化する実際のデータを表すために使用されますFloat Quarterly2 = 14; Float Quarterly3 = 34; Float Quarterly4 = 38; yvalues.add(新しいエントリ(Quarterly1、0)); yvalues.add(new Entry(Quarterly2、1)); yvalues.add(新しいエントリ(Quarterly3、2)); yvalues.add(新しいエントリ(Quarterly4、3)); // y軸Piedatasetpiedataset = new piedataset(yvalues、 "Quarterly Revenue 2014"/*スケールチャートでshow*/); piedataset.setslicespace(0f); //パイチャート間の距離を設定しますarraylist <integer> colors = new ArrayList <Integer>(); //パイチャートColors.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(colors); displaymetrics metrics = getResources()。getDisplaymetrics(); floatpx = 5 *(metrics.dencesdpi / 160f); Piedataset.setselectionShift(PX); //選択された状態の長さpiedatapiedata = new piedata(xvalues、piedataset); returnpiedata; }}レンダリングは次のとおりです。
MPAANDROIDCHARTオープンソースチャートライブラリラインチャート
1. MandroidChartLibrary-2-0-8.JarパッケージをプロジェクトのLIBSにコピーします
2。XMLファイルを定義します
3.主なJavaロジックコードは次のとおりです。
packagecom.example.mpandroidlinechart; importjava.util.arraylist; comportcom.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; Android.support.v7.app.actionBaractivityをインポートします。 importandroid.graphics.color; importandroid.os.bundle;パブリッククラスのMainActivityは、アクションバラアクティビティを拡張します{privatelinechartmlinechart; // private thipface mtf; @Override Protected void oncreate(bundle savedinstancestate){super.oncreate(savedinstancestate); setContentView(r.layout.activity_main); mlinechart =(linechart)findViewById(r.id.spread_line_chart); // mtf = gootface.createfromasset(getAssets()、 "opensans-bold.ttf"); linedatamlinedata = getLinedata(36、100); showchart(mlinechart、mlinedata、color.rgb(114、188、223)); } //ディスプレイスタイルのプライベートボイドショーチャート(linechartlinechart、linedatalinedata、int color){linechart.setdrawborders(false); //ラインチャートに境界を追加する場所//グリッドの背景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.setform(ledgentform.circle); // style mlegend.setformsize(6f); // font mlegend.settextcolor(color.white); // color // mlegend.settypeface(mtf); // font linechart.animex(2500); //アニメーションの即時実行、x-axis}/ ***データを生成* @paramカウントチャートにある座標ポイントの数を示します* @return*/ privatelinedatagetlinedata(int count、float range){arraylist <string> xvalues = new arraylist <string>(arraylist <string>); for(inti = 0; i <count; i ++){// x軸に表示されたデータ、デフォルトでは、xValues.add( ""+i)を表示するために数値subscriptが使用されます。 } // y-axis data arrayList <Entry> yvalues = new ArrayList <Entry>(); for(inti = 0; i <count; i ++){float value =(float)(math.random() * range)+3; yvalues.add(new entry(value、i)); } //データセットを作成して、タイプ// y-xisデータセットLinedatasetlinedataset = new Linedataset(yvalues、 "Test Line Chart" /*スケールチャート* /)に表示されます。 // mlinedataset.setfillalpha(110); // mlinedataset.setFillcolor(color.red); // y軸セットを使用して、パラメーターlinedataset.setlinewidth(1.75f)を設定します。 // linewidth linedataset.setcirclesize(3f); //円のサイズLINEDINATASET.SETCOLOR(color.white)を表示します。 //色を表示linedataset.setCircleColor(color.white); //円の色linedataset.sethighlightcolor(color.white); //強調表示された行の色ArrayList <Linedataset> LINEDINATASETS = new ArrayList <Linedataset>(); linedatasets.add(linedataset); //データセットの追加returnlinedata; }}レンダリングは次のとおりです。
MPAANDROIDCHARTオープンソースチャートライブラリバーチャート
1. MandroidChartLibrary-2-0-8.JarパッケージをプロジェクトのLIBSにコピーします
2。XMLファイルを定義します
3.主なJavaロジックコードは次のとおりです。
packagecom.jackie.mpandoidiodbarchart; 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 form; comportcom.github.mikephil.charting.components.xaxis; compontcom.github.mikephil.charting.components.xaxis.xaxisposition; importcom.githu b.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; privatebardatambardata; {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 shawbarchart(barchartbarchart、bardatabardata){barchart.setdrawborders(false); ///ラインチャートに境界を追加する場所barchart.setdescription( ""); // data description //データがない場合、listViewのemptyViewBarchart.setNodateTtdescription( "チャートにデータを提供する必要がある)と同様に表示されます。 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(legnedform.circle); // style mlegend.setformsize(6f); // font mlegend.settextcolor(color.black); // color // x-axis setting // xaxisxaxis = barchart.getxaxis(); // xaxis.setposition(xaxisposition.bottom); barchart.animex(2500); //アニメーションの即時実行、x-axis} privatebardatagetbardata(int count、float range){arraylist <string> xvalues = new arraylist <string>(); for(inti = 0; i ++){xvalues.add( "th" +(i + 1); "Quarter < arrayList <barentry>(); for(inti = 0; i <count; i ++){float value =(float)(math.random()*randual nums in the range/*100*/)+3; yvalues.add(new Barentry(value、i)); } // y軸のデータセットbardatasetbardataset = new bardataset(yvalues、 "test pie chart"); bardataset.setcolor(color.rgb(114、188、223)); arraylist <bardataset> bardatasets = new arraylist <bardataset>(); bardatasets.add(bardataset); //データセットを追加Bardatabardata = new Bardata(XValues、 bardatasets); returnbardata;}} packagecom.jackie.mpandoidiodbarchart; importjava.util.arraylist; importcom.github.mikephil.charting.chart.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; privatebardatambardata; {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 shawbarchart(barchartbarchart、bardatabardata){barchart.setdrawborders(false); ///ラインチャートに境界を追加する場所barchart.setdescription( ""); // data description //データがない場合、listViewのemptyViewBarchart.setNodateTtdescription( "チャートにデータを提供する必要がある)と同様に表示されます。 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(legnedform.circle); // style mlegend.setformsize(6f); // font mlegend.settextcolor(color.black); // color // x-axis setting // xaxisxaxis = barchart.getxaxis(); // xaxis.setposition(xaxisposition.bottom); barchart.animex(2500); //アニメーションの即時実行、x-axis} privatebardatagetbardata(int count、float range){arraylist <string> xvalues = new arraylist <string>(); for(inti = 0; i ++){xvalues.add( "th" +(i + 1); "Quarter < arrayList <barentry>(); for(inti = 0; i <count; i ++){float value =(float)(math.random()*randual nums in the range/*100*/)+3; yvalues.add(new Barentry(value、i)); } // y軸のデータセットbardatasetbardataset = new bardataset(yvalues、 "test pie chart"); bardataset.setcolor(color.rgb(114、188、223)); arraylist <bardataset> bardatasets = new arraylist <bardataset>(); bardatasets.add(bardataset); //データセットを追加Bardatabardata = new Bardata(XValues、Bardatasets); ReturnBardata;}}レンダリングは次のとおりです。
上記は、MPAANDROIDCHARTオープンソースチャートライブラリの使用の紹介です。これは、パイチャート、ラインチャート、バーチャートに関連しています。私はそれが誰にでも役立つことを願っています。