안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요-
책을 보면서 예제 문제들을 가지고 메뉴를 만들어서 하려고 하는데
1.리스트 뷰 출력
2.파이차트 출력
할려고 합니다.
1번은 되는데 2번이 안되더라구요-
왜 안되는지 모르겠습니다.
2번의 경우에는 독립적으로 할때는 분명 잘 되는데
메뉴에 넣어서 할려니까 안되네요 ㅠ
achartengine 라이브러리는 이용해서 만들구요
소스는 다음과 같습니다.
public class chart extends Activity {
private chartView mChartView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.graph);
LinearLayout dynamicLayout = (LinearLayout)findViewById(R.id.layout);
mChartView = new chartView(this);
dynamicLayout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
mChartView.makeChart();
}
}
public class chartView extends View{
private PieChart mPieChart = null;
private chart parent;
public chartView(Context context)
{
super(context);
setFocusable(true);
parent = (chart)context;
}
public chartView(Context context,AttributeSet attrs)
{
super(context,attrs);
setFocusable(true);
parent = (chart)context;
}
public chartView(Context context,AttributeSet attrs, int defaultStyle)
{
super(context, attrs, defaultStyle);
setFocusable(true);
parent = (chart)context;
}
@Override
protected void onDraw(Canvas canvas)
{
int width = getMeasuredWidth();
int height = getMeasuredHeight();
if(mPieChart != null) mPieChart.draw(canvas,0,0,width,height, null);
}
public void makeChart()
{
//value color text
double[] values = new double[] {10, 20, 30, 40};
int [] colors = new int[] {Color.CYAN,Color.MAGENTA,Color.RED,Color.YELLOW};
String[] texts = new String[] {"SAMPLE1", "SAMPEL2", "SAMPLE3", "SAMPLE4" };
DefaultRenderer renderer = new DefaultRenderer();//색깔 관련 부분
for(int color : colors){
SimpleSeriesRenderer ssr = new SimpleSeriesRenderer();
ssr.setColor(color);
renderer.addSeriesRenderer(ssr);
}
CategorySeries series = new CategorySeries("Project budget"); //카테고리에 관련 텍스트와 값을 저장
int count = 0;
for (double value : values) {
series.add(texts[count++], value);
}
mPieChart = new PieChart(series, renderer); invalidate(); } }



