How to remove the central white circle in a pie chart - android

I made a pie-chart in my Android app and I have a white cerce in the middlle I tried to remove it but I couldn't even the piechart.setCentralCirculaire doesn't work in my code. Is there any way that I can do that? Thanks.
pieChart=(PieChart)findViewById(R.id.Piechart);
pieChart.setRotationEnabled(true);
addDataSet();
private void addDataSet(){
Log.d(TAG, "addDataSet: ");
ArrayList<PieEntry> yEntrys=new ArrayList<>();
yEntrys.add(new PieEntry(15.0f, "LOW"));
yEntrys.add(new PieEntry(50.0f,"Normal"));
yEntrys.add(new PieEntry(25.0f,"hyper"));
PieDataSet pieDataSet= new PieDataSet(yEntrys,"Employee Global Activity");
pieDataSet.setSliceSpace(2);
pieDataSet.setValueTextSize(12);
ArrayList<Integer> colors =new ArrayList<>();
colors.add(Color.RED);
colors.add(Color.BLUE);
colors.add(Color.GREEN);
pieDataSet.setColors(colors);
PieData pieData =new PieData(pieDataSet);
pieChart.setData(pieData);
pieChart.invalidate();
}

piechart.setDrawHoleEnabled(false);

If i understand right this is a MPAndroidChart, so you uses.
piechart.setHoleRadius(0.0f);

Related

Mpandroidchart display values as text

I have created a pie and a line chart using Mpandroidchart.
Pie Chart
Code
getEntries();
pieDataSet = new PieDataSet(pieEntries, "");
pieDataSet.setColors(ColorTemplate.JOYFUL_COLORS);
pieDataSet.setSliceSpace(2f);
pieDataSet.setValueTextColor(Color.BLACK);
pieDataSet.setValueTextSize(10f);
pieDataSet.setSliceSpace(5f);
pieData = new PieData(pieDataSet);
pieChart.getDescription().setEnabled(false);
pieChart.getLegend().setEnabled(false);
pieChart.setCenterText("Last Two Months Sale" );
pieChart.setCenterTextSize(14f);
pieChart.setCenterTextColor(Color.BLUE);
pieChart.animateX(1500);
pieChart.setData(pieData);
public void getEntries() {
pieEntries = new ArrayList<>();
pieEntries.add(new PieEntry(200,"March", 0));
pieEntries.add(new PieEntry(300, "April",1));
}
Line Chart
Code
private ArrayList<Entry> lineChartDataSet(){
ArrayList<Entry> dataSet = new ArrayList<Entry>();
dataSet.add(new Entry(1,200));
dataSet.add(new Entry(2,300));
dataSet.add(new Entry(3,500));
return dataSet;
}
lineDataSet = new LineDataSet(lineChartDataSet(),"data set");
lineDataSet.setLineWidth(1.75f);
lineDataSet.setCircleRadius(5f);
lineDataSet.setCircleHoleRadius(2.5f);
iLineDataSets.add(lineDataSet);
lineData = new LineData(iLineDataSets);
lineChart.setNoDataText("Data not Available");
lineChart.getDescription().setEnabled(false);
lineChart.getLegend().setEnabled(false);
lineDataSet.setColors(color);
lineChart.setTouchEnabled(true);
lineChart.setDragEnabled(true);
lineDataSet.setCircleColor(Color.parseColor("#891e9a"));
lineDataSet.setCircleHoleColor(Color.parseColor("#891e9a"));
lineDataSet.setDrawHighlightIndicators(false);
lineDataSet.setDrawCircles(true);
lineDataSet.setDrawCircleHole(true);
lineDataSet.setLineWidth(5);
lineDataSet.setCircleRadius(5);
lineDataSet.setCircleHoleRadius(5);
lineDataSet.setValueTextSize(10);
lineDataSet.setValueTextColor(Color.BLACK);
lineChart.setPinchZoom(false);
lineChart.getAxisLeft().setSpaceTop(40);
lineChart.getAxisLeft().setSpaceBottom(40);
XAxis xAxis = lineChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setValueFormatter(new IndexAxisValueFormatter(xAxisLabel));
xAxis.setGranularity(1f);
xAxis.setGranularityEnabled(true);
lineChart.getAxisRight().setEnabled(false);
lineChart.setData(lineData);
lineChart.invalidate();
Both the charts are displaying but I want to change the format of the value. In both the Pie and Line charts, one can only add floating values. But I want to add strings.
Example
I want to do the following
pieEntries.add(new PieEntry(200,"March", 0));
replace with
pieEntries.add(new PieEntry("200K","March", 0));
and
dataSet.add(new Entry(1,200));
replace with
dataSet.add(new Entry(1,"200K"));
How can I achieve it ?
Any help would be highly appreciated.
You can use ValueFormatter. Create ValueFormatter and then set it to the pieData
ValueFormatter formatter = new ValueFormatter() {
#Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return ((int) value) + " " + "K";
}
};
pieData.setValueFormatter(formatter);
If you use LargeValueFormatter it automatically turn values like "1.000" into "1k", "1.000.000" into "1m" (million) e.g. To use LargeValueFormatter just set it to pieData.
pieData.setValueFormatter(new LargeValueFormatter())
See also https://github.com/PhilJay/MPAndroidChart/wiki/The-ValueFormatter-interface

how to resizing X-label text size in MPandroidCharts

I'm using MPandroidCharts in android application to make a bar chart it data from NodeJs server my code works fine but I found that when I change nbs of data (number of articles "on XAxe" < 5) the label nb and size still the some ( max 5 elements) that make my graph Not understood, I need a solution plz
to understand my situation plz look at pictures:
My code:
ArrayList<BarEntry> entries = new ArrayList<>();
final ArrayList<String> months = new ArrayList<>();
Log.d("liste size ",product_List.size()+"");
for(int i=0; i<product_List.size();i++){
Log.d("get List nb ",product_List.get(i).getId());
Log.d("get List produit ",product_List.get(i).getProduit());
months.add(i,product_List.get(i).getProduit());
int nb = Integer.parseInt(product_List.get(i).getId());
entries.add(new BarEntry(i, nb));
}
BarDataSet barDataSet = new BarDataSet(entries, "Produits");
barDataSet.setBarBorderWidth(0.9f);
barDataSet.setColors(ColorTemplate.COLORFUL_COLORS);
BarData barData = new BarData(barDataSet);
XAxis xAxis = barChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
IndexAxisValueFormatter formatter = new IndexAxisValueFormatter(months);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(formatter);
barChart.setData(barData);
barChart.setFitBars(true);
barChart.animateY(5000);
barChart.invalidate();
One more thing, if I when to clear chart data and make others by a button which code I need to use.

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

How to add real time data in Barchart using MPAndroidChart library

I am using MPAndroid Chart library to draw BarChart.
But not getting how to draw bars with real time data in on button click.
Can anyone please help me in this.
Thanks.
After getting data store that in List(graphData). Then,
BarChart barChart;
/*List to store real time data*/
private List<Integer> graphData = new ArrayList<>();
/*List of String which contains X-axis values */
ArrayList<String> xAxisValuesList = new ArrayList<>();
// create BarEntry for group
ArrayList<BarEntry> group = new ArrayList<>();
for (int i = 0; i < graphData.size(); i++) {
Log.d(TAG, "generating for:" + graphData.get(i));
group.add(new BarEntry(graphData.get(i), i));
}
// creating dataset for group
BarDataSet barDataSet = new BarDataSet(group, "Label");
// combined all dataset into an arraylist
ArrayList<BarDataSet> dataSets = new ArrayList<>();
dataSets.add(barDataSet);
// initialize the Bardata with argument labels and dataSet
BarData barData = new BarData(xAxisValuesList, dataSets);
barChart.setData(barData);

MP Piechart data entry counts

I created a Piechart with MPandroidchart for my app. The chart works great. The problem is that the original data contains 4 data entry but the chart only show 3. Can somebody help? What is the limitation for this?
My PieChart
Hi Thank you so much for getting me back. The xVals and yVals are from SQLite database. xVals{30-,30-45,46-60,60-} String and yVals(6,14,13,3) float.
My codes are posted here:
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();
}

Categories

Resources