这个问题已经在这里有了答案:????????????>????????????How to check if activity is in foreground or in visible background?????????????????????????????????????22个
这是我用于使用MPAndroid库版本3的组bar_chart的代码.此代码不起作用.没有崩溃和错误日志,仍在加载图形,并且没有数据显示.帮我找出毛病
List entriesGroup1 = new ArrayList<>();
List entriesGroup2 = new ArrayList<>();
List entriesGroup3 = new ArrayList<>();
entriesGroup1.add(new BarEntry(0, 8f));
entriesGroup1.add(new BarEntry(1, 2f));
entriesGroup1.add(new BarEntry(2, 5f));
entriesGroup1.add(new BarEntry(3, 20f));
entriesGroup1.add(new BarEntry(4, 15f));
entriesGroup1.add(new BarEntry(5, 19f));
entriesGroup2.add(new BarEntry(0, 6f));
entriesGroup2.add(new BarEntry(1, 10f));
entriesGroup2.add(new BarEntry(2, 5f));
entriesGroup2.add(new BarEntry(3, 25f));
entriesGroup2.add(new BarEntry(4, 4f));
entriesGroup2.add(new BarEntry(5, 17f));
entriesGroup3.add(new BarEntry(0, 9f));
entriesGroup3.add(new BarEntry(1, 1f));
entriesGroup3.add(new BarEntry(2, 15f));
entriesGroup3.add(new BarEntry(3, 13f));
entriesGroup3.add(new BarEntry(4, 40f));
entriesGroup3.add(new BarEntry(5, 25f));
BarDataSet set1 = new BarDataSet(entriesGroup1, "Group 1");
BarDataSet set2 = new BarDataSet(entriesGroup2, "Group 2");
BarDataSet set3 = new BarDataSet(entriesGroup3, "Group 3");
final ArrayList labels = new ArrayList();
labels.add("2016");
labels.add("2015");
labels.add("2014");
labels.add("2013");
labels.add("2012");
labels.add("2011");
IAxisValueFormatter formatter = new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
if((int) value < 0 || (int) value >= labels.size()){
return "";
}else{
return labels.get((int) value);
}
}
// we don't draw numbers, so no decimal digits needed
@Override
public int getDecimalDigits() { return 0; }
};
set1.setColor(Color.parseColor("#cd5080"));
set2.setColor(Color.parseColor("#0d5080"));
set3.setColor(Color.parseColor("#fc5080"));;
float groupSpace = 0.06f;
float barSpace = 0.02f; // x2 dataset
float barWidth = 0.45f; // x2 dataset
// (0.02 + 0.45) * 2 + 0.06 = 1.00 -> interval per "group"
XAxis xAxis = barChart.getXAxis();
xAxis.setCenterAxisLabels(true);
xAxis.setGranularity(1f); // minimum axis-step (interval) is 1
xAxis.setValueFormatter(formatter);
BarData data = new BarData(set1, set2, set3);
data.setBarWidth(barWidth); // set the width of each bar
barChart.setData(data);
barChart.groupBars(2016, groupSpace, barSpace);
barChart.invalidate(); // refresh
barChart.animateY(5000);
Nb:因为我被禁止提出新问题,所以我已经编辑了当前的问题.但这对我很重要.感谢大家.