✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Pie Chart Legend from list not working

Hi

I am having an issue with my pie chart legends in Dash.

dcc.Graph(
                    id='Graph8',
                    figure={
                        'data' : gen_pie_chart(args),
                        'legend' : pie_labels,
                        'layout' : go.Layout(
                            title='Title of chart',
                            legend=dict(traceorder='normal'),
                        )
                    },
                ),

The “pie_labels” variable is a list, which is generated from the following bit of code:

def Get_Values2(data):
      x_values = []
      for index, row in data.iteritems():     
            x_values.append(index)
      return x_values

pie_labels = Get_Values2(a_pandas_series)

But the result I’m getting is the labels are numbers 0 to 5, rather than the text labels that are the index of the series object that I’ve sent to “Get_Values2”:

Untitled Untitled

If I print(pie_labels) I get:

[‘0 - 100’, ‘100 - 200’, ‘1000 +’, ‘200 - 300’, ‘300 - 400’, ‘400 - 1000’]

Which are the labels I want.

Any pointers? I’m sure there’s something really simple I’m missing!

Thanks

Chris

Could you try replacing your graph code with hardcoded data (rather than a function call)? That’d help us debug a bit more.

Hi

Have changed that line in graph8 figure to this

'legend' : ['0 - 100', '100 - 200', '1000 +', '200 - 300', '300 - 400', '400 - 1000'],

And I’m getting the same output - labels numbers 0 to 5

Thanks

Chris

I mean rather, the entire graph, something like:

dcc.Graph(
    figure={
         'data': [{
                 'labels': [1, 2, 3], 
                 'values': [1, 2, 3], 
                 'type': 'pie',
          }]
    }
)

Thank you - that helped me sort the issue - I did not have ‘labels’ returned from my function! I thought that was dealt with by the ‘legend’ in my graph code.

Thanks for your help

Chris

1 Like