I am trying to add MPAndroidChart to my app by using the following code, but i am getting an error on
BarData barData = new BarData(xData, barDataSet); ------this line
and the error is
BarData in BarData cannot be applied to (java.util.ArrayList <java.lang.String>,
com.github.mikephil.charting.data.BarDataSet)
How to resolve this error, please help
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab1, container, false);
TextView myTextView = (TextView)rootView.findViewById(R.id.textView5);
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/slabo.ttf");
myTextView.setTypeface(typeface);
barChart = (BarChart)rootView.findViewById(R.id.chart);
float yValues [] = {10, 20, 30, 40, 50};
String xValues [] = {"first", "second", "third", "four", "five"};
drawBarGraph(yValues,xValues);
return rootView;
}
private void drawBarGraph(float yValues[], String []xValues){
ArrayList<BarEntry> yData = new ArrayList<>();
for (int i = 0; i < yValues.length; i++){
yData.add(new BarEntry(yValues[i],i));
}
ArrayList<String> xData = new ArrayList<>();
for(int i = 0; i < xValues.length; i++){
xData.add(xValues[i]);
}
BarDataSet barDataSet = new BarDataSet(yData, "Cells");
barDataSet.setColors(ColorTemplate.COLORFUL_COLORS);
BarData barData = new BarData(xData, barDataSet);
barData.setValueTextSize(13f);
barData.setValueTextColor(Color.BLACK);
barChart.setData(barData);
barChart.invalidate();
}