我得到蝙蝠条形图如下所示.
我使用下面的代码.
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,30 });
//multiRenderer.setBarSpacing(0.2f);
multiRenderer.addSeriesRenderer(loan1Renderer);
multiRenderer.addSeriesRenderer(loan2Renderer);
GraphicalView barChart = ChartFactory.getBarChartView(CompareLoanActivity.this,dataset,multiRenderer,Type.DEFAULT);
rlBarChart.addView(barChart);
}
我想要这样的条形图.
当我缩小时,上图也是相同的图表.
谢谢
最佳答案