2017-10-26 8 views
1

のスクリーンショットを私の使用チャートに添付しました。赤いボックスにはの伝説が表示され、円グラフで切れています。以下 は私のコードです:MpAndroidChart底面中央にピエールの伝説の切れ味の問題

pieChart.setUsePercentValues(false); 
pieChart.getDescription().setEnabled(false); 
pieChart.setDragDecelerationFrictionCoef(0.95f); 
pieChart.setDrawHoleEnabled(true); 
pieChart.setHoleColor(Color.WHITE); 
pieChart.setTransparentCircleColor(Color.WHITE); 
pieChart.setTransparentCircleAlpha(110); 
pieChart.setHoleRadius(55f); 
pieChart.setTransparentCircleRadius(57f); 
pieChart.setDrawCenterText(true); 
pieChart.setRotationAngle(0); 
// enable rotation of the chart by touch 
pieChart.setRotationEnabled(true); 
pieChart.setHighlightPerTapEnabled(true); 
// add a selection listener 
pieChart.setOnChartValueSelectedListener(this); 
pieChart.animateY(1400, Easing.EasingOption.EaseInOutQuad); 

Legend l = pieChart.getLegend(); 
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM); 
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER); 
l.setOrientation(Legend.LegendOrientation.VERTICAL); 
l.setDrawInside(false); 
l.setForm(Legend.LegendForm.CIRCLE); 
l.setXEntrySpace(7f); 
l.setYEntrySpace(0f); 
l.setYOffset(0f); 
l.setWordWrapEnabled(true); 
l.setDrawInside(false); 
l.getCalculatedLineSizes(); 

// entry label styling 
pieChart.setEntryLabelColor(Color.WHITE); 
pieChart.setEntryLabelTextSize(12f); 

誰もが答えを知っていることはできますか?この問題を解決するのを手伝ってください。事前に感謝します。

enter image description here

アップデート:以下

チャートをdispalyするために私のxmlファイルです。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/coordinatorLayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:theme="@style/AppTheme" 
tools:context="com.visualogyx.app.activity.SettingsActivity$PlaceholderFragment"> 

<RelativeLayout 
    android:id="@+id/linear_change_usage" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="16dp" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:id="@+id/relative_text_dropdown_arraow" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/light_grey"> 

     <TextView 
      android:id="@+id/textview_usage_type" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="16dp" 
      android:layout_marginLeft="22dp" 
      android:layout_marginRight="22dp" 
      android:layout_marginTop="16dp" 
      android:text="Tasks" 
      android:textColor="@color/black" 
      android:textSize="17sp" /> 

     <ImageView 
      android:id="@+id/dropdown_arraow" 
      android:layout_width="24dp" 
      android:layout_height="24dp" 
      android:layout_alignParentRight="true" 
      android:layout_marginBottom="16dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="16dp" 
      android:src="@drawable/ic_arrow_drop_down_black_24dp" /> 
    </RelativeLayout> 

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

</RelativeLayout> 

<ProgressBar 
    android:id="@+id/display_chart_progress" 
    style="?android:attr/progressBarStyle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:visibility="gone" /> 
</RelativeLayout> 

号 - 私は、グラフを読み込むたびに、グラフの凡例が自動的に下から切り取られます。同じ伝説を中央に置くとうまくいきますが、問題は底だけに起こります。

答えて

0

ほとんどの場合、チャートのオフセットに問題があります。これを試してみて、この関数は 自動計算されたオフセットに追加する(チャートビューの周りに)余分なオフセットを設定します

pieChart.setExtraOffsets(0, 0, 0, 25); 

あなたの問題を解決する必要があります。引数は(left、top、right、bottom)です。 あなたのニーズに合ったオフセットを表示するには、値を使いましょう。

+0

このコードを使用すると、私の円グラフが上下に動きます。しかし、私の伝説はまだその位置にあります。彼らは動いていない。ご回答有難うございます。 –

0

PieChartに余白または余白を設定するか、凡例を水平方向に揃えてください。

2

私はこれが私のレイアウトXML

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:clickable="true" 
    android:background="@color/background_color"> 

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

    <ListView 
     android:id="@+id/list_chart" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/chart1" /> 

</RelativeLayout> 

といけないのを忘れている通常のリストビュー

ListView list = (ListView) findViewById(R.id.list_chart); 
list.setAdapter(new ChartTextLegendAdapter(this, values, colors)); 

にタイトルを追加することで、この問題を解決し、伝説

内のタイトルを非表示にしています色の値とArrayListを渡します。

for (int c : ColorTemplate.PASTEL_COLORS) 
      colors.add(c); 
     for (int c : ColorTemplate.LIBERTY_COLORS) 
      colors.add(c); 
     for (int c : ColorTemplate.COLORFUL_COLORS) 
      colors.add(c); 
     for (int c : ColorTemplate.JOYFUL_COLORS) 
      colors.add(c); 
     for (int c : ColorTemplate.VORDIPLOM_COLORS) 
      colors.add(c); 

     colors.add(ColorTemplate.getHoloBlue()); 


     values.DetailAmount = getIntent().getStringArrayListExtra("amount"); 
     values.DetailId = getIntent().getIntegerArrayListExtra("id"); 
     values.DetailName = getIntent().getStringArrayListExtra("names"); 
     values.DetailEnglishName = getIntent().getStringArrayListExtra("enames"); 
     month_name = getIntent().getStringExtra("month_name"); 

これもあなたの問題を解決することを願っています。

+0

あなたの答えをありがとう。 値に含まれるべきものと、この値を取得する方法は?あなたはこれについてより多くのコードを私に送ることができますか? –

+0

私はバンドルの値を渡しました。チャートと同じ方法で取得します。投稿の更新を確認してください – AbuQauod

+0

アダプタコードを送れますか? –

関連する問題