This is a 3 part question.
1) First, is it possible to rotate the horizontal X values. Currently when I am trying to display all the days in a month on the X axis (4/1/2015, 4/2/2015, etc...) they will all bunch up and become unreadable. Is there a way to rotate the X-axis labels so they are vertical?
2) To setup the viewport, the documentation suggests to use:
graphview.getViewport().setScalable(true); graphview.getViewport().setScrollable(true); // To set a fixed manual viewport use this: // set manual X bounds graph.getViewport().setXAxisBoundsManual(true); graph.getViewport().setMinX(0.5); graph.getViewport().setMaxX(3.5); // set manual Y bounds graph.getViewport().setYAxisBoundsManual(true); graph.getViewport().setMinY(3.5); graph.getViewport().setMaxY(8);
However, the getViewport().setMinX(...)
function requires a double, not a date. Is there a way to scroll the viewport to show 3-5 dates at a time?
Code 2):
GraphView graph = (GraphView) graphView.findViewById(R.id.graph);
DataPoint[] stockArr = new DataPoint[dplist.size()];
stockArr = dplist.toArray(stockArr);
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(stockArr);
graph.addSeries(series);
graph.setTitle("TEST GRAPH");
// set date label formatter
graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(context));
graph.getViewport().setScalable(true);
graph.getViewport().setScrollable(true);
graph.getGridLabelRenderer().setNumHorizontalLabels(data.size()-1); // Approx 28-30
graph.getViewport().setXAxisBoundsManual(true);
graph.getViewport().setMinX(firstDate.getTime());
graph.getViewport().setMaxX(lastDate.getTime());
3) Is there a way to line up the bullet points with the Date labels? I modified my X labels with the following code. However, even before the change it seems like the bullet points are not lined up. In the picture below, 1/1 should be the first point, 1/2 should be the 2nd point, and 1/3 should be the third point. Any ideas?
Code 3):
graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(context) {
@Override
public String formatLabel(double value, boolean isValueX) {
if (isValueX) {
// show normal x values
Calendar c = Calendar.getInstance();
// set time in milliseconds
c.setTimeInMillis(((long)value));
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
System.out.println((mMonth+1) + "/" + mDay);
// Return Month/Day
return (mMonth+1) + "/" + mDay;
//return super.formatLabel(newDate.toString(), isValueX);
} else {
// show currency for y values
return super.formatLabel(value, isValueX);
}
}
});