这是代码,我试图使用Graphview制作图形,但是我无法将XAxis标签格式化为时间,所以进行了一些搜索,然后从该页面复制了代码: http://www.android-graphview.org/dates-as-labels/
fetchData process= new fetchData();
Date date[];
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
graph=(GraphView) findViewById(R.id.graph);
process.execute();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// manage error ...
}
String[] asseX=fetchData.prendix();
date=new Date[x.length];
for(int i=0;i<x.length;i++)
{
try {
date[i] = new SimpleDateFormat("HH:mm").parse(x[i]);
} catch (ParseException e) {
e.printStackTrace();
}
}
graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(getActivity));
graph.getGridLabelRenderer().setNumHorizontalLabels(x.length);
}
答案 0 :(得分:1)
代替此行:
graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(getActivity()));
使用
graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(your_activity_name.this));
尝试一下。如果可行,请在此处进行更新。