具有空值的 MPAndroidChart [英] MPAndroidChart with null values

查看:38
本文介绍了具有空值的 MPAndroidChart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MPAndroidChart 并且非常享受.

I'm using the MPAndroidChart and am really enjoying it.

我有一个小"需要是我可以将空值放在条目"中.我正在监视系统服务器上的 apache 连接,我想看看它们是否已关闭(我放置空值的地方)或者它们是否只是没有连接 (0).

A 'little' need I have is that I can put null values to the 'entrys'. I'm monitoring the apache conections on servers of my system, and I would to see if they is down (where I put the null value) or if they just no conections (0).

我试过了,但 Entry 类不接受 'null' 作为显示消息的值:'The constructor Entry(null, int) is undefined'

I tried, but the Entry class don't accept 'null' as value showing the message: 'The constructor Entry(null, int) is undefined'

谢谢!

推荐答案

一个可能的解决方案是检查您收到的对象是否为空.如果对象为空,您甚至不创建 Entry 对象,而只是将其值设置为空.

A possible solution for you could be to check weather the object you received is null, or not. If the object is null, you don't even create an Entry object instead of just setting it's value to null.

示例:

// array that contains the information you want to display
ConnectionHolder[] connectionHolders = ...;

ArrayList<Entry> entries = new ArrayList<Entry>();
int cnt = 0;

for(ConnectionHolder ch : connectionHolders) {

    if(ch != null) entries.add(new Entry(ch.getNrOfConnections(), cnt));
    else {
        // do nothing
    }

    cnt++; // always increment
}

这将创建例如一个 LineChart,其中没有在 ConnectionHolder 对象为空的索引上绘制圆圈.

This would create e.g. a LineChart where no circles are drawn on indices where the ConnectionHolder object was null.

对于库的未来版本,我将尝试添加该功能以支持空值.

For a future release of the library, I will try to add the feature so that null values are supported.

这篇关于具有空值的 MPAndroidChart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆