I cannot make the color of the numbers in the gauge scale and the “value” number displayed to be different colours using the scale and color properties. But I can change it with a custom.css file. Which is not very useful as I want the color of the “current_value” to change dynamically (green, yellow & red) depending on the number value. I have attached a pic of the dash daq.gauge which I want (created with css, not daq properties).
I am using the “scale” property to have a custome scale:
scale=custom_gauge_scale,
custom_gauge_scale = {‘custom’: {
‘0’: {‘label’: ‘0’, ‘style’: {‘color’: ‘white’, ‘font-size’: ‘20px’ }}, ‘10’: {‘label’: ’ ', ‘style’: {‘font-size’: ‘10px’}},
‘20’: {‘label’: ‘20’, ‘style’: {‘color’: ‘white’,‘font-size’: ‘20px’}}, ‘30’: {‘label’: ’ ', ‘style’: {‘font-size’: ‘10px’}},
‘40’: {‘label’: ‘40’, ‘style’: {‘color’: ‘white’,‘font-size’: ‘20px’}}, ‘50’: {‘label’: ’ ', ‘style’: {‘font-size’: ‘10px’}},
‘60’: {‘label’: ‘60’, ‘style’: {‘color’: ‘white’,‘font-size’: ‘20px’}}, ‘70’: {‘label’: ’ ', ‘style’: {‘font-size’: ‘10px’}},
‘80’: {‘label’: ‘80’, ‘style’: {‘color’: ‘white’,‘font-size’: ‘20px’}}, ‘90’: {‘label’: ’ ', ‘style’: {‘font-size’: ‘10px’}},
‘100’: {‘label’: ‘100’, ‘style’: {‘color’: ‘white’,‘font-size’: ‘20px’}},
},
}
The label, font-size is recognized, but the color is not applied, even if it is read and accepted.
The value of the current value is defined here:
color={“default”: disc_pct_col, “gradient”: True,“ranges”: {“red”: [0,20],“yellow”: [20,40],“green”: [40,100]}}
where for example disc_pct_col = “yellow”
the value property is: value=pct_disc,
pct_disc = 30
These css parms do work, but they are not useful or a good way to dynamically specify this.
- This is the actual number in the bottom middle of the pct disc gauge /
.sc-gqjmRU.eVTJwt {
color: #b01212;
}
/ This is the scale numbers col in the pct discount gauga fix */
.cRfgdB.scale {
color: #fff;
}
Summary I cannot get the daq.gauge properties to have different values for the value and the numbers in the scale.
Full code:
custom_gauge_scale = {‘custom’: {
‘0’: {‘label’: ‘0’, ‘style’: {‘color’: ‘white’, ‘font-size’: ‘20px’ }}, ‘10’: {‘label’: ’ ', ‘style’: {‘font-size’: ‘10px’}},
‘20’: {‘label’: ‘20’, ‘style’: {‘color’: ‘white’,‘font-size’: ‘20px’}}, ‘30’: {‘label’: ’ ', ‘style’: {‘font-size’: ‘10px’}},
‘40’: {‘label’: ‘40’, ‘style’: {‘color’: ‘white’,‘font-size’: ‘20px’}}, ‘50’: {‘label’: ’ ', ‘style’: {‘font-size’: ‘10px’}},
‘60’: {‘label’: ‘60’, ‘style’: {‘color’: ‘white’,‘font-size’: ‘20px’}}, ‘70’: {‘label’: ’ ', ‘style’: {‘font-size’: ‘10px’}},
‘80’: {‘label’: ‘80’, ‘style’: {‘color’: ‘white’,‘font-size’: ‘20px’}}, ‘90’: {‘label’: ’ ', ‘style’: {‘font-size’: ‘10px’}},
‘100’: {‘label’: ‘100’, ‘style’: {‘color’: ‘white’,‘font-size’: ‘20px’}},
},
}
units_style = “%” # testing if parms can be passed to units as a dict, not working.
reference_disc_pct=40
disc_limit_low = 20
disc_limit_med = 40
disc_pct_col = “yellow” # test vals
pct_disc = 30 # test vals
def plot_results():
app = Dash(name) # Initialize the app
app.layout = html.Div([daq.Gauge(
id=‘discount-gauge’,
label={‘label’:“Overall Discount (%)”, ‘style’:{‘color’: ‘white’, ‘font-size’: ‘100%’}},
value=pct_disc,
scale=custom_gauge_scale,
max=100,
min=0,
showCurrentValue=True,
units=units_style,
color={“gradient”: True,“ranges”: {“red”: [0,20],“yellow”: [20,40],“green”: [40,100]}}
#color={“default”: disc_pct_col, “gradient”: True,“ranges”: {“red”: [0,20],“yellow”: [20,40],“green”: [40,100]}}
)
], style={‘background’: cprice_bgv1, ‘font-family’: ‘Arial’},)
#], style={‘background’: ‘black’, ‘paper_bgcolor’: ‘black’})
app.run(debug=True)
return
sw vers:
dash: 3.0.4
dcc: 3.0.6
html: 3.0.2
dash_table: 6.0.2
plotly: 6.0.1
Thanks for your help/advice & solutions,