I'm trying to plot graph using GraphView library. My problem is, the x-axis does not show up but the y-axis can. Besides, the value at the x-axis label also not showing up.
我正在嘗試使用GraphView庫繪制圖形。我的問題是,x軸沒有顯示,但y軸可以顯示。此外,x軸標簽上的值也沒有顯示出來。
Here is my xml file:
這是我的xml文件:
<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" />
and the java code:
和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);
}
I did not show all the codes because it is very long. Thanks in advance :)
我沒有顯示所有代碼,因為它很長。提前致謝 :)
5
If you want to show X Axis's title
如果你想顯示X軸的標題
GridLabelRenderer gridLabel = graphView.getGridLabelRenderer();
gridLabel.setHorizontalAxisTitle("X Axis Title");
If you want to show X Axis's label, based on this documentation
如果要根據此文檔顯示X Axis的標簽
// 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);
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/05/16/7259bcad3cb3452f4cc78554fc3213f3.html。