afreechart Android的日食esample [英] afreechart Android eclipse esample
问题描述
我想使用AFreeChart在我的活动,以显示一个图表,我已签那么多文件扔互联网,但我没有发现任何完整的例子,我的意思是如何建立一个图表,并把它显示在我的布局后,我需要表现出来的抱怨GUI(同样的事情像一个形象在我的GUI),Y正在使用eclipse(安卓4.2)它。
I am trying to use AFreeChart to display a chart in my activity, I have checked so many documentation throw internet but I do not find any full example, I mean how to build a chart and to show it after in my Layout, I need to show it whining an GUI (same thing like an image in my GUI), y am using eclipse (android 4.2) for it.
有谁知道如何在Android的使用AfreeChart?谢谢
Does anyone know how to use AfreeChart in android? Thanks
推荐答案
好吧,因为这是一个较早的帖子,我不知道你是否能找到这个问题的答案。这是需要做您的活动中显示图表AFREE什么。
Okay, since this is an older post I am not sure if you were able to find an answer for this question. This is what needs to be done to display a afree chart in your activity.
-
创建扩展ImageView的,像blelow一些自定义视图
Create a custom view extending ImageView, something like blelow
public class ChartView extends ImageView
{
private Bitmap bitmap;
private RectShape rectArea;
private Canvas canvas;
private AFreeChart chart;
public ChartView( Context context, AttributeSet attributeSet )
{
super(context, attributeSet);
}
public ChartView( Context context )
{
super(context);
intChart();
}
private void intChart()
{
//Setting different width and height based on the orientation.
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
{
bitmap = Bitmap.createBitmap(400, 200, Bitmap.Config.ARGB_8888);
rectArea = new RectShape(0.0, 0.0, 400, 200);
}
else
{
bitmap = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
rectArea = new RectShape(0.0, 0.0, 200, 200);
}
}
public void drawChart( AFreeChart chart )
{
canvas = new Canvas(bitmap);
this.chart = chart;
this.chart.draw(canvas, rectArea);
setImageBitmap(bitmap);
}
@Override
protected void onDraw( Canvas canvas )
{
super.onDraw(canvas);
}
}
创建活动,如下图所示,你都设置去。我假设你已经创建了AFreeChart对象被传递到视图。
Create an activity, as shown below and you all set to go. I assume that you have already created your AFreeChart object to be passed to the view.
public class ChartActivity extends Activity
{
@Override
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate(savedInstanceState);
setContentView(R.layout.chart);
ViewGroup viewGroup = (ViewGroup)getWindow().getDecorView().findViewById(android.R.id.content);
ChartView chartView = new ChartView(this);
chartView.drawChart(ChartFactory.createChart()/*Returns AFreechart object*/);
viewGroup.addView(chartView);
}
}
chart.xml
chart.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
希望这有助于
这篇关于afreechart Android的日食esample的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!