gpt4 book ai didi

java - 在布局中加载图表

转载 作者:行者123 更新时间:2023-11-30 03:36:05 24 4
gpt4 key购买 nike

我尝试在布局中加载图形,使用 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 类而导致编译错误。我怎样才能将另一个类中的方法用于另一个类中?这可能是我知道的对象编程的一个基本问题,但我在这里问这个也是为了知道我是否打算在布局中加载 grahp 图表。我在 Eclipse 工作。谢谢

最佳答案

buildRendererAbstractDemoChart 中的 protected 方法。但是在AChartExampleActivity示例 buildRenderer 是执行此操作的私有(private)方法:

private XYMultipleSeriesRenderer buildRenderer(int[] colors,PointStyle[] styles) 
{
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
setRenderer(renderer, colors, styles);
return renderer;
}

你见过GeneratedChartDemo吗?代码?它以这种方式创建渲染器:

private XYMultipleSeriesRenderer getDemoRenderer() {

XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(16);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setPointSize(5f);
renderer.setMargins(new int[] {20, 30, 15, 0});
...

我认为您应该更改初始化 XYMultipleSeriesRenderer 的方式。

关于java - 在布局中加载图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16627373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com