简体   繁体   中英

Creating a spinning pie chart (wheel) android

I have created an Pie chart which I want to spin randomly and stop on click.
Then my android program needs to read which value is above.

I already got this:

    PieDataSet dataSet = new PieDataSet(yvalues, "");

    ArrayList<String> xVals = new ArrayList<String>();
    ArrayList<Integer> colors = new ArrayList<Integer>();
    pieChart.setDrawHoleEnabled(false);
    pieChart.animateXY(1400, 1400);

    pieChart.getLegend().setEnabled(false);
    pieChart.setDrawSliceText(false);
    dataSet.setDrawValues(false);
    xVals.add("Correct");
    xVals.add("Wrong");
    colors.add(Color.rgb(115, 255, 134));
    colors.add(Color.rgb(255, 115, 115));
    dataSet.setColors(colors);
    pieChart.setDescription("");

    PieData data = new PieData(xVals, dataSet);

    data.setValueFormatter(new PercentFormatter());
    data.setValueTextSize(18f);
    data.setValueTextColor(Color.BLACK);
    pieChart.setData(data);
    pieChart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            pieChart.spin( 500,0,-360f, Easing.EasingOption.EaseInOutQuad);
        }
    });

I don't know how to spin this chart on click and stop it randomly.
Then I need to get the value of the chart which is spinned.

You can use this library. (Easy and simple implementation of PieChart with Scatter) This library will fulfill all the requirements you have mentioned above.

https://android-arsenal.com/details/1/4492

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM