【发布时间】:2014-05-13 13:04:08
【问题描述】:
我正在开发需要散点图的应用程序。对于散点图,我使用 Apache aChartEngine 库来绘制散点图,但我还需要在该散点图上绘制交易线。 aChartEngine 不支持交易线功能。所以任何人都有想法如何在 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<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)); }
如何使用此代码在我的图表上画一条线?
【问题讨论】:
标签: android charts achartengine scatter-plot