I am developing application which requires scatter chart. For scatter chart I am using Apache aChartEngine library to draw scatter chart but I needto draw Trade line also on that scatter chart. aChartEngine is not supports Trade line functionality.So anyone has Idea how to draw Trade line on scatter chart in android.
Edit
Here is my code.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TrendLine t = new PolyTrendLine(2);
Random rand = new Random();
// double[] x = new double[10*10];
double[] x = {4,6.5,8,10,15.5};
double[] err = new double[x.length];
double[] y = new double[x.length];
Log.d(TAG,""+x.length);
for (int i=0; i<x.length; i++) { x[i] = 1000*rand.nextDouble(); }
for (int i=0; i<x.length; i++) { err[i] = 100*rand.nextGaussian(); }
for (int i=0; i<x.length; i++)
{
y[i] = x[i]*x[i]+err[i];
// y = -0.0004x2 + 0.3133x - 6.4081
Log.d(TAG,"y y[i].."+y[i]);
//Log.e(TAG,"t.predict..."+t.predict(y[i]));
} // quadratic model
Log.d(TAG,"y size.."+y.length);
t.setValues(y,x);
System.out.println(t.predict(12)); // when x=12, y should be... , eg 143.61380202745192
Log.e(TAG,""+t.predict(12)); }
Using this code how can I draw a line on my graph?
You could use Apache Commons math.
For linear, polynomial, exponential, logarithmic, and power trend lines OLSMultipleLinearRegression is all you need.
In this S.O. previous question, you can found the code for the trend lines.
Then you can simply add new series to yout chart with values derived from the trendline.