1

I am using MPAndroid chart to plot a cubic graph using a few points. Currently, the library joins those points and plots a smooth graph. The code I am using is :

ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < count; i++) {
    xVals.add((1990 +i) + "");
}

ArrayList<Entry> vals1 = new ArrayList<Entry>();

for (int i = 0; i < count; i++) {
    float mult = (range + 1);
    float val = (float) (Math.random() * mult) + 20;// + (float)
                                                   // ((mult *
                                                   // 0.1) / 10);
    vals1.add(new Entry(val, i));
}

// create a dataset and give it a type
LineDataSet set1 = new LineDataSet(vals1, "DataSet 1");
    set1.setDrawCubic(true);
LineData data = new LineData(xVals, set1);

I would like to get a list of ALL the intermediate points that the library plots between the ones given by me in order to obtain a smooth curve in an array. Is there any way to achieve this ?

Thanks

Junaid
  • 4,822
  • 2
  • 21
  • 27
Shivam Bhalla
  • 1,879
  • 5
  • 35
  • 63

2 Answers2

1

In the class LineChartRenderer.java , drawCubic() is called. In that function at the bottom when it is rendering the path there you can find all the points that are used in plotting a smooth curve. See if it helps you.

umesh lohani
  • 162
  • 1
  • 4
  • 13
  • Yes I did see that, but I didn't understand how to extract a collection of all points from that function. Could you provide some code to explain how to do this if possible ? – Shivam Bhalla Mar 12 '15 at 08:20
  • You have a path object named spline. Extracting all points is nothing because a Path contains infinite number of points but yes you can use this path object for extracting as many points on the path as possible by giving equal intervals over the path.For finding points follow @hasanghaforian answer on the below link. http://stackoverflow.com/questions/7972780/how-do-i-find-all-the-points-in-a-path-in-android – umesh lohani Mar 12 '15 at 08:51
0

For Curve(Smooth edge line)dataset mode is CUBIC_BEZIER.

    LineDataSet lds=new LineDataSet(water_entryline,"Levels");
    lds.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    LineData ld=new LineData();
    ld.addDataSet(lds);
    linechart.setData(ld);
    linechart.animateY(1000, Easing.EasingOption.Linear);
    linechart.invalidate();

For gettting the value from linechart

 linechart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
        @Override
        public void onValueSelected(Entry e, Highlight h) {
            Log.d("value","X: "+e.getX()+" Y: "+e.getY());
        }

        @Override
        public void onNothingSelected() {

        }
    });
Raj
  • 477
  • 5
  • 20