allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
compile 'com.github.PhilJay:MPAndroidChart:v2.2.4'
public class MainActivity extends AppCompatActivity {
BarChart chart;
ArrayList<BarEntry> entries;
ArrayList<String> labels;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chart = (BarChart) findViewById(R.id.barChartId);
entries = new ArrayList<>();
labels = new ArrayList<>();
entries.add(new BarEntry(2f, 0));
entries.add(new BarEntry(4f, 1));
entries.add(new BarEntry(6f, 2));
entries.add(new BarEntry(8f, 3));
entries.add(new BarEntry(7f, 4));
entries.add(new BarEntry(3f, 5));
labels.add("January");
labels.add("February");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
BarDataSet barDataSet = new BarDataSet(entries, "Projects");
BarData barData = new BarData(labels, barDataSet);
barDataSet.setColors(ColorTemplate.COLORFUL_COLORS);
chart.setData(barData);
chart.animateY(3000);
}
Error :
java.lang.NoSuchMethodError: No direct method (FI)V in class Lcom/github/mikephil/charting/data/BarEntry;
Related
Drawing a horizontal bar chart using MPAndroidChart 3.0.2. the values are shown on the right of the bars. I could use setValueFormatter and use IAxisValueFormatter interface to display the labels on the right. But the values are not displayed now.
{
HorizontalBarChart barChart = (HorizontalBarChart) itemView.findViewById(R.id.barChart);
BarData data = new BarData();
ArrayList<BarEntry> valueSet1 = new ArrayList<>();
ArrayList<String> labels = new ArrayList<>();
labels.add("January");
labels.add("February");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
ArrayList<String> ylabels = new ArrayList<>();
int dataCount=0;
for (int i=0;i<6;++i) {
BarEntry entry = new BarEntry(dataCount,(i+1)*2);
valueSet1.add(entry);
ylabels.add(" "+i);
dataCount++;
}
List<IBarDataSet> dataSets = new ArrayList<>();
BarDataSet bds = new BarDataSet(valueSet1, " ");
bds.setColors(ColorTemplate.MATERIAL_COLORS);
String[] xAxisLabels = labels.toArray(new String[0]);
String[] yAxisLabels = ylabels.toArray(new String[0]);
bds.setStackLabels(xAxisLabels);
dataSets.add(bds);
data.addDataSet(bds);
data.setDrawValues(true);
data.setBarWidth(0.4f);
XAxis xaxis = barChart.getXAxis();
xaxis.setDrawGridLines(false);
xaxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xaxis.setGranularityEnabled(true);
xaxis.setGranularity(1);
xaxis.setDrawLabels(true);
xaxis.setLabelCount(dataCount+1);
xaxis.setXOffset(10);
xaxis.setDrawAxisLine(false);
CategoryBarChartXaxisFormatter xaxisFormatter = new CategoryBarChartXaxisFormatter(xAxisLabels);
xaxis.setValueFormatter(xaxisFormatter);
YAxis yAxisLeft = barChart.getAxisLeft();
yAxisLeft.setEnabled(false);
YAxis yAxisRight = barChart.getAxisRight();
yAxisRight.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
yAxisRight.setDrawGridLines(false);
yAxisRight.setDrawAxisLine(false);
Legend legend = barChart.getLegend();
legend.setEnabled(false);
barChart.setFitBars(true);
barChart.setData(data);
barChart.setDescription(null);
}
public class CategoryBarChartXaxisFormatter implements IAxisValueFormatter {
private String[] mValues;
public CategoryBarChartXaxisFormatter(String[] values) {
this.mValues = values;
}
#Override
public String getFormattedValue(float value, AxisBase axis) {
int val = (int)value;
String label="";
if(val>=0 && val<mValues.length) {
label= mValues[val];
}
else {
label= "";
}
return label;
}
}
requirement is to display label strings on the right and a number on the left corresponding to each bar.
I did check some stack overflow and google it but didn't find anything that works so far.
i get this
but this is an example of my requirement
Do appreciate some help.
Thanks for your time
I implemented something similar just a few days back. Here's the code...
public class MainActivity extends AppCompatActivity {
protected HorizontalBarChart mChart;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<String> labels = new ArrayList<>();
labels.add("January");
labels.add("February");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
mChart = (HorizontalBarChart) findViewById(R.id.barChart);
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(true);
mChart.getDescription().setEnabled(false);
mChart.setPinchZoom(false);
mChart.setDrawGridBackground(false);
XAxis xl = mChart.getXAxis();
xl.setPosition(XAxis.XAxisPosition.BOTTOM);
xl.setDrawAxisLine(true);
xl.setDrawGridLines(false);
CategoryBarChartXaxisFormatter xaxisFormatter = new CategoryBarChartXaxisFormatter(labels);
xl.setValueFormatter(xaxisFormatter);
xl.setGranularity(1);
YAxis yl = mChart.getAxisLeft();
yl.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
yl.setDrawGridLines(false);
yl.setEnabled(false);
yl.setAxisMinimum(0f);
YAxis yr = mChart.getAxisRight();
yr.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
yr.setDrawGridLines(false);
yr.setAxisMinimum(0f);
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
for (int i = 0; i < 6; i++) {
yVals1.add(new BarEntry(i, (i+1)*10));
}
BarDataSet set1;
set1 = new BarDataSet(yVals1, "DataSet 1");
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
BarData data = new BarData(dataSets);
data.setValueTextSize(10f);
data.setBarWidth(.9f);
mChart.setData(data);
mChart.getLegend().setEnabled(false);
}
public class CategoryBarChartXaxisFormatter implements IAxisValueFormatter {
ArrayList<String> mValues;
public CategoryBarChartXaxisFormatter(ArrayList<String> values) {
this.mValues = values;
}
#Override
public String getFormattedValue(float value, AxisBase axis) {
int val = (int) value;
String label = "";
if (val >= 0 && val < mValues.size()) {
label = mValues.get(val);
} else {
label = "";
}
return label;
}
}
}
RESULT
Hope this helps.
I am using MPAndroidChart2.2.5 to draw charts in my project,which contains 2 group of BarDataand 1 group of LineData.When I use the BarData in Barchart,the bars shows well.But when I use the same BarData in CombinedChart,the position of the bars differs.Here's my activity.
Here's a screenshot:
.
public class CombinedChartActivity extends BaseActivity {
private CombinedChart combinedChart;
private BarChart barChart;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_combined_chart);
combinedChart = (CombinedChart) findViewById(R.id.chart);
barChart = (BarChart) findViewById(R.id.barChart);
initChart(combinedChart);
initChart(barChart);
barChart.setData(getBarData());
CombinedData combinedData = new CombinedData();
combinedData.setXVals(getXVals());
combinedData.setData(getLineData());
combinedData.setData(getBarData());
combinedChart.setData(combinedData);
}
private void initChart(BarLineChartBase barLineChartBase) {
barLineChartBase.setDescription("");
barLineChartBase.getAxisLeft().setEnabled(false);
barLineChartBase.getAxisRight().setEnabled(false);
barLineChartBase.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
barLineChartBase.getXAxis().setGridColor(R.color.white);
barLineChartBase.getXAxis().setAvoidFirstLastClipping(true);
barLineChartBase.setBackgroundColor(Color.WHITE);
}
private BarData getBarData() {
List<IBarDataSet> iBarDataSets = new ArrayList<>();
ArrayList<BarEntry> barEntries = new ArrayList<>();
for (int i = 0; i < 7; i++) {
BarEntry barEntry = new BarEntry(i + 1, i);
barEntries.add(barEntry);
}
BarDataSet barDataSet = new BarDataSet(barEntries, "Bar1");
barDataSet.setColor(Color.rgb(60, 220, 78));
barDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
ArrayList<BarEntry> barEntries2 = new ArrayList<>();
for (int i = 0; i < 7; i++) {
BarEntry barEntry = new BarEntry((float) (i + Math.random() * 10), i);
barEntries2.add(barEntry);
}
BarDataSet barDataSet1 = new BarDataSet(barEntries2, "Bar2");
barDataSet1.setColor(R.color.level_3);
barDataSet1.setAxisDependency(YAxis.AxisDependency.RIGHT);
iBarDataSets.add(barDataSet);
iBarDataSets.add(barDataSet1);
BarData barData = new BarData(getXVals(), iBarDataSets);[![enter image description here][1]][1]
return barData;
}
private LineData getLineData() {
ArrayList<Entry> entries = new ArrayList<>();
for (int i = 0; i < 7; i++) {
Entry entry = new Entry((float) (Math.random() * 10), i);
entries.add(entry);
}
List<ILineDataSet> iLineDataSets = new ArrayList<>();
LineDataSet lds1 = new LineDataSet(entries, "Line");
lds1.setLineWidth(0.2f);
lds1.setColor(R.color.level_3);
lds1.setDrawFilled(true);
lds1.setFillAlpha(150);
lds1.setFillColor(R.color.level_2);
lds1.setDrawValues(false);
lds1.setHighlightEnabled(true);
lds1.setDrawHorizontalHighlightIndicator(false);
lds1.setHighLightColor(R.color.white);
lds1.setDrawCubic(true);
lds1.setDrawCircles(true);
lds1.setCircleColor(R.color.white);
lds1.setCircleColorHole(R.color.theme_orange);
lds1.setAxisDependency(YAxis.AxisDependency.LEFT);
iLineDataSets.add(lds1);
LineData lineData = new LineData(getXVals(), iLineDataSets);
return lineData;
}
private List<String> getXVals() {
ArrayList<String> xVals = new ArrayList<>();
xVals.add("Monday");
xVals.add("Tuesday");
xVals.add("Wednesday");
xVals.add("Thursday");
xVals.add("Friday");
xVals.add("Saturday");
xVals.add("Sunday");
return xVals;
}
}
I use same BarData in both charts.What causes the difference.How can I make the bars in Combinedchart show as in the Barchart?
I have a problem using BarData. My code shows an error at :
BarData Data = new BarData(Date,depenses);
I only want to show the date under every bar.
My Code is..
public class statistique extends AppCompatActivity {
BarChart barChart;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_statistique);
barChart = (BarChart)findViewById(R.id.stats_chart);
ArrayList<BarEntry> entries = new ArrayList<>();
entries.add(new BarEntry(4f, 0));
entries.add(new BarEntry(8f, 1));
entries.add(new BarEntry(6f, 2));
entries.add(new BarEntry(12f, 3));
entries.add(new BarEntry(18f, 4));
entries.add(new BarEntry(9f, 5));
BarDataSet depenses = new BarDataSet(entries, "depenses");
ArrayList<String> Date = new ArrayList<>();
Date.add("2/7/2016");
Date.add("3/7/2016");
Date.add("5/7/2016");
Date.add("6/7/2016");
Date.add("23/7/2016");
Date.add("30/7/2016");
BarData Data = new BarData(Date,depenses);
barChart.setData(Data);
barChart.setTouchEnabled(true);
barChart.setDragEnabled(true);
barChart.setScaleEnabled(true);
barChart.animateXY(3000, 3000);
barChart.setHorizontalScrollBarEnabled(true);
barChart.setDoubleTapToZoomEnabled(true);
barChart.setDescription("Dépenses");
depenses.setColors(ColorTemplate.COLORFUL_COLORS);
}
}
Which version of the library are you using. The new v3.0 works slightly differently. If your using any v2 version the following will work. The error is misleading you need to cast your DataSets to IBarData sets, and it needs to be a list I believe.
This should work for you.
ArrayList<IBarDataSet> dataSets = new ArrayList<>();
dataSets.add((IBarDataSet) depenses);
BarData Data = new BarData(Date, dataSets);
If you're using the new version 3 library, you need to set your XAxis differently. In that case you just need to pass
ArrayList<IBarDataSet> dataSets = new ArrayList<>();
dataSets.add((IBarDataSet) depenses);
BarData Data = new BarData(dataSets);
You'll then need to setup your XAxis.
IAxisValueFormatter formatter = new IAxisValueFormatter() {
#Override
public String getFormattedValue(float value, AxisBase axis) {
return Date.get((int)value);
}
// we don't draw numbers, so no decimal digits needed
#Override
public int getDecimalDigits() { return 0; }
};
XAxis xAxis = barChart.getXAxis();
xAxis.setGranularity(1f); // minimum axis-step (interval) is 1
xAxis.setValueFormatter(formatter);
implementation 'com.github.PhilJay:MPAndroidChart:3.0.3'
List<BarEntry> grafdata = new ArrayList<>();
Create a method:
public void barchardata(){
grafdata.add(new BarEntry( 0, Math.round(Float.valueOf(5.5f))));
grafdata.add(new BarEntry( 1, Math.round(Float.valueOf(1.5f))));
grafdata.add(new BarEntry( 2, Math.round(Float.valueOf(7.5f))));
grafdata.add(new BarEntry( 3, Math.round(Float.valueOf(4.5f))));
grafdata.add(new BarEntry( 4, Math.round(Float.valueOf(3.5f))));
InitilizationBarChart();
}
private void InitilizationBarChart() {
BarDataSet bardataset = new BarDataSet(grafdata, "");
barChartView.animateY(2000);
BarData data = new BarData(bardataset);
bardataset.setColors(ColorTemplate.COLORFUL_COLORS);
bardataset.setValueTextColor(Color.GREEN);
barChartView.getAxisLeft().setTextColor(this.getResources().getColor(R.color.green));
barChartView.getXAxis().setTextColor(this.getResources().getColor(R.color.green));
barChartView.getAxisRight().setDrawGridLines(false);
barChartView.getAxisLeft().setDrawGridLines(false);
barChartView.getXAxis().setDrawGridLines(false);
barChartView.getLegend().setTextColor(this.getResources().getColor(R.color.green));
barChartView.setData(data);
final XAxis xAxis = barChartView.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setValueFormatter(new IndexAxisValueFormatter(){
#Override
public String getFormattedValue(float value, AxisBase axis) {
return getXAxisValues().get((int) value);
}
});
barChartView.getAxisRight().setEnabled(false);
xAxis.setGranularityEnabled(true);
}
Initialize name:
private List<String> getXAxisValues() {
ArrayList<String> xAxis = new ArrayList<>();
UserNameList.clear();
UserNameList.add("Rampal");
UserNameList.add("sonu");
UserNameList.add("Amber");
UserNameList.add("Viresh");
UserNameList.add("Pal");
return UserNameList;
}
You can do something like this:
barChart = (BarChart)findViewById(R.id.stats_chart);
ArrayList<BarEntry> entries = new ArrayList<>();
entries.add(new BarEntry(4f, 0));
entries.add(new BarEntry(8f, 1));
entries.add(new BarEntry(6f, 2));
entries.add(new BarEntry(12f, 3));
entries.add(new BarEntry(18f, 4));
entries.add(new BarEntry(9f, 5));
ArrayList<String> Date = new ArrayList<>();
Date.add("2/7/2016");
Date.add("3/7/2016");
Date.add("5/7/2016");
Date.add("6/7/2016");
Date.add("23/7/2016");
Date.add("30/7/2016");
barChart.setTouchEnabled(true);
barChart.setDragEnabled(true);
barChart.setScaleEnabled(true);
barChart.animateXY(3000, 3000);
barChart.setHorizontalScrollBarEnabled(true);
barChart.setDoubleTapToZoomEnabled(true);
barChart.setDescription("Dépenses");
depenses.setColors(ColorTemplate.COLORFUL_COLORS);
ArrayList<IBarDataSet> dataSets = null;
BarDataSet barDataSet1 = new BarDataSet(entries "your title");
dataSets=new ArrayList<>();
dataSets.add(barDataSet)
BarData Data = new BarData(Date,barDataSet1);
barChart.setData(Data);
I get the following error when trying to compile a stacked bargraph. I have copied code working for a grouped bargraph and am trying to add the "stacked" functionality to this code. The error is marked in comments in the code below, in each of the bar entry lines as per following example:
"
BarEntry v1e1 = new BarEntry(0f, new float[]{10,20,20});
"
Here is the code:
public class StackedBarGraph extends AppCompatActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.groupedbargraph);
BarChart chart = (BarChart) findViewById(R.id.mpandroidstackedbargraph );
BarData data = new BarData(getXAxisValues(),getDataSet()); //!! ignore the complaint - it compiles and works
chart.setData(data);
chart.setDescription("My Chart");
chart.animateXY(2000, 2000);
chart.invalidate();
}
private ArrayList<IBarDataSet> getDataSet() {
ArrayList<IBarDataSet> dataSets = null;
ArrayList<BarEntry> valueSet1 = new ArrayList<>();
BarEntry v1e1 = new BarEntry(0f, new float[]{10,20,20}); // ERROR
valueSet1.add(v1e1); //THESE LINES ALL GIVE ABOVE ERROR
BarEntry v1e2 = new BarEntry(1f, new float[]{20,30,30}); // ERROR
valueSet1.add(v1e2);
BarEntry v1e3 = new BarEntry(2f, new float[]{30,50,40}); // ERROR
valueSet1.add(v1e3);
BarEntry v1e4 = new BarEntry(3f, new float[]{50,70,50}); // ERROR
valueSet1.add(v1e4);
BarEntry v1e5 = new BarEntry(4f, new float[]{70,40,60}); // ERROR
valueSet1.add(v1e5);
BarEntry v1e6 = new BarEntry(5f, new float[]{40,30,70}); // Jun
valueSet1.add(v1e6);
ArrayList<BarEntry> valueSet2 = new ArrayList<>();
BarEntry v2e1 = new BarEntry(0, new float[]{10,20,30}); // ERROR
valueSet2.add(v2e1);
BarEntry v2e2 = new BarEntry(1, new float[]{10,20,30}); // ERROR
valueSet2.add(v2e2);
BarEntry v2e3 = new BarEntry(2, new float[]{10,20,30}); // ERROR
valueSet2.add(v2e3);
BarEntry v2e4 = new BarEntry(3, new float[]{10,20,30}); // ERROR
valueSet2.add(v2e4);
BarEntry v2e5 = new BarEntry(4, new float[]{10,20,30}); // ERROR
valueSet2.add(v2e5);
BarEntry v2e6 = new BarEntry(5, new float[]{10,20,30}); // ERROR
valueSet2.add(v2e6);
BarDataSet barDataSet1 = new BarDataSet(valueSet1, "Brand 1");
barDataSet1.setColor(Color.rgb(0, 155, 0)); // Green
BarDataSet barDataSet2 = new BarDataSet(valueSet2, "Brand 2");
barDataSet1.setColor(Color.rgb(0, 155, 155)); // Light Blue
dataSets = new ArrayList<>();
dataSets.add(barDataSet1);
dataSets.add(barDataSet2);
return dataSets;
}
private ArrayList<String> getXAxisValues() {
ArrayList<String> xAxis = new ArrayList<>();
xAxis.add("JAN");
xAxis.add("FEB");
xAxis.add("MAR");
xAxis.add("APR");
xAxis.add("MAY");
xAxis.add("JUN");
return xAxis;
}
BarEntry contains the following constructors:
BarEntry(float[] vals, int xIndex)
BarEntry(float val, int xIndex)
BarEntry(float[] vals, int xIndex, String label)
BarEntry(float val, int xIndex, Object data)
So, what your doing is not possible. Flip your arguments...
i.e
BarEntry v1e1 = new BarEntry(new float[]{10,20,20}, 0);
Please look into the source code for details.
In my app there is a need of pie chart for which i am using MPAndroidChart but, getting error while adding data in Piedata constructor,please help.
Using dependancy compile 'com.github.PhilJay:MPAndroidChart:v3.0.0 beta'
imageView=(PieChart) v.findViewById(R.id.result_text);
ArrayList<Entry> entries = new ArrayList<>();
entries.add(new Entry(4f, 0));
entries.add(new Entry(8f, 1));
entries.add(new Entry(6f, 2));
entries.add(new Entry(12f, 3));
entries.add(new Entry(18f, 4));
entries.add(new Entry(9f, 5));
PieDataSet dataset = new PieDataSet(entries,"uyggh");
ArrayList<Object> labels = new ArrayList<Object>();
labels.add("January");
labels.add("February");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
PieData data = new PieData(labels, dataset);//getting error here
imageView.setData(data);
imageView.setDescription("Description");
Acoording to the latest documentation corresponding to com.github.PhilJay:MPAndroidChart:v3.0.3 , entries (Pie Entries) now take x and y values together.
List<PieEntry> entries = new ArrayList<>();
entries.add(new PieEntry(18.5f, "Green"));
entries.add(new PieEntry(26.7f, "Yellow"));
entries.add(new PieEntry(24.0f, "Red"));
entries.add(new PieEntry(30.8f, "Blue"));
PieDataSet set = new PieDataSet(entries, "Election Results");
PieData data = new PieData(set);
pieChart.setData(data);
pieChart.invalidate(); // refresh
So instead of degrading the depandency , use the updated code.
PieData takes only one argument and that is PieDataSet. So replace
PieData data = new PieData(labels, dataset);
with
PieData data = new PieData(dataset);
For more details, you can check this official example.
Hope, this answer is helpful to you.
When i used dependancy com.github.PhilJay:MPAndroidChart:v2.1.6' then
PieData accepts two arguments i.e String and PieDataSet. So, I think its problem with the dependancy update.
Using lower dependancy it can be solve.
You should passing labels in PieEntry methode like this.
it works for me
private float[] yData = {25.3f,10.3f,66.3f,44.3f,16.3f,46.3f,23.3f};
private String[] xData = {"med","hamza","mohammed","","","",""};
for(int i = 0 ; i <yData.length;i++){
yEntrys.add(new PieEntry(yData[i],xData[i % xData.length]));
}
it's my code , it works 100 % with
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1' But higher version of gradle use implementation instead of compile
public class Main2Activity extends AppCompatActivity {
private static String TAG = "MainActivit";
private float[] yData = {25.3f,10.3f,66.3f,44.3f,16.3f,46.3f,23.3f};
private String[] xData = {"med","hamza","mohammed","","","",""};
PieChart pieChart;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Log.d(TAG, "Beach chart");
pieChart = (PieChart) findViewById(R.id.idPieChart);
//pieChart.setDescription(" Sales by employee In thousands $");
pieChart.setRotationEnabled(true);
pieChart.setHoleRadius(25f);
pieChart.setTransparentCircleAlpha(0);
pieChart.setCenterText("super cool chart");
pieChart.setCenterTextSize(10);
pieChart.setDrawEntryLabels(true);
addDataSet();
pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
#Override
public void onValueSelected(Entry e, Highlight h) {
Log.d(TAG, "onValueSelected: value selected from chart");
Log.d(TAG, "onValueSelected: "+ e.toString());
Log.d(TAG, "onValueSelected: "+ h.toString());
}
#Override
public void onNothingSelected() {
}
});
}
private void addDataSet() {
Log.d(TAG, "addDataSet: started");
ArrayList<PieEntry> yEntrys = new ArrayList<>();
ArrayList<String> xEntrys = new ArrayList<>();
for(int i = 0 ; i <yData.length;i++){
yEntrys.add(new PieEntry(yData[i],xData[i % xData.length]));
}
for(int i = 0 ; i <xData.length;i++){
xEntrys.add(xData[i]);
}
//create the DATA
PieDataSet pieDataSet = new PieDataSet(yEntrys,"Beachs");
pieDataSet.setSliceSpace(2);
pieDataSet.setValueTextSize(12);
//add colors to dataSet
ArrayList<Integer> colors = new ArrayList<>();
colors.add(Color.GRAY);
colors.add(Color.BLUE);
colors.add(Color.RED);
colors.add(Color.GREEN);
colors.add(Color.CYAN);
colors.add(Color.YELLOW);
colors.add(Color.MAGENTA);
pieDataSet.setColors(colors);
pieDataSet.setSliceSpace(25);
//add legend to chart
Legend legend = pieChart.getLegend();
legend.setForm(Legend.LegendForm.CIRCLE);
legend.setPosition(Legend.LegendPosition.LEFT_OF_CHART);
//create a pieData object
PieData pieData = new PieData(pieDataSet);
pieChart.setData(pieData);
pieChart.invalidate();
}
}
Your ArryayList<> should be with String, not with Object:
ArrayList<String> labels = new ArrayList<String>();
....
PieData data = new PieData(labels, dataset);//getting error here
Because new PieData needs ArrayList<< String >>