Reputation: 97
this is picture of GraphView.enter image description here As you see Texts are black color. I want change this color to white. How can i change of this texts?
public class MainActivity extends AppCompatActivity {
GraphView graph;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
graph = (GraphView) findViewById(R.id.graph);
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {"Yan", "Fev", "Mart", "Apr", "May", "Iyn",
"Iyl", "Avq", "Sent", "Okt", "Noy", "Dek"});
//staticLabelsFormatter.setVerticalLabels(new String[] {"low", "middle", "high", "koko"});
graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[] {
new DataPoint(0, 2),
new DataPoint(1,5),
new DataPoint(2, 4),
new DataPoint(3, 4),
new DataPoint(4, 8),
new DataPoint(5, 6),
new DataPoint(6, 8),
new DataPoint(7, 1),
new DataPoint(8, 5),
new DataPoint(9, 2),
new DataPoint(10, 7),
new DataPoint(11, 3),
});
series.setColor(Color.YELLOW);
series.setDrawBackground(true);
series.setDrawDataPoints(true);
graph.addSeries(series);
}
Upvotes: 0
Views: 1411
Reputation: 2678
I also encountered this problem, unfortunately, due to lack of documentation of GraphView methods, I was on the verge of shifting to MPAndroidChart but I thought of giving one more try to change label color in GraphView. Thus, the following is the solution I found out:
graph.getGridLabelRenderer().setVerticalLabelsColor(Color.WHITE);
graph.getGridLabelRenderer().setHorizontalLabelsColor(Color.WHITE);
graph.getGridLabelRenderer().setVerticalLabelsColor(Color.WHITE);
graph.getGridLabelRenderer().setHorizontalLabelsColor(Color.WHITE);
graph.getGridLabelRenderer().reloadStyles();
Thus merging these lines with the provided code:
public class MainActivity extends AppCompatActivity {
GraphView graph;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
graph = (GraphView) findViewById(R.id.graph);
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {"Yan", "Fev", "Mart", "Apr", "May", "Iyn",
"Iyl", "Avq", "Sent", "Okt", "Noy", "Dek"});
//staticLabelsFormatter.setVerticalLabels(new String[] {"low", "middle", "high", "koko"});
graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
//First two lines change the grid line color
graph.getGridLabelRenderer().setGridColor(Color.WHITE);
graph.getGridLabelRenderer().setHighlightZeroLines(false);
//Below two lines change the label color
graph.getGridLabelRenderer().setVerticalLabelsColor(Color.WHITE);
graph.getGridLabelRenderer().setHorizontalLabelsColor(Color.WHITE);
graph.getGridLabelRenderer().reloadStyles();
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[] {
new DataPoint(0, 2),
new DataPoint(1,5),
new DataPoint(2, 4),
new DataPoint(3, 4),
new DataPoint(4, 8),
new DataPoint(5, 6),
new DataPoint(6, 8),
new DataPoint(7, 1),
new DataPoint(8, 5),
new DataPoint(9, 2),
new DataPoint(10, 7),
new DataPoint(11, 3),
});
series.setColor(Color.YELLOW);
series.setDrawBackground(true);
series.setDrawDataPoints(true);
graph.addSeries(series);
}
Upvotes: 1