2

I am attempting to set the background color of a GraphView (http://android-graphview.org). I looked at the following StackOverflow question: https://stackoverflow.com/questions/24276370/changing-graphview-background-not-working but there was no joy. I also took a peek at the GraphView demos at: https://github.com/jjoe64/GraphView-Demos but unfortunately, none of them set the background color to something other than white. So, what I did try was:

graphView.setBackgroundColor(getResources().getColor(R.color.teal));

and I also tried:

graphView.setBackgroundColor(getResources().getColor(R.color.teal));
((LineGraphView) graphView).setDrawBackground(true);

neither wanted to work. Thoughts on what I need to do?

Community
  • 1
  • 1
Perry Hoekstra
  • 2,687
  • 3
  • 33
  • 52

1 Answers1

3

Your code looks fine - that should work perfectly. It does for me:

graphView.setDrawBackground(true);
graphView.setBackgroundColor(getResources().getColor(android.R.color.holo_green_light));

If you want the series to have a slightly transparent background, you can set an alpha-color value:

graphView.setBackgroundColor(Color.argb(50, 50, 0, 200));

As an aside, if you are looking to set the background for each series independantly, I have left the details on another question:

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
  • 1
    Thank you for the Background/each series link, it was very useful to some other things I was attempting. – Perry Hoekstra Aug 06 '14 at 16:30
  • I thought it might be, because I found your question while trying to solve my issue, which prompted me to write the code myself. – Richard Le Mesurier Aug 06 '14 at 16:47
  • @RichardLeMesurier, can you look at this question and give some hint. http://stackoverflow.com/questions/34011301/graphview-android-color-under-graph-flickering-issue I am facing some issues regarding `GraphView`. – Saad Saadi Dec 04 '15 at 03:33
  • @Saad it has been a year since I have worked on this library and unfortunately I am unable to help further. Good luck – Richard Le Mesurier Dec 04 '15 at 05:26
  • @RichardLeMesurier. can you answer this question-http://stackoverflow.com/questions/31260218/make-grid-lines-invisible-android-graphview – abh22ishek Apr 28 '16 at 09:03