我正在尝试使用AChartEngine创建图表,除非我似乎无法使其工作。我的代码如下。注意:Default2
是在用户登录之前阻止视图的叠加层,设置Visibility(8)
表示它已折叠。 historyGraph
是一个RelativeLayout,几乎可以填满整个屏幕。
//TODO: Remove and place in Void currently at end of onCreate()
Toast.makeText(getApplicationContext(), "Finally", 1).show();
default2.setVisibility(8);
GraphicalView chartView;
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setPanEnabled(false);
renderer.setLabelsColor(Color.BLACK);
renderer.setShowLabels(true);
renderer.setChartTitle("Test");
XYSeriesRenderer r1 = new XYSeriesRenderer();
r1.setColor(Color.BLUE);
XYSeriesRenderer r2 = new XYSeriesRenderer();
r2.setColor(Color.RED);
renderer.addSeriesRenderer(r1);
renderer.addSeriesRenderer(r2);
XYMultipleSeriesDataset data = new XYMultipleSeriesDataset();
XYSeries series1 = new XYSeries("Series 1");
XYSeries series2 = new XYSeries("Series 2");
double[] first = {5,4,3,4,5};
double[] second = {10, 8, 6, 8, 10};
for (double i = 0; i < 5; i++) {
series1.add(i, first[(int) i]);
series2.add(i, second[(int) i]);
}
data.addSeries(series1);
data.addSeries(series2);
chartView = ChartFactory.getLineChartView(getApplicationContext(), data, renderer);
historyGraph.addView(chartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
historyGraph.setBackgroundColor(Color.BLUE);
Toast.makeText(getApplicationContext(), "Done", 1).show();
任何人都明白为什么这不起作用?