Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

complete bar chart in screen in AchartEngine

I get bat barchart as like below.

enter image description here

I have used below code for it.

public void createBarChart(String loanName1,String loanName2){
        XYSeries loan1Series = new XYSeries(loanName1);
        // Creating an  XYSeries for Income
        XYSeries loan2Series = new XYSeries(loanName2);
        // Adding data to Income and Expense Series
        double ymax = principleLoan1;
        if(principleLoan2 > principleLoan1){
            ymax = principleLoan2;
        }
        if(totalPayment1 > 10000){
            totalPayment1 = totalPayment1/1000;
        }
        if(totalPayment2 > 10000){
            totalPayment2 = totalPayment2/1000;
        }
        if(totalPayment1 > totalPayment2){
            if(totalPayment1 > ymax){
                ymax = totalPayment1;
            }
        }else{
            if(totalPayment2 > ymax){
                ymax = totalPayment2;
            }
        }

        loan1Series.add(1, principleLoan1);
        loan1Series.add(2, totalPayment1);

        loan2Series.add(1, principleLoan2);
        loan2Series.add(2, totalPayment2);

        // Creating a dataset to hold each series
        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        // Adding loan 1 Series to the dataset
        dataset.addSeries(loan1Series);
        // Adding loan 2 Series to dataset
        dataset.addSeries(loan2Series);   

        XYSeriesRenderer loan1Renderer = new XYSeriesRenderer();
        loan1Renderer.setColor(Color.parseColor("#b3b3b3"));
        loan1Renderer.setFillPoints(true);
        loan1Renderer.setChartValuesTextSize(20);
        loan1Renderer.setLineWidth(0.2f);
        loan1Renderer.setDisplayChartValues(true);

        // Creating XYSeriesRenderer to customize expenseSeries
        XYSeriesRenderer loan2Renderer = new XYSeriesRenderer();
        loan2Renderer.setColor(Color.parseColor("#5eae1f"));
        loan2Renderer.setFillPoints(true);
        loan2Renderer.setChartValuesTextSize(20);
        loan2Renderer.setLineWidth(0.2f);
        loan2Renderer.setDisplayChartValues(true);   

        XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
        //multiRenderer.setXLabels(0);
        multiRenderer.setChartTitle("Difference between Two loan");
        //multiRenderer.setXTitle("Year 2012");
       // multiRenderer.setYTitle("Amount in Dollars");
        multiRenderer.setZoomButtonsVisible(false);
        multiRenderer.setZoomEnabled(false);
        multiRenderer.setPanEnabled(false);
        multiRenderer.setInScroll(true);
        multiRenderer.setClickEnabled(false);
        //multiRenderer.setFitLegend(true);
        //multiRenderer.setLegendHeight(50);

        //For apply background
        multiRenderer.setApplyBackgroundColor(true);
        multiRenderer.setBackgroundColor(Color.WHITE);
        multiRenderer.setMarginsColor(Color.WHITE);


        //multiRenderer.setLegendTextSize(20);

        multiRenderer.setAxisTitleTextSize(20);
        multiRenderer.setChartTitleTextSize(28);
        multiRenderer.setLabelsTextSize(18);
        multiRenderer.setLegendTextSize(18);
        //multiRenderer.setLegendHeight(5);
        // for x axis
        //multiRenderer.setXLabelsAlign(Align.CENTER);
        multiRenderer.setXLabels(0);
        //for y axis
        multiRenderer.setYLabelsAlign(Align.RIGHT);
        multiRenderer.setYAxisMax(ymax);

        // main axis 
        multiRenderer.setAxisTitleTextSize(22);
        multiRenderer.setLabelsColor(Color.BLACK);

        //multiRenderer.setFitLegend(true);
        //multiRenderer.setZoomRate(0.2f); 
        //multiRenderer.setMargins(new int[] { 70, 50, 50, 30 });
        //multiRenderer.setBarSpacing(0.2f);
        multiRenderer.addSeriesRenderer(loan1Renderer);
        multiRenderer.addSeriesRenderer(loan2Renderer);

        GraphicalView barChart = ChartFactory.getBarChartView(CompareLoanActivity.this, dataset, multiRenderer, Type.DEFAULT);
        rlBarChart.addView(barChart);

    }

And I want bar chart like this.

enter image description here

Upper chart is also same chart when I zoom out.

Thanks

like image 975
Girish Bhutiya Avatar asked Oct 03 '22 21:10

Girish Bhutiya


1 Answers

I have solved my issue by setting below property.

multiRenderer.setXAxisMax(3);
 multiRenderer.setXAxisMin(0);
like image 186
Girish Bhutiya Avatar answered Oct 12 '22 10:10

Girish Bhutiya