我正在試圖做一個基於MultipleTemperatureChart的3系列圖。 - 3系列具有相同的x值。 - 3個Y軸有不同的值,但我只使用2個Y軸,並繪製一個黑色,它沒有出現。Achartengine - 如何在兩個系列中使用相同的比例尺?
如果我使用「addXYSeries(dataset,new String [] {」Temperatura「},x,y,Z),我希望使用相同的比例來表示TWO;」 * Z =比例,正確的比例,這是「第3」系列,所以我用3作爲比例。一切都很好,但規模是不同的。 但是,如果我使用0作爲一個比例,以便我的第3個系列與第1個系列具有相同的比例,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釋放對象731 /在52992字節92ms 11-01 18:31:25.794:D/dalvikvm(9567):GC_FOR_MALLOC釋放6115個對象/ 363864字節59ms 11-01 18:31:26.154:D/dalvikvm(9567):GC_FOR_MALLOC釋放8229個對象/ 498936字節在57ms 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:unable找到字段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釋放6683個對象/ 465000字節在60ms
這裏出現問題。
11-01 18:31:30.658 D/AndroidRuntime(9567):關閉VM 11-01 18:31:30.658:W/dalvikvm(9567):threadid = 1:線程退出時未捕獲的異常E/AndroidRuntime(9567):java.lang.NullPointerException 11-bit:0x4001d800) 11-01 18:31:30.678:E/AndroidRuntime(9567):FATAL EXCEPTION:main 11-01 18:31:30.678: 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/Androi dRuntime(9567):在org.achartengine.GraphicalView.onTouchEvent(GraphicalView。java:300) 11-01 18:31:30.678:E/AndroidRuntime(9567):at android.view.View.dispatchTouchEvent(View.java:3766) 11-01 18:31:30.678:E/AndroidRuntime (android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)):at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) 11-01 18:31:30.678:E/AndroidRuntime(9567) 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):在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):at android.view.ViewRoot.handleMessage(ViewRoot。 java:1785) 11-01 18:31:30.678:E/AndroidRuntime(9567):at 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) E/AndroidRuntime(9567):在java中(在本地方法) 11-01 18:31:30.678:E/AndroidRuntime .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):在dalvik.system.NativeStart.main(本地方法)
發佈整個代碼,例如任何人都可以看到您的類擴展了AbstractDemoChart。 –
謝謝@Dan 我使用的是原來的AbstractDemoChart,只是改了名字。 就像這[https://code.google.com/p/achartengine/source/browse/trunk/achartengine/demo/org/achartengine/chartdemo/demo/chart/AbstractDemoChart.java] –
請分享一些日誌。 –