简体   繁体   English

GraphView,如何显示x轴标签?

[英]GraphView, how to show x-axis label?

I'm trying to plot graph using GraphView library. 我正在尝试使用GraphView库绘制图形。 My problem is, the x-axis does not show up but the y-axis can. 我的问题是,x轴没有显示,但y轴可以。 Besides, the value at the x-axis label also not showing up. 此外,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 :) 提前致谢 :)

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM