bar chart fixes (#6667)

This commit is contained in:
Danglewood
2024-09-15 08:12:16 -07:00
committed by GitHub
parent d9ebf73c33
commit 77e22cc7ef
2 changed files with 14 additions and 18 deletions

View File

@@ -426,7 +426,8 @@ def bar_chart( # noqa: PLR0912
bar_df = data.copy().set_index(x) # type: ignore
y = y.split(",") if isinstance(y, str) else y
hovertemplate = bar_kwargs.pop("hovertemplate", None)
width = bar_kwargs.pop("width", None)
for item in y:
figure.add_bar(
x=bar_df.index if orientation == "v" else bar_df[item],
@@ -436,11 +437,19 @@ def bar_chart( # noqa: PLR0912
legendgroup=bar_df[item].name,
orientation=orientation,
hovertemplate=(
"%{fullData.name}:%{y}<extra></extra>"
if orientation == "v"
else "%{fullData.name}:%{x}<extra></extra>"
hovertemplate
if hovertemplate
else (
"%{fullData.name}:%{y}<extra></extra>"
if orientation == "v"
else "%{fullData.name}:%{x}<extra></extra>"
)
),
width=(
width
if width
else 0.95 / len(y) * 0.75 if barmode == "group" and len(y) > 1 else 0.95
),
width=0.95 / len(y) * 0.75 if barmode == "group" and len(y) > 1 else 0.95,
**bar_kwargs,
)

View File

@@ -925,19 +925,6 @@ class OpenBBFigure(go.Figure):
if data.get("layout", {}):
pio.show(data, *args, **kwargs)
self.update_layout(
legend=dict(
orientation=(
"v"
if not self.layout.legend.orientation
else self.layout.legend.orientation
),
),
barmode="overlay",
bargap=0,
bargroupgap=0,
)
return pio.show(self, *args, **kwargs)
def _xaxis_tickformatstops(self) -> None: