MP饼图数据输入计数

时间:2016-05-18 16:33:16

标签: android pie-chart

我为我的应用创建了一个带有MPandroidchart的饼图。图表效果很好。问题是原始数据包含4个数据输入,但图表只显示3.有人可以帮忙吗?对此有何限制?

1 个答案:

答案 0 :(得分:0)

My PieChart

嗨,非常感谢你让我回来。 xVals和yVals来自SQLite数据库。 xVals {30-,30-45,46-60,60-} String和yVals(6,14,13,3)浮动。

我的代码发布在这里:

    private void AddDataCYNewCustomersAge(){
    DataBaseHelper databasehelper = new DataBaseHelper       (NewCustomerReportCurrentYear.this);
    PieChart ageChart = new PieChart(this);
    ageChart = (PieChart)findViewById(R.id.agechart);
    //get yVals and datasets of marriage chart
    ArrayList<Entry> yValsageCounts = new ArrayList<Entry>();
    for(int i = 0;i < databasehelper.yDataIncomeCounts().size(); i++)
        yValsageCounts.add(new Entry(databasehelper.yDataAgeCounts().get(i), i));

    //get xVals of marriage chart
    ArrayList<String> xValsage = new ArrayList<String>();
    for(int i = 0;i < databasehelper.xDataAge().size();i++)
        xValsage.add(databasehelper.xDataAge().get(i));

    PieDataSet ageCounts = new PieDataSet(yValsageCounts, "");

    //set yvals attribute
    ageCounts.setSliceSpace(3);
    ageCounts.setSelectionShift(5);

    //add many colors
    ageCounts.setColors(new int[]{R.color.Fuchsia, R.color.Aqua,R.color.Yellow,R.color.LightSeaGreen,R.color.Blue}, this);

    // configue pie chart
    ageChart.setUsePercentValues(true);
    ageChart.setRotationEnabled(true);
    ageChart.setRotationAngle(0);
    ageChart.setDescriptionPosition(350, 550);
    ageChart.setDrawHoleEnabled(true);
    ageChart.setHoleColor(Color.TRANSPARENT);
    ageChart.setHoleRadius(13);
    ageChart.setTransparentCircleRadius(18);
    ageChart.getLegend().setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
    //ageChart.getLegend().setXEntrySpace(3);
   // ageChart.getLegend().setYEntrySpace(3);
    ageChart.getLegend().setTextColor(Color.BLUE);
    ageChart.setDescription("Income");
    ageChart.setDescriptionTextSize(13);
    ageChart.setDescriptionColor(Color.BLUE);

    //get income chart data
    PieData ageData = new PieData(xValsage,ageCounts);
    ageData.setValueFormatter(new PercentFormatter());
    ageData.setValueTextSize(11);
    ageData.setValueTextColor(Color.BLUE);
    ageChart.setData(ageData);


    //refresh data
    ageChart.invalidate();
}