我已经使用 AChartEngine 几个星期了,截至上周一切正常。我真的找不到我所做的更改,但现在该图表并没有出现在我的屏幕上。我Activity
使用图形的空布局属性进行初始化。在某个时刻,用户读入输入,然后更新图表。
这是我的图表的 XML 代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="@drawable/eti1"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="11" >
<LinearLayout
android:id="@+id/wavesOptions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:gravity="center"
android:weightSum="8" >
<!--
Unrelated spinners/checkboxes
-->
<ScrollView
android:layout_width="fill_parent"
android:id="@+id/graphScroll"
android:layout_height="wrap_content"
android:layout_above="@id/wavesOptions"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/graph1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
下面是我在 Eclipse 中显示的布局图片。我视图顶部的蓝色框框是我的图表所在的位置。它看起来很小,但我wrap_content
用于高度,所以它应该匹配它的父级。当我在我的 java 代码中将图表设置为该视图时,根本没有任何变化。所有复选框都已更新,并正确添加了新的微调器。
下面是我的 .java 文件中的代码:
public void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView( R.layout.waves );
renderer = new XYMultipleSeriesRenderer( 2 );
}
一旦用户调用要绘制的信息,数据就会存储在一个数组中waveResults
,然后调用该方法updateGraph()
。graphView设置为布局的重要部分一直在底部:
public void updateGraph() {
int num = 166;
renderer = new XYMultipleSeriesRenderer( 2 );
dataset = new XYMultipleSeriesDataset();
// NetV1
netV1Series = new XYSeries( "Net V1", 0 );
// NetV2
netV2Series = new XYSeries( "Net V2", 0 );
// NetV3
netV3Series = new XYSeries( "Net V3", 0 );
// VDI1
// VDI2
// VDI3
if( spinnerChoice == 0 ) {
vdi1Series = new XYSeries( "Diff V1", 1 );
vdi2Series = new XYSeries( "Diff V2", 1 );
vdi3Series = new XYSeries( "Diff V3", 1 );
} else {
vdi1Series = new XYSeries( "Curr 1", 1 );
vdi2Series = new XYSeries( "Curr 2", 1 );
vdi3Series = new XYSeries( "Curr 3", 1 );
}
dataset.addSeries( netV1Series );
dataset.addSeries( netV2Series );
dataset.addSeries( netV3Series );
dataset.addSeries( vdi1Series );
dataset.addSeries( vdi2Series );
dataset.addSeries( vdi3Series );
netV1Renderer = new XYSeriesRenderer();
netV1Renderer.setColor( Color.WHITE );
netV2Renderer = new XYSeriesRenderer();
netV2Renderer.setColor( Color.YELLOW );
netV3Renderer = new XYSeriesRenderer();
netV3Renderer.setColor( Color.BLUE );
vdi1Renderer = new XYSeriesRenderer();
vdi1Renderer.setColor( Color.RED );
vdi2Renderer = new XYSeriesRenderer();
vdi2Renderer.setColor( Color.CYAN );
vdi3Renderer = new XYSeriesRenderer();
vdi3Renderer.setColor( Color.GRAY );
renderer.addSeriesRenderer( netV1Renderer );
renderer.addSeriesRenderer( netV2Renderer );
renderer.addSeriesRenderer( netV3Renderer );
renderer.addSeriesRenderer( vdi1Renderer );
renderer.addSeriesRenderer( vdi2Renderer );
renderer.addSeriesRenderer( vdi3Renderer );
renderer.setAxesColor( Color.DKGRAY );
renderer.setPointSize( 14 );
renderer.setApplyBackgroundColor( true );
renderer.setBackgroundColor( Color.BLACK );
renderer.setMarginsColor( Color.BLACK );
renderer.setChartTitle( "Waves" );
renderer.setShowGrid( true );
renderer.setXLabels( 10 );
renderer.setYLabels( 7 );
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setYLabelsAlign(Align.RIGHT, 0);
renderer.setZoomButtonsVisible( false );
renderer.setPanEnabled( false, false );
renderer.setZoomEnabled( false, false );
renderer.setLabelsColor(Color.WHITE);
renderer.setXLabelsColor(Color.WHITE);
renderer.setYLabelsColor(0, Color.WHITE);
renderer.setYLabelsColor(1, Color.WHITE);
if( spinnerChoice == 0 ) {
renderer.setYTitle("Diff Volts", 1);
} else {
renderer.setYTitle( "Current", 1 );
}
renderer.setYTitle( "Net Volts", 0 );
renderer.setYAxisAlign( Align.LEFT, 0 );
renderer.setYAxisAlign(Align.RIGHT, 1);
renderer.setYLabelsAlign(Align.LEFT, 1);
graphLayout = (LinearLayout) findViewById( R.id.graph1 );
graphLayout.removeAllViews();
Log.i( "GRAPH", "After Remove" );
graphView = ChartFactory.getCubeLineChartView( getApplicationContext(), dataset, renderer, 0.3f);
Log.i( "GRAPH", "Before addView" );
graphLayout.addView(graphView);
Log.i( "GRAPH", "After addView" );
}
在updateGraph()
方法结束时,三个Log
调用都显示在我的 LogCat 中。