如何绘制贸易线在散点图在Android? [英] How to draw trade line on Scatter Chart in android?

查看:603
本文介绍了如何绘制贸易线在散点图在Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发需要散点图的应用程序。对于散点图,我使用Apache aChartEngine库来绘制散点图,但是我需要在散点图上绘制Trade Line。 aChartEngine不支持交易行功能。没有任何人有Idea如何绘制贸易线在散点图在Android中。

这是我的代码。

  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 for(int i = 0; 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]));
} //二次模型

Log.d(TAG,y size ..+ y.length);

t.setValues(y,x);
System.out.println(t.predict(12)); //当x = 12时,y应为...,例如143.61380202745192

Log.e(TAG,+ t.predict(12)); }

使用此代码如何在图形上绘制一条线?

解决方案

您可以使用 Apache



对于线性,多项式,指数,对数和幂趋势线
$ b。如果您需要更多资源,您可以使用这些资源。














$ b

this SO



然后,您可以简单地向yout图表添加新的系列,使用从趋势线派生的值。


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.

这篇关于如何绘制贸易线在散点图在Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆