1

最新のjarファイルを使用して棒グラフを実装しましたが、正しく表示されません

これは私のコードです:

private void openChart(){
        int[] x = { 10,20,30,40,50,60,70 };
       // int[] y = { 10,20,30,40,50,60,70 };
        int[] income = { 20,25,27,30,28,35,37,38};
        int[] expense = {22, 27, 29, 28, 26, 30, 33, 34 };
        int[] sample = {22, 27, 29, 28, 26, 30, 33, 34 };

        // Creating an  XYSeries for Income
        XYSeries incomeSeries = new XYSeries("Income");
        // Creating an  XYSeries for Expense
        XYSeries expenseSeries = new XYSeries("Expense");
     // Creating an  XYSeries for Expense
        XYSeries sampleseries = new XYSeries("Sample");
        // Adding data to Income and Expense Series
        for(int i=0;i<x.length;i++){
            incomeSeries.add(i,income[i]);
            expenseSeries.add(i,expense[i]);
            sampleseries.add(i,sample[i]);
        }

        // Creating a dataset to hold each series
        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        // Adding Income Series to the dataset
        dataset.addSeries(incomeSeries);
        // Adding Expense Series to dataset
        dataset.addSeries(expenseSeries);
        // Adding Expense Series to dataset
        dataset.addSeries(sampleseries);

        // Creating XYSeriesRenderer to customize incomeSeries
        XYSeriesRenderer incomeRenderer = new XYSeriesRenderer();
        incomeRenderer.setColor(Color.rgb(130, 130, 230));
        incomeRenderer.setFillPoints(true);
        incomeRenderer.setLineWidth(2);
        incomeRenderer.setChartValuesTextAlign(Align.CENTER);
        incomeRenderer.setChartValuesTextSize(18);
        incomeRenderer.setDisplayChartValues(true);

        // Creating XYSeriesRenderer to customize expenseSeries
        XYSeriesRenderer expenseRenderer = new XYSeriesRenderer();
        expenseRenderer.setColor(Color.rgb(220, 80, 80));
        expenseRenderer.setFillPoints(true);
        expenseRenderer.setLineWidth(2);
        expenseRenderer.setChartValuesTextAlign(Align.CENTER);
        expenseRenderer.setChartValuesTextSize(18);
        expenseRenderer.setDisplayChartValues(true);

     // Creating XYSeriesRenderer to customize expenseSeries
        XYSeriesRenderer samplseries = new XYSeriesRenderer();
        samplseries.setColor(Color.rgb(120, 40, 40));
        samplseries.setFillPoints(true);
        samplseries.setLineWidth(2);
        samplseries.setChartValuesTextAlign(Align.CENTER);
        samplseries.setChartValuesTextSize(18);
        samplseries.setDisplayChartValues(true);


        // Creating a XYMultipleSeriesRenderer to customize the whole chart
        XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
        multiRenderer.setMargins(new int[] {30, 50, 50, 20});
        multiRenderer.setZoomRate(0.2f); // disable pinch to zoom
        multiRenderer.setZoomEnabled(false, false); // disable pinch to zoom
        multiRenderer.setBarSpacing(0.3f); // space between series
        multiRenderer.setXAxisMin(-1); // for x axis to start with some space
        multiRenderer.setXAxisMax(5);
        multiRenderer.setYAxisMin(0);
        multiRenderer.setYAxisMax(50);
        multiRenderer.setAxisTitleTextSize(20); // increase the text size of title of x and y
        multiRenderer.setAxesColor(Color.BLACK); // x and y line color
        multiRenderer.setGridColor(Color.GRAY); // grid line color
        multiRenderer.setShowGridX(true); // to show the grid line
        multiRenderer.setXLabels(0);
        multiRenderer.setPanEnabled(true, false);
        multiRenderer.setPanLimits(new double[] {-1,x.length,0,x.length});
       // multiRenderer.setYLabels(0);
      //  multiRenderer.setChartTitle("Income vs Expense Chart");
        multiRenderer.setLegendTextSize(26);
        multiRenderer.setLabelsColor(Color.BLACK); // changing the x,y title color
        multiRenderer.setLabelsTextSize(20); // changing the text size labels of x and y  

        multiRenderer.setXLabelsColor(Color.BLACK); // changing the color of x label
        multiRenderer.setXTitle("Tests"); // title for x
        multiRenderer.setYLabelsAlign(Align.RIGHT);// labels to display right
        multiRenderer.setYLabelsColor(0, Color.BLACK);// changing the color of y label
        multiRenderer.setYTitle("Scores");// title for y

        for(int i=0; i< x.length;i++){
            multiRenderer.addXTextLabel(i, mMonth[i]);
        }
        /*for(int i=0; i< x.length;i++){
            multiRenderer.addYTextLabel(i, mScores[i]);
        }*/
        // Adding incomeRenderer and expenseRenderer to multipleRenderer
        // Note: The order of adding dataseries to dataset and renderers to multipleRenderer
        // should be same
        multiRenderer.addSeriesRenderer(incomeRenderer);
        multiRenderer.addSeriesRenderer(expenseRenderer);
        multiRenderer.addSeriesRenderer(samplseries);

        // Creating an intent to plot bar chart using dataset and multipleRenderer
        Intent intent = ChartFactory.getBarChartIntent(getBaseContext(), dataset, multiRenderer, Type.DEFAULT);

        // Start Activity
        startActivity(intent);

    }

これは私の棒グラフがどのように見えるかです;

ここに画像の説明を入力

どこが間違っているのですか?

スクロールせず、背景が黒いために x 軸、y 軸の値が表示されず、また、パン制限を指定しましたが、何も機能していません

4

1 に答える 1

2

わかりました、自分で解決しました multiRenderer.setMarginsColor(Color.WHITE); を追加するのを逃していました。

于 2013-02-05T12:27:18.533 に答える