我正在使用来自github的graphview库,简称为Graphview。
我将日期作为x轴,将价格作为y轴。我从api获取数据,但是当我将人工舍入设置为false时,y轴会发疯,并为许多值添加了方式:Picture of it happening.
现在,如果我打开人工舍入,则y值是固定的,但日期却显示为奇怪:Picture of that.
当我旋转设备时,没有问题,我不知道出了什么问题,请帮忙。
代码:
@Override
public void onLoadFinished(Loader<ArrayList<GraphObject>> loader,
ArrayList<GraphObject> graphObjects) {
if (graphObjects != null && !graphObjects.isEmpty()) {
ArrayList<GraphObject> objects = new ArrayList<>(graphObjects);
List<DataPoint> list = getDataPoint(graphObjects);
LineGraphSeries<DataPoint> series = new LineGraphSeries<>
(list.toArray(new DataPoint[1]));
Log.e("Message", objects.get(0).getclose());
graphView.addSeries(series);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("LLLyy");
graphView.getGridLabelRenderer().setLabelFormatter(new
DateAsXAxisLabelFormatter(this,simpleDateFormat));
graphView.getGridLabelRenderer().setNumHorizontalLabels(3);
graphView.getViewport().setMinX(list.get(0).getX());
graphView.getViewport().setMaxX(list.get(list.size()-1).getX());
graphView.getViewport().setXAxisBoundsManual(true);
graphView.getGridLabelRenderer().setHumanRounding(false);
}
}
private List<DataPoint> getDataPoint(ArrayList<GraphObject> graphObjects) {
List<DataPoint> dataPoints = new ArrayList<>();
for (GraphObject object : graphObjects) {
String close_string = object.getclose();
String string_time = object.getMtime();
long time = Long.parseLong(string_time);
time = time * 1000;
Double close = Double.parseDouble(close_string);
Date dateObject = new Date(time);
dataPoints.add(new DataPoint(dateObject, close));
}
return dataPoints;
}
答案 0 :(得分:0)
DataPoint[] dataPoint = new DataPoint[total_count];
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(dataPoint);
设置这些属性
寓言
`graph.getGridLabelRenderer().setLabelFormatter(new DefaultLabelFormatter() {
@Override
public String formatLabel(double value, boolean isValueX) {
if (isValueX) {
// show normal x values
Date date1 = IRoidAppHelper.parseTime(Helper.parseTime(productPriceData.getdate(), "yyyy-MM-dd'T'HH:mm:ssZ", "dd-MM-yyyy"), "dd-MM-yyyy");
String dateString =Helper.parseTime(date1.getTime(), "dd/MM");
return dateString;
} else {
// show currency for y values
return super.formatLabel(value, isValueX);
}
}
});`