你能建议我一个简单的方法吗?
我为此写了一个视图类,但不令人满意.所以,如果你告诉我一个好的和高性能的图表库,我将不胜感激.解决方法 从下载jar
http://www.achartengine.org/content/download.html
将jar添加到项目lib文件夹.还有开发人员提供的示例.您可以根据需要检查并修改相同的内容.
还有一个演示@
http://www.achartengine.org/content/demo.html
文件
http://www.achartengine.org/content/javadoc/org/achartengine/chart/PieChart.html
例:
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:orIEntation="vertical" > <linearLayout androID:ID="@+ID/chart" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_weight="1" androID:orIEntation="horizontal" > </linearLayout></linearLayout>
活动类
public class AChartEnginePIEChartActivity extends Activity { private static int[] colorS = new int[] { color.GREEN,color.BLUE,color.magenta,color.CYAN }; private static double[] VALUES = new double[] { 10,11,12,13 }; private static String[] name_List = new String[] { "A","B","C","D" }; private categorySerIEs mSerIEs = new categorySerIEs(""); private DefaultRenderer mRenderer = new DefaultRenderer(); private GraphicalVIEw mChartVIEw; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); mRenderer.setApplyBackgroundcolor(true); mRenderer.setBackgroundcolor(color.argb(100,50,50)); mRenderer.setChartTitleTextSize(20); mRenderer.setLabelsTextSize(15); mRenderer.setLegendTextSize(15); mRenderer.setmargins(new int[] { 20,30,15,0 }); mRenderer.setZoom@R_301_5554@sVisible(true); mRenderer.setStartAngle(90); for (int i = 0; i < VALUES.length; i++) { mSerIEs.add(name_List[i] + " " + VALUES[i],VALUES[i]); SimpleSerIEsRenderer renderer = new SimpleSerIEsRenderer(); renderer.setcolor(colorS[(mSerIEs.getItemCount() - 1) % colorS.length]); mRenderer.addSerIEsRenderer(renderer); } if (mChartVIEw != null) { mChartVIEw.repaint(); } } @OverrIDe protected voID onResume() { super.onResume(); if (mChartVIEw == null) { linearLayout layout = (linearLayout) findVIEwByID(R.ID.chart); mChartVIEw = ChartFactory.getPIEChartVIEw(this,mSerIEs,mRenderer); mRenderer.setClickEnabled(true); mRenderer.setSelectableBuffer(10); mChartVIEw.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { SerIEsSelection serIEsSelection = mChartVIEw.getCurrentSerIEsAndPoint(); if (serIEsSelection == null) { Toast.makeText(AChartEnginePIEChartActivity.this,"No chart element was clicked",Toast.LENGTH_SHORT).show(); } else { Toast.makeText(AChartEnginePIEChartActivity.this,"Chart element data point index "+ (serIEsSelection.getPointIndex()+1) + " was clicked" + " point value="+ serIEsSelection.getValue(),Toast.LENGTH_SHORT).show(); } } }); mChartVIEw.setonLongClickListener(new VIEw.OnLongClickListener() { @OverrIDe public boolean onLongClick(VIEw v) { SerIEsSelection serIEsSelection = mChartVIEw.getCurrentSerIEsAndPoint(); if (serIEsSelection == null) { Toast.makeText(AChartEnginePIEChartActivity.this,"No chart element was long pressed",Toast.LENGTH_SHORT); return false; } else { Toast.makeText(AChartEnginePIEChartActivity.this,"Chart element data point index "+ serIEsSelection.getPointIndex()+ " was long pressed",Toast.LENGTH_SHORT); return true; } } }); layout.addVIEw(mChartVIEw,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); } else { mChartVIEw.repaint(); } }}总结
以上是内存溢出为你收集整理的如何在Android中绘制饼图全部内容,希望文章能够帮你解决如何在Android中绘制饼图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)