2
現在我已經在android中使用AchartEngine庫創建了條形圖。如何在android中一個個顯示條形圖?
這裏我的問題是,
得到啓動模擬器後,我的應用程序是顯示棒形圖瞬間, 但我需要的是通過展示各個one.Which一個酒吧每個指條應該要一個接一個地可見。
如何做到這一點?
請提出建議?
請找我的消息來源參考
MainActivity.java
public class MainActivity extends Activity {
Button btn_result;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn_result = (Button)findViewById(R.id.button1_invoke);
btn_result.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
Intent intnt = new Intent(MainActivity.this,Result_BarActivity.class);
startActivity(intnt);
}
}); }}
Result_BarActivity.java
public class Result_BarActivity extends Activity
{
RelativeLayout rltv;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.result_barchart);
final GraphicalView grfv =createIntent();
RelativeLayout rl=(RelativeLayout)findViewById(R.id.RelativeLayout_ID);
rl.addView(grfv);
}
public GraphicalView createIntent()
{
rltv = (RelativeLayout)findViewById(R.id.RelativeLayout_ID);
String[] titles = new String[] { "Order's profit of the year", " " };
List<double[]> values = new ArrayList<double[]>();
values.add(new double[] { 7, 2, 5, 8 });
values.add(new double[] {});
int[] colors = new int[] { Color.BLUE, Color.WHITE};
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
renderer.setOrientation(Orientation.HORIZONTAL);
setChartSettings(renderer, "Profit for the year 2012", " ", " ",0,10, 0,10, Color.GRAY, Color.LTGRAY);
renderer.setXLabels(1);
renderer.addXTextLabel(0.75, "ord1");
renderer.addXTextLabel(1.75, "ord2");
renderer.addXTextLabel(2.75, "ord3");
renderer.addXTextLabel(3.75, "ord4");
renderer.setPanEnabled(true, false);
int length = renderer.getSeriesRendererCount();
for (int i = 0; i < length; i++)
{
SimpleSeriesRenderer seriesRenderer = renderer.getSeriesRendererAt(i);
seriesRenderer.setDisplayChartValues(true);
}
final GraphicalView grfv = ChartFactory.getBarChartView(Result_BarActivity.this, buildBarDataset(titles, values), renderer,Type.DEFAULT);
return grfv;
/* ChartFactory.getBarChartIntent(this, buildBarDataset(titles, values), renderer,Type.DEFAULT);*/
}
protected XYMultipleSeriesRenderer buildBarRenderer(int[] colors)
{
// creates a SeriesRenderer and initializes it with useful default values as well as colors
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(15);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
int length = colors.length;
for (int i = 0; i < length; i++)
{
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(colors[i]);
renderer.addSeriesRenderer(r);
}
return renderer;
}
protected void setChartSettings(XYMultipleSeriesRenderer renderer, String title, String xTitle,
String yTitle, double xMin, double xMax, double yMin, double yMax, int axesColor,int labelsColor)
{
// sets lots of default values for this renderer
renderer.setChartTitle(title);
renderer.setXTitle(xTitle);
renderer.setYTitle(yTitle);
renderer.setXAxisMin(xMin);
renderer.setXAxisMax(xMax);
renderer.setYAxisMin(yMin);
renderer.setYAxisMax(yMax);
renderer.setAxesColor(axesColor);
renderer.setLabelsColor(labelsColor);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.MAGENTA);
}
protected XYMultipleSeriesDataset buildBarDataset(String[] titles, List<double[]> values)
{
// adds the axis titles and values into the data-set
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
int length = titles.length;
for (int i = 0; i < length; i++)
{
CategorySeries series = new CategorySeries(titles[i]);
double[] v = values.get(i);
int seriesLength = v.length;
for (int k = 0; k < seriesLength; k++)
{
series.add(v[k]);
}
dataset.addSeries(series.toXYSeries());
}
return dataset;
}}
的main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1_invoke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="195dp"
android:text="Invoke barchart" />
</RelativeLayout>
result_barchart.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout_ID"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</RelativeLayout>
在此先感謝...