MPAndroid组条形图未显示

MPAndroid组条形图未显示,第1张

概述这个问题已经在这里有了答案:            >            Howtocheckifactivityisinforegroundorinvisiblebackground?                                    22个这是我用于使用MPAndroid库版本3的组bar_cha

这个问题已经在这里有了答案:            >            How to check if activity is in foreground or in visible background?                                    22个
这是我用于使用MPAndroID库版本3的组bar_chart的代码.此代码不起作用.没有崩溃和错误日志,仍在加载图形,并且没有数据显示.帮我找出毛病

        List<barEntry> entrIEsGroup1 = new ArrayList<>();        List<barEntry> entrIEsGroup2 = new ArrayList<>();        List<barEntry> 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<String> labels = new ArrayList<String>();        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:因为我被禁止提出新问题,所以我已经编辑了当前的问题.但这对我很重要.感谢大家.

解决方法:

这不是我的答案,我以前看过这些问题,并在我的应用程序中实现,它像一种魅力.找不到原始答案的链接,所以我要张贴我使用的代码.
您可以使用ActivitylifecycleCallbacks:

public class AppTransitionStatus implements Application.ActivitylifecycleCallbacks {private static final long MAX_BACKGROUND_TIME = 2000;private Timer timer;private TimerTask task;private boolean isBackground;private final Transition Transition;private voID goToForeground(Activity iActivity) {    Transition.appToForeground(iActivity);}private voID goToBackground() {    Transition.appToBackground();}private voID stopTimer() {    if (task != null) task.cancel();    if (timer != null) timer.cancel();}public AppTransitionStatus(@NonNull Transition Transition) {    this.Transition = Transition;}@OverrIDepublic voID onActivityCreated(Activity activity, Bundle bundle) {}@OverrIDepublic voID onActivityStarted(Activity activity) {}@OverrIDepublic voID onActivityResumed(Activity activity) {    if (isBackground) {        goToForeground(activity);    }    stopTimer();    isBackground = false;}@OverrIDepublic voID onActivityPaused(Activity activity) {    timer = new Timer();    task = new TimerTask() {        public voID run() {            isBackground = true;            goToBackground();        }    };    timer.schedule(task, MAX_BACKGROUND_TIME);}@OverrIDepublic voID onActivityStopped(Activity activity) {}@OverrIDepublic voID onActivitySaveInstanceState(Activity activity, Bundle bundle) {}@OverrIDepublic voID onActivityDestroyed(Activity activity) {}public interface Transition {    voID appToForeground(Activity iActivity);    voID appToBackground();}}

然后可以在您的应用程序类中注册

 registeractivitylifecycleCallbacks(new AppTransitionStatus(new AppTransitionStatus.Transition() {        @OverrIDe        public voID appToForeground(Activity iActivity) {            Log.d("Transition", "App in Foreground");        }        @OverrIDe        public voID appToBackground() {            Log.d("Transition", "App in Background");        }    }));
总结

以上是内存溢出为你收集整理的MPAndroid组条形图未显示全部内容,希望文章能够帮你解决MPAndroid组条形图未显示所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1095214.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存