2012-08-03 71 views
0

我一直在玩AchartEngine一两天了。我修改了TrignometricFunctionsChart以显示各种可能的图形。现在我想让用户输入函数并绘制该函数的图形。为此,我需要一个EditText和一个Button里面的图表。我试着读Android: I am using AChartEngine library for graphs, but not able to integrate achartengine's graph view with android xml?却无法完成任务。我尝试编辑XYChartBuilder(唯一包含在XML文件中的图表),但无法将TrignometricFunctionsChart插入它。Achartengine:以XML显示视图

我不知道如何迁移这个代码片段:

public Intent execute(Context context) { 
String[] titles = new String[] { "sin", "cos" }; 
List<double[]> x = new ArrayList<double[]>(); 
List<double[]> values = new ArrayList<double[]>(); 
int step = 4; 
int count = 360/step + 1; 
x.add(new double[count]); 
x.add(new double[count]); 
double[] sinValues = new double[count]; 
double[] cosValues = new double[count]; 
values.add(sinValues); 
values.add(cosValues); 
for (int i = 0; i < count; i++) { 
    int angle = i * step; 
    x.get(0)[i] = angle; 
    x.get(1)[i] = angle; 
    double rAngle = angle/57.295779513082; 
    sinValues[i] = rAngle; 
    cosValues[i] = 0.25*rAngle; 
} 
int [] colors = new int[] { Color.BLUE, Color.CYAN }; 
PointStyle[] styles = new PointStyle[] { PointStyle.POINT, PointStyle.POINT }; 
XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles); 
setChartSettings(renderer, "Trigonometric functions", "X (in degrees)", "Y", 0, 360, -1, 1, 
    Color.GRAY, Color.LTGRAY); 
renderer.setXLabels(20); 
renderer.setYLabels(10); 
return ChartFactory.getLineChartIntent(context, buildDataset(titles, x, values), renderer); 
} 

回答

0

开始与嵌入图表为布局的最好的地方正是你所提到的一个。我建议更仔细地阅读演示代码。

确保您了解演示图表如何从其父类继承行为。例如,buildRenderer(),buildDataset()等都位于AbstractDemoChart中。

+0

我尝试了很多我的朋友。正如我所提到的,我甚至修改了代码来显示复杂函数的图形。我唯一无法理解的是如何将上面的代码插入到XYChartBuilder中。 – 2012-08-03 13:38:00