I'm using a pie chart in my activity. When I set a big value into the entries, it doesn't show the value correctly.
For example:
My value is 627050000 but the chart shows is 627049986,
or
my value is 477470000 but the chart shows is 477470016.
Here's my code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
double num1 = 627050000 ;
double num2 = 477470000 ;
setupPieChart();
}
private void setupPieChart() {
List<PieEntry> pieEntries = new ArrayList<>();
pieEntries.add(new PieEntry((float) num1 , "num1"));
pieEntries.add(new PieEntry((float) num2 , "num2"));
PieDataSet dataSet = new PieDataSet(pieEntries , "numbers");
PieData data = new PieData(dataSet);
PieChart pieChart = (PieChart) findViewById(R.id.piechart);
pieChart.setTransparentCircleAlpha(1);
pieChart.getDescription().setEnabled(false);
//add legend to chart
Legend legend = pieChart.getLegend();
legend.setForm(Legend.LegendForm.CIRCLE);
legend.setOrientation(Legend.LegendOrientation.VERTICAL);
legend.setDirection(Legend.LegendDirection.RIGHT_TO_LEFT);
legend.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
//add colors to dataset
ArrayList<Integer> colors = new ArrayList<>();
colors.add(Color.CYAN);
colors.add(Color.GREEN);
colors.add(Color.RED);
dataSet.setColors(colors);
pieChart.setData(data);
pieChart.animateY(1000);
pieChart.invalidate();
}
I read about ValueFormatter
class also using BigDecimal but I didn't understand.
Please help and explain in a simple way.
Thanks.