Android MPChart如何更改YAxis

时间:2015-10-01 09:27:21

标签: android bar-chart mpandroidchart

我想创建一个条形图,其中YAxis包含浮点值,而xAxis包含字符串值, 我的问题是我想在YAxis中更改显示的数据并使其成为String,但该值仍然是浮动的 这是我的图表

       mChart = (BarChart) findViewById(R.id.chart1);

    mChart.setDescription("");

    // if more than 60 entries are displayed in the chart, no values will be


    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);

    mChart.setDrawBarShadow(false);
    mChart.setDrawGridBackground(false);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setSpaceBetweenLabels(0);
    xAxis.setTextSize(10);
    xAxis.setDrawGridLines(false);

    mChart.getAxisRight().setDrawGridLines(false);
    mChart.getAxisLeft().setDrawGridLines(false);

    mChart.getAxisLeft().setDrawLabels(true);

    mChart.getXAxis().setXOffset(10);


    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setDrawAxisLine(false);
    rightAxis.setTextColor(Color.WHITE);
    rightAxis.setDrawGridLines(false);

    // add a nice and smooth animation
    mChart.animateY(2500);

    mChart.getLegend().setEnabled(true);

这就是我调用条形数据集的方式

      xVals.add(" ");
      ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();

        for (int i = 0; i < yvalues.size(); i++) {
            BarEntry b=new BarEntry((int)Float.parseFloat(yvalues.get(i)), i);
   //here is the BarEntry values but i cant change the displayed value its still
   //showing float


            yVals1.add(b);
        }


        BarDataSet set1 = new BarDataSet(yVals1, "duration min");
        set1.setColor(Color.GREEN);

        set1.setDrawValues(false);
        set1.setLabel("duration min");

        ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
        dataSets.add(set1);


        BarData data = new BarData(xVals, dataSets);

        mChart.setData(data);
        mChart.invalidate();

1 个答案:

答案 0 :(得分:0)

如果您不想显示浮点值,请尝试获取舍入值。

BarEntry b=new BarEntry(Math.round(yvalues.get(i)), i);