Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LineChart null values problem. #1498

Closed
epikxm opened this issue Feb 22, 2016 · 7 comments
Closed

LineChart null values problem. #1498

epikxm opened this issue Feb 22, 2016 · 7 comments

Comments

@epikxm
Copy link

epikxm commented Feb 22, 2016

HI.
I'm using this.

  1. my data count: 90
  2. can left-right scoll
int index = 0;
while (true) {
    if (index >= 90) break;
    if (index < 70 || index > 80) {
        values.add(new Entry(some_int_value, index));
    }
    index++;
}

I want this.. (A)
2

but now (B)
1

how to like (A) ?????
if can, I need example code

thanks for read.

@PhilJay
Copy link
Owner

PhilJay commented Feb 22, 2016

use 2 datasets

@PhilJay PhilJay closed this as completed Feb 22, 2016
@epikxm
Copy link
Author

epikxm commented Feb 22, 2016

2 datasets ?
really?
that is example.
I am already use 20 datasets.
if network problem, more 20 datasets create ? and again, again??
20, 40, 60, 80, 100 datasets ?
I'm quickly support null values.
......................or need another solution .............. :(

@licongqi
Copy link

@PhilJay
The same requirement and the same problem.
Will you support this or can you provide some other advices please?

@ali6p
Copy link

ali6p commented Feb 2, 2017

Using another dataset is not a nightmare :) Write recursive code to create dataset. Here is a quick pseudo example -Swift style :)-
...

let chartData = LineChartData()
for i in 0 ..< _myDataCollection.count {
            createDataSet(data: chartData, index: i, offset: 0)
}
self.lineChartView.data = chartData

....

createDataSet(data: LineChartData, index: Int, offset: Int) {
        
        var yValues : [ChartDataEntry] = [ChartDataEntry]()
        
        for i in offset ..< _myLabels.count {
            let point = _myDataCollection[index][i]
            if(point == 0) {
                if( (i + 1) < _myLabels.count) {
                	createDataSet(data: data, index: index, offset: i + 1)
                }
                break
            } else {
                yValues.append(ChartDataEntry(x: i, y: point))
            }
        }
        
        let ds = LineChartDataSet(values: yValues, label: nil)
        let lc = _myColorCollection[index] 
        ds.setColor(lc)
        ds.lineWidth = 1.0
        ...etc...
        data.addDataSet(ds)
    }

Thank you @PhilJay , you are awesome!

@mir47
Copy link

mir47 commented Oct 6, 2017

Thank you @ali6p your example really helped me. Here is my example code in java:

public void createDataSet(List<Double> data, int index) {
    List<Entry> entries = new ArrayList<>();

    for (int i = index; i < data.size(); i++) {
        if (data.get(i) != null) {
            double ypoint = data.get(i);
            Entry entry = new Entry((float) i, (float) ypoint);
            entries.add(entry);
            entriesAll.add(entry);

        } else if ((i+1) < data.size()) {
            if (data.get(i+1) != null) {
                createDataSet(data, i+1);
                break;
            }
        }
    }

    if (entries.size() > 0) {
        LineDataSet dataSet = new LineDataSet(entries, "");
        dataSet.setLineWidth(2);
        // ...
        lineData.addDataSet(dataSet);
    }
}

@danek130995
Copy link

@mir47 Thank you very much, helped me a lot.

@grapesurgeon
Copy link

Is there a way to show just one entry for the datasets in the legend?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants