Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
892 views
in Technique[技术] by (71.8m points)

android - MPAndroidChart with null values

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

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).

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

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Example:

// 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
}

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...