它给出了数组存储异常错误

时间:2014-10-09 08:50:59

标签: android achartengine

我想在Android的单个页面上显示两个饼图,怎么可能?它给出了ArrayStoreException

的错误
public class Subscription_Statics extends Activity implements
        OnItemSelectedListener
{
    private String[] pPacks = new String[]{
            "BasePack", "SliverPack", "GoldPack"
    };

    String[] code = new String[]{"Base Pack", "Sliver Pack", "Gold Pack"};
    // Pie Chart Section Value
    int[] distribution = results;

    // ***Calculating percentage***//
    int sum = 0;
    float[] per = new float[3];

    for(
    int i = 0;
    i<distribution.length;i++)

    {
        sum += distribution[i];
        // System.out.println("addition: " + sum);
    }

    for(
    int i = 0;
    i<distribution.length;i++)

    {
        // System.out.println("dis: " + distribution[i]);
        per[i] = (((float) distribution[i] / sum) * 100);
        System.out.println("percentage: " + per[i]);
        // System.out.println("Base" + per[0]+"Sliver"+per[1]+"Gold"+per[2]);

        //*** store in single array list ***///
  /* ArrayList<Float> al = new ArrayList<Float>();
  al.add(per[0]); al.add(per[1]); al.add(per[2]);
  System.out.println("array list: " + al);*/


    }

    ArrayList<Float> al = new ArrayList<Float>();
    al.add(per[0]);al.add(per[1]);al.add(per[2]);
    System.out.println("array list: "+al);

    String[] arr = al.toArray(new String[al.size()]);
    System.out.println("array list: "+arr);
    //int[] distribution = { 3, 1, 2} ;
    // Color of each Pie Chart Sections
    int[] colors = {Color.BLUE, Color.GREEN, Color.RED};
    // Instantiating CategorySeries to plot Pie Chart
    CategorySeries distributionSeries = new CategorySeries(" Content Revenue");
    for(
    int i = 0;
    i<distribution.length;i++)

    {
        // Adding a slice with its values and name to the Pie Chart
        distributionSeries.add(code[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.addSeriesRenderer(seriesRenderer);


    }


    defaultRenderer.setChartTitle("Content Revenue ");
    defaultRenderer.setChartTitleTextSize(20);
    defaultRenderer.setZoomButtonsVisible(true);
    defaultRenderer.setLabelsColor(Color.BLACK);
    defaultRenderer.setLabelsTextSize(25);


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

    // Start Activity
    startActivity(intent);
}

0 个答案:

没有答案