我修改了示例代码,因为我需要获得一个不断更新的饼图。我设法做了一些工作,但我无法弄清楚如何刷新图表。这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
ButtonInit();
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setMargins(new int[] { 20, 30, 15, 0 });
mRenderer.setZoomButtonsVisible(true);
mRenderer.setStartAngle(90);
for (int i = 0; i < VALUES.length; i++) {
mSeries.add(NAME_LIST[i] + " " + VALUES[i], VALUES[i]);
SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
mRenderer.addSeriesRenderer(renderer);
}
if (mChartView != null) {
mChartView.repaint();
}
}
@Override
protected void onResume() {
super.onResume();
LinearLayout layout = (LinearLayout) findViewById(R.id.Graph);
mChartView = (GraphicalView) ChartFactory.getPieChartView(this, mSeries, mRenderer);
mRenderer.setClickEnabled(true);
mRenderer.setSelectableBuffer(10);
layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
mChartView.repaint();
}
变量a,b,c,d不断变化,因为我通过蓝牙获得它们。
答案 0 :(得分:1)
尝试这样做
private GraphicalView mChart;
LinearLayout chart_container = (LinearLayout) findViewById(R.id.graphHolder);
.........
.......
mChart = (GraphicalView) ChartFactory.getPieChartView(this, dataset,
mRenderer);
chart_container.addView(mChart);
现在你可以使用
mChart.repaint();