MPAndroidChart无法正确呈现

时间:2016-03-02 22:27:20

标签: mpandroidchart

我期待一张图表,我得到以下内容。我附上了生成它的代码,希望有些人有一些见解。我甚至试图将布局放在一个单独的片段中,我得到相同的输出。任何帮助表示赞赏。

enter image description here

act_chart.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rl"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"

    android:orientation="vertical">


    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="100dp"
        android:layout_height="100dp">

        <com.github.mikephil.charting.charts.BarChart
            android:id="@+id/chart"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>
</RelativeLayout>

ChartAct.java

public class ChartActivity extends Activity {

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

        RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl);

        BarChart bc = (BarChart) findViewById(R.id.chart);


        ArrayList<BarEntry> entries = new ArrayList<>();
        entries.add(new BarEntry(4f, 0));
        entries.add(new BarEntry(8f, 1));
        entries.add(new BarEntry(6f, 2));
        entries.add(new BarEntry(12f, 3));
        entries.add(new BarEntry(18f, 4));
        entries.add(new BarEntry(9f, 5));
        entries.add(new BarEntry(12f, 6));
        entries.add(new BarEntry(10f, 7));

        BarDataSet dataset = new BarDataSet(entries, "# of Calls");

        ArrayList<String> labels = new ArrayList<String>();
        labels.add("January");
        labels.add("February");
        labels.add("March");
        labels.add("April");
        labels.add("May");
        labels.add("June");
        labels.add("July");
        labels.add("August");
       // bc=new BarChart(this);

        BarData data = new BarData(labels, dataset);


        bc.setData(data);

        bc.setDrawBarShadow(false);
        //rl.add(bc);

       // rl.addView(bc);
    }
}

0 个答案:

没有答案