How to draw trade line on Scatter Chart in android?

↘锁芯ラ 提交于 2019-12-25 02:22:17

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/22808204/how-to-draw-trade-line-on-scatter-chart-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!