现在我使用AchartEngine库在android中创建了一个条形图。
我的问题是,
启动模拟器后,我的应用程序立即显示条形图, 但我需要逐一展示每个酒吧。这意味着每个酒吧应该一个接一个地看到。
怎么做?
建议吗?
请找我的参考资料
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>
提前致谢...
答案 0 :(得分:0)
您可以使用动态图表表示在特定时间继续发送数据并repaint
从其他函数发送数据到value
列表
int i = 0;
While(true)
{
int[] series ={1,2,1,3,4,5,3,2,1,} // ex: your input data to be ploted
Thread.sleep(300000); //aprox. 5minutes delay
update(series[i]);
}
在update()
函数中添加数据
update(int newval)
{
value.add(newval);
}
在此repaint
图表