1

可能重复:
使用 ChartEngine 自定义显示的饼图

我使用图表引擎成功显示图表,但遇到以下问题:

1.我无法缩小图表大小。

2. 图表在屏幕上移动,但我不希望这样。

3.我想在屏幕底部再显示一张图像,但这里的图表显示在屏幕中间,只是我想在图像的顶部和下方显示图表(如何设置边距)。

请任何人都可以帮助我。在此先感谢。

公共类 MainActivity 扩展 Activity {

private String[] mMonth = new String[] {
            "Jan", "Feb" , "Mar", "Apr", "May", "Jun",
            "Jul", "Aug" , "Sep", "Oct", "Nov", "Dec"
        };

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    openChart();                        


}

private void openChart(){       

    double[] distribution = { 10,200,3,400,500,60} ;
    String[] dis = { "10","200","13","400","500","60"} ;
    // Color of each Pie Chart Sections
    int[] colors = { Color.BLUE, Color.MAGENTA, Color.GREEN, Color.CYAN, Color.RED,
                     Color.YELLOW };

    // Instantiating CategorySeries to plot Pie Chart       
    CategorySeries distributionSeries = new CategorySeries("Sample");
    for(int i=0 ;i < distribution.length;i++){
        // Adding a slice with its values and name to the Pie Chart
        distributionSeries.add(dis[i],distribution[i]);

    }   

    // Instantiating a renderer for the Pie Chart
    DefaultRenderer defaultRenderer  = new DefaultRenderer();       
    for(int i = 0 ;i<distribution.length;i++){          
        SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer();       
        seriesRenderer.setColor(colors[i]);
        seriesRenderer.setDisplayChartValues(true);

        // Adding a renderer for a slice
        defaultRenderer.setShowLegend(false);
        defaultRenderer.addSeriesRenderer(seriesRenderer);
        int mar[]=defaultRenderer.getMargins();
        System.out.println(mar);
    }

    // Creating an intent to plot bar chart using dataset and multipleRenderer      
    Intent intent = ChartFactory.getPieChartIntent(getBaseContext(), distributionSeries , defaultRenderer, "");     

    // Start Activity
    startActivity(intent);

}

@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); 返回真;} }

4

0 回答 0