1:在Fragment中使用achart
在onCreateView中加载布局文件
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
//return super.onCreateView(inflater, container, savedInstanceState);
return inflater.inflate(R.layout.ovil, container, false);
}
在onActivityCreated加载好图表转化为view,获取布局文件的LinearLayout,向LinearLayout添加图表view
LinearLayout ly = (LinearLayout)getActivity().findViewById(R.id.linovil);
View view = ChartFactory.getLineChartView(getActivity().getApplicationContext(), buildDataset(titles, x, values), renderer);
view.setBackgroundColor(Color.BLACK);
//getActivity().setContentView(view);
ly.addView(view);
2:Android使用achart绘图框架出现java.lang.NoClassDefFoundError错误解决方式
在到导入achartDemo工程运行出现
java.lang.NoClassDefFoundError: org.achartengine.chart.PointStyle[]
java.lang.NoClassDefFoundError: org.achartengine.model.XYMultipleSeriesDataset
依赖的Jar包没有编译到apk中,
选择工程Project右键-->属性-->Java Build Path -->Order and Export-->将引入的Jar包移到Android包之上-->Clean运行程序即可。