几天来,我一直在使用AchartEngine。我修改了 TrignometricFunctionsChart 以显示各种可能的图表。现在我希望用户输入函数并为该函数绘制图表。为此,我需要一个 EditText 和一个图表内的按钮。我尝试阅读Android:我正在使用 AChartEngine 图形库,但无法将 achartengine 的图形视图与 android xml 集成?却无法完成任务。我尝试编辑 XYChartBuilder(包含在 XML 文件中的唯一图表),但无法将 TrignometricFunctionsChart 插入其中。
我不知道如何迁移这段代码:
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);
}