androidmpandroidchart

Incomplete Line Chart with MPAndroidChart Using Double ArrayLists


I'm trying to draw a line chart using MPAndroidChart in my Android application. I have two ArrayList objects, Pn_points and Mn_points, which I add to yVals for plotting. However, when I run the program, the chart is drawn incompletely and doesn't match the desired output.

    lineChart = (LineChart) findViewById(R.id.graph);
int size = Pn_points.size();
ArrayList<Entry> yVals = new ArrayList<>();
TextView tv = (TextView) findViewById(R.id.textView);

for (int i = 0; i < size; i++) {
    double y2 = Math.round(Pn_points.get(i) / 1000 * 100.0) / 100.0;
    double x2 = Math.round(Mn_points.get(i) / 100000 * 100.0) / 100.0;
    float y = (float) y2;
    float x = (float) x2;
    yVals.add(new Entry(x, y));
}

LineDataSet sety = new LineDataSet(yVals, "yData");
LineData data = new LineData(sety);
lineChart.setData(data);
lineChart.animateX(3000);
lineChart.setDragEnabled(true);
lineChart.setScaleEnabled(true);

Problem:

The chart is not displaying all data points as expected. It appears incomplete compared to the desired chart image.

What I've Tried:

Verified the data in Pn_points and Mn_points to ensure they are correct. Adjusted the scaling and animation settings in the chart. Searched through the MPAndroidChart documentation for possible issues. Questions:

What could be causing the chart to display incompletely? How can I ensure all data points are plotted correctly on the line chart?


Solution

  • I'd guess that in a line chart (that represents the graph of a function), there can't exist two y values for one x value. Your graph can't change its direction.