Malik Mussabeheen Noor
Malik Mussabeheen Noor

Reputation: 864

Increasing decimal number of percentage in dash plotly pie chart

I am trying to plot a pie chart using dash and plotly but the problem is that when I plot it. It rounds off the percentage to 100% as it should be 99.97%.

it shows 100% but it must show something like 99.97%

dcc.Graph(
        id="piechart_2",
        figure={
            "data": [
                {
                    "labels": string_request,
                    "values": val_request,
                    "type": "pie",
                    "marker": {"line": {"color": "red", "width": 1}},
                }
            ],
            "layout": {

                "height":500,
                "width":500
            },
            'legend': {'x': 0, 'y': 1},

        },
    ),

it shows 100% but it must show something like 99.97%

Upvotes: 0

Views: 1736

Answers (1)

sentence
sentence

Reputation: 8913

You could create your own percentages and then show them by using textinfo:

import dash
import dash_core_components as dcc
import dash_html_components as html

import plotly.graph_objects as go

labels = ['bind','rpz']
values = [99.9628, 0.0372]
text = [str(i)+'%' for i in values]

fig = go.Figure(data=[go.Pie(labels=labels,
                             values=values,
                             text=text,
                             textinfo='text')])

app = dash.Dash()
app.layout = html.Div([dcc.Graph(figure=fig)])

app.run_server(debug=True,
               use_reloader=False)

and you get:

enter image description here

Upvotes: 1

Related Questions