Skip to main content
Associate II
December 12, 2023
Question

Dynamic Graph background color

  • December 12, 2023
  • 1 reply
  • 1244 views

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

This topic has been closed for replies.

1 reply

Graduate II
December 12, 2023

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

RichH81Author
Associate II
December 20, 2023

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.