Android GraphView,如何显示x轴标签?
我正在尝试使用GraphView库绘制图形。我的问题是,x轴不显示,但y轴可以。此外,x轴标签上的值也未显示 这是我的xml文件:Android GraphView,如何显示x轴标签?,android,android-graphview,Android,Android Graphview,我正在尝试使用GraphView库绘制图形。我的问题是,x轴不显示,但y轴可以。此外,x轴标签上的值也未显示 这是我的xml文件: <com.jjoe64.graphview.GraphView android:id="@+id/graph" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_a
<com.jjoe64.graphview.GraphView
android:id="@+id/graph"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:background="#FAFA82" />
java代码:
double graph1LastXValue = 5d;
GraphView graph = (GraphView) findViewById(R.id.graph);
graph.getGridLabelRenderer().setVerticalAxisTitle("Match Value");
graph.getGridLabelRenderer().setHorizontalAxisTitle("Time/s");
Series2 = new LineGraphSeries<DataPoint>();
mSeries1.setColor(Color.RED);
mSeries1.setThickness(2);
graph.addSeries(mSeries2);
graph.getViewport().setXAxisBoundsManual(true);
graph.getViewport().setMinX(0);
graph.getViewport().setMaxX(100);
graph.getGridLabelRenderer().setGridStyle(GridStyle.BOTH);
plotter(matchValMean);
protected void plotter(Double matchVal) {
matchValue = matchVal;
// TODO Auto-generated method stub
mTimer1 = new Runnable() {
@Override
public void run() {
graph1LastXValue += 1d;
mSeries1.appendData(new DataPoint(graph1LastXValue, matchValue), true, 100);
mHandler.postDelayed(this, 1000);
}
};
mHandler.postDelayed(mTimer1, 1000);
}
double graph1LastXValue=5d;
GraphView图形=(GraphView)findViewById(R.id.graph);
getGridLabelRenderer().setVerticalExistitle(“匹配值”);
graph.getGridLabelRenderer().setHorizontalAxisTitle(“时间”);
Series2=新的LineGraphSeries();
mSeries1.setColor(Color.RED);
mSeries1.设置厚度(2);
图1.addSeries(mSeries2);
graph.getViewport().setXAxisBoundsManual(true);
graph.getViewport().setMinX(0);
graph.getViewport().setMaxX(100);
graph.getGridLabelRenderer().setGridStyle(GridStyle.BOTH);
绘图仪(平均值);
受保护的无效绘图仪(双匹配值){
matchValue=matchVal;
//TODO自动生成的方法存根
mTimer1=新的可运行(){
@凌驾
公开募捐{
图1 LastX值+=1d;
mSeries1.appendData(新数据点(graph1LastXValue,matchValue),true,100);
mHandler.postDelayed(这个,1000);
}
};
mHandler.postDelayed(mTimer1,1000);
}
我没有显示所有的代码,因为它很长。提前感谢:)如果您想显示X轴的标题
GridLabelRenderer gridLabel = graphView.getGridLabelRenderer();
gridLabel.setHorizontalAxisTitle("X Axis Title");
如果要根据文档显示X轴的标签
// GraphView 3.x
graphView.setHorizontalLabels(new String[] {"2 days ago", "yesterday", "today", "tomorrow"});
graphView.setVerticalLabels(new String[] {"high", "middle", "low"});
// GraphView 4.x
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {"old", "middle", "new"});
staticLabelsFormatter.setVerticalLabels(new String[] {"low", "middle", "high"});
graphView.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
它正在进行演示项目,这意味着只进行一项活动,但它不在我的现场项目上工作,有什么问题吗?