PlotlyDash: How to change line color?

Viewed 2288

I'm using plotly dash to create a line chart and want to change the lines to a specific color. You'll see this in my code, but it doesn't change the colors from the default. I'm guessing I'm doing this wrong. There is a way to change the color right? And if so, how do I fix this?

dcc.Graph(id='henry',
        figure={
            'data':[
                {'x':dates,'y':henrycases,'type':'line','name':'Cases','color':'red'},
                {'x':dates,'y':henrydf,'type':'line','name':'Wait Time','color':'black'}
                ],
            'layout':{
                'title':'Henry County Wait Time and New Cases per Day'
                }
1 Answers

You can specify the line colors like this

dcc.Graph(
    id='henry',
    figure={
        'data': [
            {'x':dates,'y':henrycases,'type':'line','name':'Cases','line':dict(color='red')},
            {'x':dates,'y':henrydf,'type':'line','name':'Wait Time','line':dict(color='black')}
        ],
        'layout': {
            'title':'Henry County Wait Time and New Cases per Day'
        }
    }
)

Alternatively like this

dcc.Graph(
    id='henry',
    figure={
        'data': [
            {'x':dates,'y':henrycases,'type':'line','name':'Cases','line_color':'red'},
            {'x':dates,'y':henrydf,'type':'line','name':'Wait Time','line_color':'black'}
        ],
        'layout': {
            'title':'Henry County Wait Time and New Cases per Day'
        }
    }
)
Related