Mpandroidchart: LineChart null values problem.

Created on 22 Feb 2016  路  7Comments  路  Source: PhilJay/MPAndroidChart

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.

Most helpful comment

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

`
public void createDataSet(List data, int index) {
List 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);
        ...etc...
        lineData.addDataSet(dataSet);
    }
}

`

All 7 comments

use 2 datasets

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 .............. :(
~~~ or next version support ? i want. wnat!

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

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!

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

`
public void createDataSet(List data, int index) {
List 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);
        ...etc...
        lineData.addDataSet(dataSet);
    }
}

`

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

botondbutuza picture botondbutuza  路  3Comments

rohitkumarbhagat picture rohitkumarbhagat  路  3Comments

OnlyInAmerica picture OnlyInAmerica  路  3Comments

galex picture galex  路  3Comments

AiTheAnswer picture AiTheAnswer  路  3Comments