Grafana - Panel Plugin - How to access the colors of my palette in my code?

Hello Everybody,

I just want to access the colors set at my Panel Plugin → Standard Options → Color scheme → Classic palette in my code. For example:

image

Do I need to change something at my module.ts file ?
Are these colors are direct accessed through the data field? However, I did not find it.

Thank you very much in advance!

Your Sincerely,
Turtles

Hello Everybody,

I found the solution.
I am posting here: at your function app component, just import the useTheme2 like:

import { Alert, useTheme, useTheme2 } from ‘@grafana/ui’;

Then use this in your code like:

const theme = useTheme2();
const palette = theme.visualization.palette

I am still open for a better solution!
I hope I could help someone!
Thanks!

Cheers,
Marcelo

1 Like

i had the same question and got a suggestion

but i haven’t had time to test the suggested solution

2 Likes