안드로이드 개발 질문/답변
(글 수 45,052)
achartengine를 이용해 그래프를 구현하고 있습니다...
구글링을 통해 라이브러리도 다운받고, 소스도 찾아보고해서 그래프는 구현이 되었는데...
이 그래프를 예제에 나와있는 Intent가 아니라 LinearLayout에 addview로 추가하려니 잘 안됩니다..
StatsLineChart.java
public class StatsLineChart extends AbstractDemoChart { .... public GraphicalView execute(Context context){ String[] titles = new String[] { "Graph A","Graph B" }; List<double[]> dates = new ArrayList<double[]>(); List<double[]> values = new ArrayList<double[]>(); int length = titles.length; double[] dateValues = new double[] { 1,2,3,4,5,6,7,8,9,10,11,12}; dates.add(dateValues); dates.add(dateValues); values.add(new double[] { 1, 2, 3, 4, 5, 7, 8, 9, 10, 10.5, 5, 9}); values.add(new double[] { 3,10, 5, 8, 7, 7, 2, 10, 5, 11, 10, 11}); int[] colors = new int[] { Color.RED,Color.GREEN }; PointStyle[] styles = new PointStyle[] { PointStyle.CIRCLE,PointStyle.DIAMOND }; XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles); setChartSettings(renderer, "2012 년", "Date", "", 1,12, 0, 12, Color.GREEN, Color.RED); renderer.setXLabels(13); renderer.setYLabels(10); return ChartFactory.getLineChartView(context, buildDateDataset(titles, dates, values), renderer); } }
GraphDemoActivity.java
public class GraphDemoActivity extends Activity { private LinearLayout linear_chart; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); linear_chart = (LinearLayout)findViewById(R.id.linear_statis); GraphicalView view = new HappyStatsChart().execute(this); linear_chart.removeAllViews(); linear_chart.addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); view.repaint(); }
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:weightSum="100" android:background="@color/default_bg_pink" > <LinearLayout android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="10" android:weightSum="10" android:background="@color/default_bg_pink" > <TextView android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="10" ............ /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="80" android:layout_margin="10dip" android:background="@color/default_bg_pink" > <LinearLayout android:id="@+id/linear_statis" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="80" android:background="@drawable/border_pink_listview_selector" > </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="10" android:weightSum="10" android:background="@color/default_bg_pink" > ......... </LinearLayout> </LinearLayout>
실행시켜보면 빈화면만 뜹니다.
main.xml에 LinearLayout하나만 뒀을 때는 정상적인 결과가 나옵니다..
addview할 때 잘못된 것같긴 한데....
아시는 분 답변 부탁합니다....