2
我的目標是創建一個圖形,根據用戶操作隱藏和顯示一系列圖形。我想通過首先清除圖表和數據集和渲染器,然後重新插入新值來實現這一點。就像Arraylists的.clear()
方法一樣,我想知道是否爲XYMultipleSeriesRenderer構建了一些類似的功能。我注意到,XYMultipleSeriesDataset是缺乏類似的功能,但我可以做XYMultipleSeriesRenderer中的achartengine清晰渲染器
for(int i = 0; i < dataset.getSeriesCount(); i++) {
dataset.removeSeries(i);
}
幸運的是XYMultipleSeriesRenderer似乎有方法的getrenderercount類型,以解決(我想,我不能肯定還沒有),但不是一個需要ints
的移除方法。我所看到的只是一個刪除功能,不需要ints
,只是實際的系列渲染器名稱。
這裏是更多的代碼是否有幫助:
private void excecuteGraph() {
// add series to the complete dataset
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
XYMultipleSeriesRenderer mrenderer = new XYMultipleSeriesRenderer();
switch (graphCase){
case -1:
dataset.addSeries(series0);
dataset.addSeries(series1);
dataset.addSeries(series2);
dataset.addSeries(series3);
// create the individual renderers, customize settings for each
XYSeriesRenderer renderer1 = new XYSeriesRenderer();
renderer1.setColor(Color.BLUE);
renderer1.setLineWidth(3);
XYSeriesRenderer renderer2 = new XYSeriesRenderer();
renderer2.setColor(Color.DKGRAY);
renderer2.setLineWidth(3);
XYSeriesRenderer renderer3 = new XYSeriesRenderer();
renderer3.setColor(Color.RED);
renderer3.setLineWidth(3);
XYSeriesRenderer renderer4 = new XYSeriesRenderer();
renderer4.setColor(Color.WHITE);
renderer4.setLineWidth(3);
// add renderers to the complete multirenderer, customize settings for it
mrenderer.addSeriesRenderer(renderer1);
mrenderer.addSeriesRenderer(renderer2);
mrenderer.addSeriesRenderer(renderer3);
mrenderer.addSeriesRenderer(renderer4);
break;
case 0:
for(int i = 0; i < dataset.getSeriesCount(); i++) {
dataset.removeSeries(i);
}
dataset.addSeries(series0);
XYSeriesRenderer renderer00 = new XYSeriesRenderer();
renderer00.setColor(Color.BLUE);
renderer00.setLineWidth(3);
mrenderer.addSeriesRenderer(renderer00);
break;
case 1:
for(int i = 0; i < dataset.getSeriesCount(); i++) {
dataset.removeSeries(i);
Log.d("testingGraph", dataset.toString());
}
dataset.addSeries(series1);
XYSeriesRenderer renderer10 = new XYSeriesRenderer();
renderer10.setColor(Color.DKGRAY);
renderer10.setLineWidth(3);
mrenderer.addSeriesRenderer(renderer10);
break;
case 2:
for(int i = 0; i < dataset.getSeriesCount(); i++) {
dataset.removeSeries(i);
}
dataset.addSeries(series2);
XYSeriesRenderer renderer20 = new XYSeriesRenderer();
renderer20.setColor(Color.RED);
renderer20.setLineWidth(3);
mrenderer.addSeriesRenderer(renderer20);
case 3:
for(int i = 0; i < dataset.getSeriesCount(); i++) {
dataset.removeSeries(i);
}
dataset.addSeries(series3);
XYSeriesRenderer renderer30 = new XYSeriesRenderer();
renderer30.setColor(Color.WHITE);
renderer30.setLineWidth(3);
mrenderer.addSeriesRenderer(renderer30);
}
mrenderer.setYTitle("Accuracy (%)");
mrenderer.setYAxisMin(0);
mrenderer.setYAxisMax(100);
mrenderer.setApplyBackgroundColor(true);
mrenderer.setBackgroundColor(Color.TRANSPARENT);
// Get the chart view result, add it to the linear layout
GraphicalView mChartView = ChartFactory.getTimeChartView(this, dataset,
mrenderer, "MM/dd/yyyy");
LinearLayout graphLayout = (LinearLayout) findViewById(R.id.layout_graph);
graphLayout.addView(mChartView, new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
if (mChartView !=null) {
mChartView.repaint();
}
}
也許我有一個過時的jar或什麼的,我找不到'mrenderer.removeAllRenderers();'離我最近的是'mrenderer.removeSeriesRenderer(renderer)'。這要求我一次只做一個,這對我來說沒有用處,因爲這些在運行時會有所不同。如果這有所作爲,我正在做一個時間系列。 – mango
從這裏下載1.0.0:http://code.google.com/p/achartengine/downloads/list或1.1.0-rc1從這裏:http://www.achartengine.org/download/ –
以及我有1.0 .0已經。我會測試rc1。你認爲最好是擴展課程並嘗試我自己的系列可見性切換器嗎?我對自己的能力沒有那麼自信,但如果可能的話,我很樂意嘗試。 – mango