superset icon indicating copy to clipboard operation
superset copied to clipboard

Are there any ways to set the color for the chart specifically

Open ijyun opened this issue 9 years ago • 23 comments

Hi team, Right now,When I refresh the dashboard the color of the chart would change automatically.I want to set the color for the chart and dont' change after refresh. Could you please tell me are there any ways? Thanks

ijyun avatar Mar 30 '17 10:03 ijyun

@ijyun - not at the moment. Could be an interesting feature to implement. I know several people have enquired about it.

alanmcruickshank avatar Mar 31 '17 13:03 alanmcruickshank

It's somewhat challenging. Currently we guarantee that metrics of the same name in a dashboard will be the same color across charts.

There's this function/object that cycles through the palette and provide a new color for new expressions and memoizes as it goes. If you ask for Metric 1 twice it'll give you the same color.

Early on I would hash "Metric 1" and provide a color based on the hash so that "Metric 1" would ALWAYS be the same color. The problem there was that with say 8 colors, you relatively often get in situation where a chart with say 2 or 3 metrics will get the same color twice, and that's no good. A chart with "Metric 1" and "Metric 2" might have the same color for both 1 out of 8 times...

Someone in the community said they pre-populate that memoized object with an array of all their important metrics.

For reference: https://github.com/airbnb/superset/blob/master/superset/assets/javascripts/modules/colors.js#L51

Somehow f you call category21 for an array of metrics, before you render the dashboard, colors for these metrics will be deterministic.

mistercrunch avatar Apr 03 '17 03:04 mistercrunch

Hi mistercrunch we are interesting in this feature, can you give an advise to understand better the mechanism how is working now and how we can implement this feature .

Thanks

olegIn80 avatar Jul 26 '17 13:07 olegIn80

It'd be nice to support different color schemes, and allow people to pick a default in their environment. It would also be nice to make "Colors" one of the core set of controls, cohesive across visualizations, but that's a bit more complicated.

For now the categorical colors are defined here: https://github.com/apache/incubator-superset/blob/master/superset/assets/javascripts/modules/colors.js#L6

A first step might be to define an object with different color sets, and add a new control to most visualizations that would allow to pick the color set. And add a new DEFAULT_COLOR_SET variable in superset/config.py.

mistercrunch avatar Jul 26 '17 16:07 mistercrunch

Hello guys! Do you have any update about that?

In my company different products use different colors but same superset, in my particular case I can not use unique color pallet.

renanoliveira avatar Jan 16 '18 13:01 renanoliveira

It's somewhat easy to add new palettes and set one as default but you'll have to do this in your fork. https://github.com/apache/incubator-superset/blob/master/superset/assets/javascripts/modules/colors.js#L130

It could be nice to add an environment variable to define your default color scheme without having to alter the code and bake your own build.

mistercrunch avatar Jan 17 '18 19:01 mistercrunch

Agreed, this would be a great feature to have. To be able to change colors for any chart customized for each breakdown of the Group By feature.

For example, have a pie chart with 2 different categories and custom pick which colors those categories show up in the pie chart. See below image as an example. 2018-06-07_9-41-35

shinabarger avatar Jun 07 '18 13:06 shinabarger

There's now a way to do this that should work in most cases: http://superset.apache.org/faq.html#is-there-a-way-to-force-the-use-specific-colors

mistercrunch avatar Jun 07 '18 17:06 mistercrunch

There's now a way to do this that should work in most cases: http://superset.apache.org/faq.html#is-there-a-way-to-force-the-use-specific-colors

mistercrunch avatar Jun 07 '18 18:06 mistercrunch

@mistercrunch I tried to enforce a colors in the link described way but wasn't really successful. Have you experience in defining colors in superset and maybe a more precise experience?

frischknechtna avatar Jun 22 '18 14:06 frischknechtna

@mistercrunch I've also tried that method as SO question without success.

dominijk avatar Jan 31 '19 12:01 dominijk

screen shot 2019-01-31 at 9 50 16 pm screen shot 2019-01-31 at 9 49 33 pm

{"filter_immune_slices": [], "timed_refresh_immune_slices": [], "filter_immune_slice_fields": {}, "expanded_slices": {}, "default_filters": "{}",
"label_colors": {
        "Girls": "#FF69B4",
        "Boys": "#ADD8E6"
    }
}

mistercrunch avatar Feb 01 '19 05:02 mistercrunch

I got that to work but for me the chart must also be set to the default colour scheme

dominijk avatar Feb 01 '19 14:02 dominijk

Wait do you want to set colors a specific way or do you want the default color scheme?

mistercrunch avatar Feb 01 '19 16:02 mistercrunch

Specific colours for keys but these persist across an entire instance of superset. Per dashboard is fine but I will test as a scheme if that can be key specific?

With the dashboard code it will only alter the chart if the chart is using the default colour scheme (for me) if you select a different colour scheme the override does not work.

dominijk avatar Feb 01 '19 20:02 dominijk

I'd be nice to add a global environment setting for this, I'm not sure why this only applies to the default color scheme, but that's not the intended behavior.

mistercrunch avatar Feb 01 '19 21:02 mistercrunch

I can confirm you have to have this set to the default color scheme to work.

mlberg avatar Feb 10 '19 14:02 mlberg

@mistercrunch How do I get to the "JSON Metadata" view from your top screenshot?

rangerscience avatar Mar 12 '19 21:03 rangerscience

@rangerscience viewing the dashboard, click "Edit Dashboard", then click the ▼ menu and select "edit dashboard metadata".

Screen Shot 2019-04-01 at 10 56 17 AM

danmdoh avatar Apr 01 '19 17:04 danmdoh

HI @mistercrunch I have tried ur method but it is showing an error has occurred I have given exactly without any error can u give some more info regarding this

mohan770 avatar Apr 02 '20 16:04 mohan770