MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

LineChart null values problem.

Open epikxm opened this issue 10 years ago • 7 comments

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.

epikxm avatar Feb 22 '16 16:02 epikxm

use 2 datasets

PhilJay avatar Feb 22 '16 17:02 PhilJay

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 .............. :(

epikxm avatar Feb 22 '16 17:02 epikxm

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

licongqi avatar Feb 24 '16 09:02 licongqi

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!

ali6p avatar Feb 02 '17 12:02 ali6p

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);
    }
}

mir47 avatar Oct 06 '17 11:10 mir47

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

danek130995 avatar Nov 11 '19 08:11 danek130995

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

grapesurgeon avatar Jun 12 '20 11:06 grapesurgeon