cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Graph background color

RichH81
Associate II

Hello, This seems like a basic question but I can't seem to find an answer anywhere: I'd like to change the background color of the dynamic graph from white to some other color (black ideally). This would be the entire background color I'm after, not just the color below the line as it's drawn. In all examples of the dynamic graph the background is always white so I'm sort of wondering if this is even possible?

I noticed in MainViewBase.cpp when the graph is being drawn initially a background is added and it is explicitly set to white so it seems like this could be some other color?

graphBackground.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
..
add(graphBackground);

 

Is there a way to change this?

 

Thanks!

Rich

2 REPLIES 2
JTP1
Lead

Hello

just add for example something like this:

graphBackground.setColor(touchgfx::Color::getColorFromRGB(0, 0, 0)); // black BG
graphMajorXAxisLabel.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255)); // white X labels
graphMajorYAxisLabel.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255)); // White Y labels
graphMajorYAxisGrid.setColor(touchgfx::Color::getColorFromRGB(100, 100, 100)); // grey Y drid lines

 to your view.cpp setupScreen- function.

Remember to include color.hpp to view.cpp file

#include <touchgfx/Color.hpp>

Br JTP

Thank you for that!. I also discovered another way to do this is to create a background black image and put it behind the graph and then set the graph transparency.