2012-03-19 51 views
1

我在achartengine的幫助下製作了一個餅圖,現在我想設置點擊命令,以便在用戶點擊餅圖時打開一個新視圖。對不同楔形餅圖的不同觀點。我試着用iTouchHandler,但我不知道如何處理觸摸。我已經在渲染器設置onClickEnabled(真),但怎麼我讓它聽我的命令,請幫助..代碼如下..如何使用achartengine添加點擊餅圖

import org.achartengine.ChartFactory; 
import org.achartengine.ITouchHandler; 
import org.achartengine.model.CategorySeries; 
import org.achartengine.renderer.DefaultRenderer; 
import org.achartengine.renderer.SimpleSeriesRenderer; 
import org.achartengine.tools.PanListener; 
import org.achartengine.tools.ZoomListener; 

import android.content.Context; 
import android.content.Intent; 
import android.graphics.Color; 
import android.os.storage.OnObbStateChangeListener; 
import android.view.MotionEvent; 
import android.view.View.OnClickListener; 

public class PieChart implements ITouchHandler 
{ 
public Intent getIntent(Context context) 
{ 
    double[] values = new double[] {12, 14, 11, 10,2}; 
    int[] colors = new int[] {Color.BLUE, Color.GREEN, Color.MAGENTA, Color.YELLOW, Color.CYAN}; 
    DefaultRenderer renderer = buildCategoryRenderer(colors); 
    renderer.setLabelsTextSize(10); 
    return ChartFactory.getPieChartIntent(context, buildCategoryDataset("Project budget", values), renderer,"pie"); 
    } 
protected DefaultRenderer buildCategoryRenderer(int[] colors) { 
    DefaultRenderer renderer = new DefaultRenderer(); 
    renderer.setBackgroundColor(Color.WHITE); 
    renderer.setPanEnabled(false); 
    renderer.setClickEnabled(true); 
    renderer.getSelectableBuffer(); 
    renderer.setAntialiasing(true); 
    renderer.setApplyBackgroundColor(true); 
    renderer.setLegendTextSize(30); 

    for (int color : colors) { 
     SimpleSeriesRenderer r = new SimpleSeriesRenderer(); 
     r.setColor(color); 
     r.setDisplayChartValues(false); 

     renderer.addSeriesRenderer(r); 
    } 
    return renderer; 
    } 
protected CategorySeries buildCategoryDataset(String title, double[] values) { 
    CategorySeries series = new CategorySeries(title); 
    int k = 0; 
    for (double value : values) { 
     series.add("Project " + ++k, value); 
    } 

    return series; 

} 
public void addPanListener(PanListener arg0) { 
    // TODO Auto-generated method stub 

} 
public void addZoomListener(ZoomListener arg0) { 
    // TODO Auto-generated method stub 

} 
public boolean handleTouch(MotionEvent arg0) { 
    // TODO Auto-generated method stub 
    System.out.println("lskdflk"); 

    return false; 
} 
public void removePanListener(PanListener arg0) { 
    // TODO Auto-generated method stub 

} 
public void removeZoomListener(ZoomListener arg0) { 
    // TODO Auto-generated method stub 

} 
} 

回答

0

我不知道你怎麼可以添加一個點擊監聽器以圖表活動

但如果可能的話,你可以改爲創建圖表查看使用​​3210並在返回查看通話setOnClickListener()