My code:
public BarData getBarData(String fieldName) {
ArrayList entries = new ArrayList<>();
entries.add(new BarEntry
It's working version of Barchart with new BarData(datasets); here is code with xml. you needto edit tools:context= in xml.
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import java.util.ArrayList;
public class SubActivity_05 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub_05);
BarChart bchart = (BarChart) findViewById(R.id.chart1);
ArrayList yVals1 = new ArrayList();
for (int i = (int) 0; i < 10 + 1; i++) {
float val = (float) (Math.random());
yVals1.add(new BarEntry(i, val));
}
BarDataSet set1;
set1 = new BarDataSet(yVals1, "The year 2017");
set1.setColors(ColorTemplate.MATERIAL_COLORS);
ArrayList dataSets = new ArrayList();
dataSets.add(set1);
BarData data = new BarData(dataSets);
data.setValueTextSize(10f);
data.setBarWidth(0.9f);
bchart.setTouchEnabled(false);
bchart.setData(data);
}
xml
It's good to check out tutorial page. https://github.com/PhilJay/MPAndroidChart/wiki/Getting-Started