1
我使用GraphView的4.x的版本在我的Android應用程序。我有一個包含7個數據點的條形圖,第一個和最後一個小節正在被切斷。的Android 4.x的GraphView - 條形圖無法適應
這裏是我的代碼
private static final String[] WEEK_DAYS = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
private void showChartData() {
ChartData[] data = new ChartData[7];
for (int x = 0; x < 7; x++) {
data[x] = new ChartData();
}
data[0].setEnrollmentCount(2);
data[1].setEnrollmentCount(4);
data[2].setEnrollmentCount(6);
data[3].setEnrollmentCount(8);
data[4].setEnrollmentCount(10);
data[5].setEnrollmentCount(12);
data[6].setEnrollmentCount(14);
chartHolder.removeAllViews();
DataPoint[] graphViewData = new DataPoint[7];
for (int i = 0; i < data.length; i++) {
graphViewData[i] = new DataPoint(i,
data[i].getEnrollmentCount());
}
BarGraphSeries<DataPoint> series = new BarGraphSeries<DataPoint>(graphViewData);
series.setColor(getResources().getColor(R.color.custom_red));
GraphView graphView = new GraphView(this);
graphView.addSeries(series); // data
graphView.setBackgroundColor(Color.WHITE);
graphView.setTitle("Sales This Week");
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graphView);
staticLabelsFormatter.setHorizontalLabels(WEEK_DAYS);
graphView.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
graphView.getGridLabelRenderer().setGridStyle(GridStyle.NONE);
chartHolder.addView(graphView);
}
這裏是條形圖