2

I'm plotting values by hour in my application and instead of the horizontal x-axis labels showing as just "0", "5", "10" (for hour 0, hour 5, hour 10, etc.), I wanted to customize the labels with the actual time of day (i.e. "12AM" for "0", "5AM" for "5", "10AM" for "10").

Without the static labels set, the horizontal labels appear as below:

enter image description here

With the static labels set, my first label always repeats. The issue pertains to my declaration of a manually set x-axis (graph.getViewport().setMaxX(24)). If I make this number very large (i.e. '500'), the label no longer repeats. But then, my graph will no longer be proportionate to the data (since my data corresponds to 24 hours in a day). Does anyone have any thought on combating this?

enter image description here

My code is as below:

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);
wnjl
  • 162
  • 1
  • 10

0 Answers0