Plotly bar chart attributes

I’m playing around with bar charts and formats.

But I can’t work out from the plotly documentation how to change the width, colour etc of bar charts.


    # Any code you write here will run when the form opens.
    self.plot_journal_entries_2.data = go.Bar(x=[1,2])

Does anyone by any chance know how to define the graph’s attributes?
Thank you so much Anvil gurus…

You can pass the marker argument to go.Bar
There is a good example of this in Shaun’s blog post
In this case he passes marker=dict(color='#0343df') to set the colour.

3 Likes

Thanks @thomas.campbell.

Is size in there too?

You can change the width of the bars by passing the width argument to go.Bar

I took the example from the help file and amended it slightly to show how to change colour and width: https://anvil.works/build#clone:LOL4TU2TTFIZDQXE=NTSWSUQ3CBIXHGMTN44RSXBK

1 Like

Thanks. And particularly thanks for the code e.g.

 self.plot_1.data = [
      go.Bar(
        x = [1, 2, 3],
        y = [3, 1, 6],
        name = 'Bar Chart Example',
        marker=dict(color='#123456'),
        width=0.5
        )
    ]
    self.init_components(**properties)    '''

Please forgive another basic question though, why does your code have the square brackets before the go.Bar. Sometimes the go.Bar doesn't seem to need the [] to work.

The square brackets are there because originally there was also a scatter plot afterwards but I got rid of it. You can ignore them. I have basically accidentally formed a list of length 1. I have now amended it for you.

1 Like

Darn. You’re good. Thanks for the time.
:wink:

2 Likes