MPAndroidChart空值 [英] MPAndroidChart with null values

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

问题描述

我使用MPAndroidChart( https://github.com/PhilJay/MPAndroidChart )和真的很享受它。

I'm using the MPAndroidChart (https://github.com/PhilJay/MPAndroidChart) and am really enjoying it.

一个'小'我需要有就是我可以把空值到entrys。我监测的apache conections在我的系统的服务器,我会看看他们是否已关闭(在这里我把空值),或者如果他们只是没有conections(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类不接受'空'的值显示一条消息:构造函数项(空,INT)未定义

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

谢谢!

推荐答案

为你一个可能的解决办法是为查询天气,您收到的对象为null ,还是不行。如果对象为空,你甚至不创建一个输入的对象,而不是仅仅设定它的值设置为null。

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
}

这将创建如一个线型图在没有圆圈上的指数,其中 ConnectionHolder 对象为null绘制。

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天全站免登陆