我正在尝试使用基于MultipleTemperatureChart的3系列图表。 - 3系列具有相同的x值。 - 3 Y轴有不同的值,但我只使用2个Y轴,并且用黑色绘制一个,它没有出现。
如果我使用“addXYSeries(dataset,new String [] {”Temperatura“},x,y,Z),我想对TWO使用相同的比例;” * Z =比例,正确的比例,这是“第3”系列,所以我使用3作为比例。一切都很好,但规模不同。 但是如果我使用0作为比例,那么我的第3个系列具有与第一个系列相同的比例,O有一些问题: 图表显示OK,就像我想要的那样,但是当我尝试用AVD中的鼠标移动图表时它会停止!!!
有人可以帮助我吗? 感谢。
克劳迪奥
public Intent getIntent(Context context) {
String[] titles = new String[] { "Corrente" };
List<double[]> x = new ArrayList<double[]>();
List<double[]> y = new ArrayList<double[]>();
x.add(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
y.add(new double[] { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 });
int[] colors = new int[] { Color.BLUE, Color.RED, Color.GREEN };
PointStyle[] styles = new PointStyle[] { PointStyle.POINT, PointStyle.POINT, PointStyle.POINT };
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer(3);
renderer.setAxisTitleTextSize(16);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setPointSize(5f);
renderer.setMargins(new int[] { 20, 30, 15, 20 });
int length = colors.length; //length é o total de series
for (int i = 0; i < length; i++) {
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(colors[i]);
r.setPointStyle(styles[i]);
renderer.addSeriesRenderer(r);
}
for (int i = 0; i < length; i++) {
XYSeriesRenderer r = (XYSeriesRenderer) renderer.getSeriesRendererAt(i);
r.setLineWidth(2f);
}
//titulo do gráfico
renderer.setChartTitle("Curva 1");
renderer.setXTitle("Tempo/hrs");
renderer.setYTitle("Amperes/Graus °C" );
renderer.setAxesColor(Color.LTGRAY);
renderer.setLabelsColor(Color.LTGRAY);
renderer.setXLabelsColor(Color.LTGRAY);
renderer.setYLabelsColor(0, colors[0]);
renderer.setYLabelsColor(1, colors[1]);
// renderer.setYLabelsColor(2, Color.BLACK);
renderer.setYTitle("volts", 1);
renderer.setYAxisAlign(Align.RIGHT, 1);
renderer.setYLabelsAlign(Align.LEFT, 1);
//quantia de valores "ticks"
//renderer.setXLabels(24);
//renderer.setYLabels(10);
renderer.setXAxisMin(0);
renderer.setXAxisMax(12);
renderer.setYAxisMin(0);
renderer.setYAxisMax(32);
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setZoomButtonsVisible(true);
renderer.setPanLimits(new double[] { 0, 200, 0, 200 });
renderer.setZoomLimits(new double[] { 0, 200, 0, 200 });
renderer.setZoomRate(1.05f);
renderer.setShowGrid(true);
XYMultipleSeriesDataset dataset = buildDataset(titles, x, y);
//---- gráfico de tensão
y.clear();
y.add(new double[] { 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 });
addXYSeries(dataset, new String[] { "Tensão" }, x, y, 1);
// ----- gráfico de temperatura
y.clear();
y.add(new double[] { 0, 11, 10, 10, 11, 10, 10, 10, 9, 10, 10, 10 });
addXYSeries(dataset, new String[] { "Temperatura" }, x, y, 0);
for (int i = 0; i < length; i++) {
XYSeriesRenderer seriesRenderer = (XYSeriesRenderer) renderer.getSeriesRendererAt(i);
// ---- seleciona qual gráfico preencher
if (i == length - 1) {
FillOutsideLine fill = new FillOutsideLine(FillOutsideLine.Type.NONE); //NONE mostra valores sobre o gráfico
fill.setColor(Color.GREEN);
seriesRenderer.addFillOutsideLine(fill);
}
seriesRenderer.setLineWidth(2.5f);
seriesRenderer.setDisplayChartValues(true);
seriesRenderer.setChartValuesTextSize(10f);
}
Intent intent = ChartFactory.getCubicLineChartIntent(context, dataset, renderer, 0.3f,
"Average temperature");
return intent;
}
public Intent execute(Context context) {
// TODO Auto-generated method stub
return null;
}
}
这里记录错误:
11-01 18:31:20.154:D / dalvikvm(9567):GC_EXTERNAL_ALLOC在92ms内释放了731个对象/ 52992个字节 11-01 18:31:25.794:D / dalvikvm(9567):GC_FOR_MALLOC在59ms内释放了6115个对象/ 363864个字节 11-01 18:31:26.154:D / dalvikvm(9567):GC_FOR_MALLOC在57ms内释放了8229个对象/ 498936个字节 11-01 18:31:26.264:D / dalvikvm(9567):GetFieldID:无法找到字段Ljava / util / HashMap; .loadFactor:F 11-01 18:31:26.264:D / dalvikvm(9567):GetFieldID:无法找到字段Ljava / util / HashMap; .loadFactor:F 11-01 18:31:26.384:D / dalvikvm(9567):GetFieldID:无法找到字段Ljava / util / HashMap; .loadFactor:F 11-01 18:31:26.404:D / dalvikvm(9567):GetFieldID:无法找到字段Ljava / util / HashMap; .loadFactor:F 11-01 18:31:26.416:D / dalvikvm(9567):GetFieldID:无法找到字段Ljava / util / HashMap; .loadFactor:F 11-01 18:31:26.416:D / dalvikvm(9567):GetFieldID:无法找到字段Ljava / util / HashMap; .loadFactor:F 11-01 18:31:26.416:D / dalvikvm(9567):GetFieldID:无法找到字段Ljava / util / HashMap; .loadFactor:F 11-01 18:31:26.424:D / dalvikvm(9567):GetFieldID:无法找到字段Ljava / util / HashMap; .loadFactor:F 11-01 18:31:26.436:D / dalvikvm(9567):GetFieldID:无法找到字段Ljava / util / HashMap; .loadFactor:F 11-01 18:31:26.436:D / dalvikvm(9567):GetFieldID:无法找到字段Ljava / util / HashMap; .loadFactor:F 11-01 18:31:26.614:D / dalvikvm(9567):GC_FOR_MALLOC在60ms内释放了6683个对象/ 465000字节
这就是问题出现了。
11-01 18:31:30.658:D / AndroidRuntime(9567):关闭VM 11-01 18:31:30.658:W / dalvikvm(9567):threadid = 1:线程退出时未捕获异常(组= 0x4001d800) 11-01 18:31:30.678:E / AndroidRuntime(9567):致命异常:主要 11-01 18:31:30.678:E / AndroidRuntime(9567):java.lang.NullPointerException 11-01 18:31:30.678:E / AndroidRuntime(9567):at org.achartengine.chart.XYChart.toRealPoint(XYChart.java:877) 11-01 18:31:30.678:E / AndroidRuntime(9567):at org.achartengine.tools.Pan.apply(Pan.java:74) 11-01 18:31:30.678:E / AndroidRuntime(9567):at org.achartengine.TouchHandler.handleTouch(TouchHandler.java:119) 11-01 18:31:30.678:E / AndroidRuntime(9567):at org.achartengine.GraphicalView.onTouchEvent(GraphicalView.java:300) 11-01 18:31:30.678:E / AndroidRuntime(9567):在android.view.View.dispatchTouchEvent(View.java:3766) 11-01 18:31:30.678:E / AndroidRuntime(9567):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) 11-01 18:31:30.678:E / AndroidRuntime(9567):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) 11-01 18:31:30.678:E / AndroidRuntime(9567):at com.android.internal.policy.impl.PhoneWindow $ DecorView.superDispatchTouchEvent(PhoneWindow.java:1671) 11-01 18:31:30.678:E / AndroidRuntime(9567):at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) 11-01 18:31:30.678:E / AndroidRuntime(9567):在android.app.Activity.dispatchTouchEvent(Activity.java:2086) 11-01 18:31:30.678:E / AndroidRuntime(9567):at com.android.internal.policy.impl.PhoneWindow $ DecorView.dispatchTouchEvent(PhoneWindow.java:1655) 11-01 18:31:30.678:E / AndroidRuntime(9567):在android.view.ViewRoot.handleMessage(ViewRoot.java:1785) 11-01 18:31:30.678:E / AndroidRuntime(9567):在android.os.Handler.dispatchMessage(Handler.java:99) 11-01 18:31:30.678:E / AndroidRuntime(9567):在android.os.Looper.loop(Looper.java:123) 11-01 18:31:30.678:E / AndroidRuntime(9567):在android.app.ActivityThread.main(ActivityThread.java:4627) 11-01 18:31:30.678:E / AndroidRuntime(9567):at java.lang.reflect.Method.invokeNative(Native Method) 11-01 18:31:30.678:E / AndroidRuntime(9567):at java.lang.reflect.Method.invoke(Method.java:521) 11-01 18:31:30.678:E / AndroidRuntime(9567):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868) 11-01 18:31:30.678:E / AndroidRuntime(9567):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 11-01 18:31:30.678:E / AndroidRuntime(9567):at dalvik.system.NativeStart.main(Native Method)