的Android 4.x的GraphView - 条形图无法适应

我使用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);

}

这里是条形图

回答:

似乎已经出现了v3.1.3和4.0.0之间有不少变化的屏幕截图,反正也打这个。在分流视了图书馆的V3和向下的光柱特定的逻辑的xInterval,让你有一个完整的宽度巴屏幕上的第一个和最后一个条目有一半显示已被删除。无论如何,它在代码周围的代码很简单。

double xInterval=1.0; 

graphView.getViewport().setXAxisBoundsManual(true);

if (dataSeries instanceof BarGraphSeries) {

// Shunt the viewport, per v3.1.3 to show the full width of the first and last bars.

graphView.getViewport().setMinX(dataSeries.getLowestValueX() - (xInterval/2.0));

graphView.getViewport().setMaxX(dataSeries.getHighestValueX() + (xInterval/2.0));

} else {

graphView.getViewport().setMinX(dataSeries.getLowestValueX());

graphView.getViewport().setMaxX(dataSeries.getHighestValueX());

}

以上是 的Android 4.x的GraphView - 条形图无法适应 的全部内容, 来源链接: utcz.com/qa/266847.html

回到顶部