This displays a waterfall with a total column:
JavaScript
x
11
11
1
import plotly.graph_objects as go
2
3
fig = go.Figure(
4
go.Waterfall(
5
measure = ["relative", "relative", "total"],
6
x = ["Sales", "Consulting", "Net revenue"],
7
y = [60, 80, 0],
8
)
9
)
10
fig.show()
11
However, if I change the x-axis to date strings then Plotly sees them as dates, converts them and then doesn’t show a total column:
JavaScript
1
11
11
1
import plotly.graph_objects as go
2
3
fig = go.Figure(
4
go.Waterfall(
5
measure = ["relative", "relative", "total"],
6
x = ["2022-01-01", "2022-01-02", "Net revenue"],
7
y = [60, 80, 0],
8
)
9
)
10
fig.show()
11
I’ve had a look at all the params for go.Waterfall
but I couldn’t see anything that might help.
Is there a way to use date strings and keep the total column?
Advertisement
Answer
If the x-axis is specified as a categorical variable, the total will be displayed.
JavaScript
1
12
12
1
import plotly.graph_objects as go
2
3
fig = go.Figure(
4
go.Waterfall(
5
measure = ["relative", "relative", "total"],
6
x = ["2022-01-01", "2022-01-02", "Net revenue"],
7
y = [60, 80, 0],
8
)
9
)
10
fig.update_xaxes(type='category')
11
fig.show()
12