效果图如下:
首先,要使用achartengine必须要加入jar包(源码中有,可以拷出来用)
直接贴代码:
& lt; ? xml version=" 1.0 ",编码=皍tf - 8”?在,, & lt; RelativeLayout  xmlns: android=" http://schemas.android.com/apk/res/android ",, ,,,xmlns:工具=" http://schemas.android.com/tools ",, ,,,android: layout_width=癿atch_parent”,, ,,,android: layout_height=癿atch_parent”,, ,,,android: paddingBottom=癅dimen/activity_vertical_margin”,, ,,,android: paddingLeft=癅dimen/activity_horizontal_margin”,, ,,,android: paddingRight=癅dimen/activity_horizontal_margin”,, ,,,android: paddingTop=癅dimen/activity_vertical_margin”,, ,,,工具:上下文=癱om.lg.achartenginedemo.MainActivity”在,, ,, ,,,& lt; RelativeLayout , ,,,,,,,android: id=癅 + id/图表”,, ,,,,,,,android: layout_width=癿atch_parent”,, ,,,,,,,android: layout_height=?00”dp/祝辞,, ,, & lt;/RelativeLayout>
下面是活动中的代码:
public class MainActivity extends AppCompatActivity {,, ,,,private RelativeLayout 图,,, ,,,//XY轴坐标数据,, ,,,private XYSeries series1,台series2;,, ,,,//单个曲线渲染器,, ,,,private XYSeriesRenderer renderer1, renderer2;,, ,,,//图标数据集,, ,,,private XYMultipleSeriesDataset mDataset=new XYMultipleSeriesDataset ();,, ,,,//曲线图整体渲染器,, ,,,private XYMultipleSeriesRenderer mRenderer=new XYMultipleSeriesRenderer ();,, ,,,//绘图视图,, ,,,private GraphicalView mChartView;,, ,, ,,,@Override , ,,,protected void onCreate (Bundle savedInstanceState), {,, ,,,,,,,super.onCreate (savedInstanceState);,, ,,,,,,,setContentView (R.layout.activity_main);,, ,,,,,,,图=(使用)findViewById (R.id.chart);,, ,,,,,,,init_chart ();,, ,,,},, ,, ,,,private void init_chart (), {,, ,,,,,,,//添加曲线,, ,,,,,,,mRenderer.setXTitle(“序”号),,//,设置为X轴的标题,, ,,,,,,,mRenderer.setYTitle(“数值”),,//,设置为Y轴的标题,, ,,,,,,,mRenderer.setChartTitle (“achartengine折线图”);,//,设置图表标题,, ,,,,,,,mRenderer.setMargins (new int[],{, 30岁,40岁,20岁,30,});,//,上左下右边距,, ,,,,,,,mRenderer.setAxisTitleTextSize(20);,//,设置轴标题文本大小,, ,,,,,,,mRenderer.setLabelsColor (Color.rgb (0 xd2, 0 x69,, 0 x1e)),,//,坐标名称及标题颜色,, ,,,,,,,mRenderer.setXLabelsColor (Color.BLACK);//,设置X轴刻度颜色,, ,,,,,,,mRenderer.setYLabelsColor (0,, Color.BLACK);//,设置Y轴刻度颜色,, ,,,,,,,mRenderer.setChartTitleTextSize(30);//,设置图表标题文字的大小,, ,,,,,,,mRenderer.setLabelsTextSize(18);//,设置标签的文字大小,, ,,,,,,,mRenderer.setYLabels(10);//,设置Y轴刻度个数,, ,,,,,,,mRenderer.setYLabelsAlign (Paint.Align.RIGHT);,//,设置刻度线与Y轴之间的相对位置关系,, ,,,,,,,mRenderer.setClickEnabled(假的),,, ,,,,,,,mRenderer.setZoomEnabled(真正的),,//,设置是否可以滑动及放大缩小,,, ,,,,,,,mRenderer.setPanEnabled(真正的),,, null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null nullAndroid折线图开发之Achartnegine