1
votes

I am having problems with MPAndroidChart. I am adding temperature and Humidity Data to the chart, but it always displays "no chart Data available". Anybody here who can see where my bug is? I would be super grateful!

//Create Data

                //set size of data
                int size = list.size();
                if (size > 24){ size = 24;}

                //create lists form temp and hum
                ArrayList<Entry> temps = new ArrayList<Entry>();
                ArrayList<Entry> hums = new ArrayList<Entry>();


                //fill list temp with values
                for (int i = 0; i < size; i++){
                    Entry value = new Entry(Math.round(list.get(list.size()-size + i).temp), (size-i));
                    temps.add(value);
                }

                //fill list hum with values
                for (int i = 0; i < size; i++){
                    Entry value = new Entry(Math.round(list.get(list.size()-size + i).hum), (size-i));
                    hums.add(value);
                }

                //other views on screen
                date.setText(dateString);
                time.setText(timeString);
                temp.setText(tempString);
                hum.setText(humString);


                //adding Data and description to array
                LineDataSet setTemp = new LineDataSet(temps, "Temperature");
                setTemp.setAxisDependency(YAxis.AxisDependency.LEFT);
                LineDataSet setHum = new LineDataSet(hums, "Humidity");
                setHum.setAxisDependency(YAxis.AxisDependency.LEFT);

                //adding Arrays to DataSet
                ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
                dataSets.add(setTemp);
                dataSets.add(setHum);
                ArrayList<String> xVals = new ArrayList<String>();

                //Adding x values of range size
                for (int i = 0; i < size; i++ ){
                    xVals.add(String.valueOf(i));
                }

                //add Data and create chart
                LineData data = new LineData(xVals, dataSets);
                chart.setData(data);
                chart.invalidate();

            }
        });
2
Try changing (size-i) to i in the Entry constructor. Let me know if that changes anything. - Philipp Jahoda
Hello Philipp, Thanks for taking a look at my problem. Sadly that did not resolve the problem. I must be using the code wrong somewhere. - Markus Schmitz
My best guess is that it has someting to do with your size variable. Have you tried removing it and see what happens? - Philipp Jahoda
Hey which version of MpAndroidchart are you using. I am using 2.1.5 and am not able to import ILineDataSet - Komal Gupta

2 Answers

0
votes

I was looking at this post long time. The only thing I can think about is this line:

Math.round(list.get(list.size()-size + i).hum

What's that .hum ? Could it generate an unsupported type for Entry? The resolution to this issue intrigues me so much since Mr. Phil J. did not found the answer yet.

0
votes

You need to call after you set the data:

 chart.invalidate();

to refresh the chart.