我正在使用android-graphview来为天气预报应用程序绘制Temps with time。
在我的标签“24小时”中,我绘制了从当前时间到24小时后的数据。我有3小时的天气预报。为了在x轴上实现正确的显示,首先我必须在一天发生变化时增加小时数。因此,如果当前时间是18:00来绘制数据,直到明天18:00,那么x轴值I绘制为--> 18 21 24 27 30 33 36 39 42。接下来,我使用标签格式设置工具将x轴标签更改为--> 18 21 0 3 6 9 12 15 18。图形在正确的点处正确显示,但是标签的步长是2而不是3,但范围是正确的。
System.out.println("WHAT1?“..正确显示了输入数据点对,并以3为步长按小时递增,但System.out.println(“pout.和"pour“显示x轴值以2的步长递增(尽管在正确的位置)。如何才能在3小时步长上显示标签?
我做错了什么?代码如下:
DataPoint b= new DataPoint(0,0);//test
DataPoint[] point_array= new DataPoint[9];
String[] time_label_24=new String[9];
GraphView graph = (GraphView) findViewById(R.id.graph);
hour=Integer.parseInt(Lista.get(x)[15]);
for(int i=x;i<=x+8;i++){
if((i-x)<Lista.size()) {
b = new DataPoint(hour, Float.parseFloat(Lista.get(i)[4]));
point_array[i - x] = b;
System.out.println("WHAT1? " + (i - x) + " " + point_array[i - x] + " " + hour);
time_label_24[i-x]=Lista.get(i)[15];
hour = hour + 3;
}
}
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(point_array);
graph.addSeries(series);
h=Integer.parseInt(Lista.get(x)[15]);
graph.getViewport().setXAxisBoundsManual(true);
//graph.getViewport().setMinX(Integer.parseInt(Lista.get(x)[15])-1);
//graph.getViewport().setMaxX(Integer.parseInt(Lista.get(x)[15])+8*3+1);
graph.getViewport().setMinX(Integer.parseInt(Lista.get(x)[15]));
graph.getViewport().setMaxX(Integer.parseInt(Lista.get(x)[15])+8*3);
graph.getGridLabelRenderer().setNumHorizontalLabels(9); //9
graph.getGridLabelRenderer().setTextSize(12f);
graph.getGridLabelRenderer().reloadStyles();
graph.getGridLabelRenderer().setLabelFormatter(new DefaultLabelFormatter() {
@Override
public String formatLabel(double value, boolean isValueX) {
int xylabel;
if (isValueX) {
if (value < 24) {
System.out.println("pout "+value+" " + String.valueOf(value));
xylabel = (int) Math.round(value);
return String.valueOf(xylabel);
} else{
System.out.println("pour "+value+" " + String.valueOf(value%24));
xylabel = (int) Math.round(value);
return String.valueOf(xylabel%24);
}
}else {
xylabel = (int) Math.round(value);
return String.valueOf(xylabel); // let graphview generate Y-axis label for us
}
}
});
////////
hour=Integer.parseInt(Lista.get(x)[15]);
for(int i=x;i<=x+8;i++){ // Same process for Temp FEEL
if((i-x)<Lista.size()) {
b = new DataPoint(hour, Float.parseFloat(Lista.get(i)[13]));
point_array[i - x] = b;
hour = hour + 3;
time_label_24[i-x]=Lista.get(i)[15];
System.out.println("What2? " + point_array[i - x]);
}
}
LineGraphSeries<DataPoint> series2 = new LineGraphSeries<DataPoint>(point_array);
graph.addSeries(series2);
series.setTitle("Temp");
series2.setTitle("Feel");
series.setColor(Color.WHITE);
series2.setColor(Color.RED);
graph.getLegendRenderer().setVisible(true);
graph.getLegendRenderer().setAlign(LegendRenderer.LegendAlign.TOP);以下是该图的图像:
发布于 2016-11-16 17:03:59
尝试通过以下方式禁用人类舍入
graph.getGridLabelRenderer().setHumanRounding(false);
https://stackoverflow.com/questions/39981601
复制相似问题