我尝试在布局中加载图形,使用 AChartEngine 的数学图形。我从该站点下载了一个演示 zip,我意识到我需要类似 sin-cosin grahp 样式的东西。所以,这是我写的代码:
package com.myproject;
import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import com.myproject.clases.AbstractDemoChart;
public class MainActivity extends Activity {
private WebView ventana;
private GraphicalView mChartView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
XYMultipleSeriesDataset mDataset = null;//this line causes runtime error but I will see this issue later.
int [] colors = new int[] { Color.BLUE, Color.CYAN };
PointStyle[] styles = new PointStyle[] { PointStyle.POINT, PointStyle.POINT };
XYMultipleSeriesRenderer mRenderer = buildRenderer(colors, styles);
LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
mChartView = ChartFactory.getLineChartView(this, mDataset, mRenderer);
layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
}
但线
XYMultipleSeriesRenderer mRenderer = buildRenderer(colors, styles);
由于方法 buildRenderer() 属于 AbstractDemoChart 类,导致编译错误。如何从另一个类中获取方法以在另一个类中使用?这可能是我知道的对象编程的一个基本问题,但我在这里问这个也知道我是否在打算在布局中加载图形图表方面做得很好。我在 Eclipse 中工作。谢谢