Java 手动设置X轴时,Android GraphView静态标签会重复
我在应用程序中按小时绘制值,而不是水平x轴标签仅显示为“0”、“5”、“10”(对于小时0、小时5、小时10等),我希望使用一天的实际时间自定义标签(即“0”的“12AM”,“5”的“5AM”,“10”的“10AM”) 如果未设置静态标签,则水平标签显示如下:Java 手动设置X轴时,Android GraphView静态标签会重复,java,android,android-graphview,Java,Android,Android Graphview,我在应用程序中按小时绘制值,而不是水平x轴标签仅显示为“0”、“5”、“10”(对于小时0、小时5、小时10等),我希望使用一天的实际时间自定义标签(即“0”的“12AM”,“5”的“5AM”,“10”的“10AM”) 如果未设置静态标签,则水平标签显示如下: GraphView graph = (GraphView) findViewById(R.id.graph); graph.setTitle("RIS values by hour"); graph.getView
GraphView graph = (GraphView) findViewById(R.id.graph);
graph.setTitle("RIS values by hour");
graph.getViewport().setYAxisBoundsManual(true);
graph.getViewport().setMinY(-50);
graph.getViewport().setMaxY(30);
graph.getViewport().setXAxisBoundsManual(true);
graph.getViewport().setMinX(0);
graph.getViewport().setMaxX(24);
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {"12AM", "5AM", "10AM", "5PM", "10PM"});
graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
设置静态标签后,我的第一个标签始终重复。这个问题与我手动设置x轴的声明有关(graph.getViewport().setMaxX(24))。如果我将此数字设为非常大(即“500”),则标签将不再重复。但是,我的图表将不再与数据成比例(因为我的数据相当于一天24小时)。有没有人想过要打击这一点
我的代码如下:
GraphView graph = (GraphView) findViewById(R.id.graph);
graph.setTitle("RIS values by hour");
graph.getViewport().setYAxisBoundsManual(true);
graph.getViewport().setMinY(-50);
graph.getViewport().setMaxY(30);
graph.getViewport().setXAxisBoundsManual(true);
graph.getViewport().setMinX(0);
graph.getViewport().setMaxX(24);
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {"12AM", "5AM", "10AM", "5PM", "10PM"});
graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);