【问题标题】:Achartengine: displaying view in XMLAchartengine:以 XML 显示视图
【发布时间】:2012-08-03 21:35:26
【问题描述】:

我已经用 AchartEngine 玩了几天了。我修改了 TrignometricFunctionsChart 以显示各种可能的图表。现在我希望用户输入函数并为该函数绘制图表。为此,我需要一个 EditText 和一个图表内的按钮。我尝试阅读Android: I am using AChartEngine library for graphs, but not able to integrate achartengine's graph view with android xml? 但无法完成任务。我尝试编辑 XYChartBuilder(包含在 XML 文件中的唯一图表),但无法将 TrignometricFunctionsChart 插入其中。

我不知道如何迁移这段 sn-p 代码:

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);
}

【问题讨论】:

    标签: android xml achartengine


    【解决方案1】:

    开始将图表嵌入到布局中的最佳位置正是您提到的那个。我建议您更仔细地阅读演示代码。

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

    【讨论】:

    • 我朋友试过很多次。正如我所提到的,我什至修改了代码以显示复杂函数的图形。我唯一不明白的是如何将上面的代码插入到 XYChartBuilder 中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 2020-11-16
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多