Chart2 Direct Legend Font Effects

Overview

The Legend parts of a Chart can be styled using the various style_* methods of the ChartLegend class.

Here we will see how to set options that are seen in Fig. 700.

Setup

General setup for this example.

from __future__ import annotations
from pathlib import Path
import uno
from ooo.dyn.awt.font_underline import FontUnderlineEnum
from ooo.dyn.awt.gradient_style import GradientStyle
from ooodev.format.inner.direct.write.char.font.font_effects import FontLine
from ooodev.calc import CalcDoc, ZoomKind
from ooodev.loader.lo import Lo
from ooodev.utils.color import StandardColor
from ooodev.utils.data_type.color_range import ColorRange

def main() -> int:
    with Lo.Loader(connector=Lo.ConnectPipe()):
        fnm = Path.cwd() / "tmp" / "piechart.ods"
        doc = CalcDoc.open_doc(fnm=fnm, visible=True)
        Lo.delay(500)
        doc.zoom(ZoomKind.ZOOM_100_PERCENT)

        sheet = doc.sheets[0]
        sheet["A1"].goto()
        chart_table = sheet.charts[0]
        chart_doc = chart_table.chart_doc
        _ = chart_doc.style_border_line(
            color=StandardColor.BRICK,
            width=1,
        )
        _ = chart_doc.style_area_gradient(
            step_count=64,
            style=GradientStyle.SQUARE,
            angle=45,
            grad_color=ColorRange(
                StandardColor.GREEN_DARK4,
                StandardColor.TEAL_LIGHT2,
            ),
        )
        legend = chart_doc.first_diagram.get_legend()
        if legend is None:
            raise ValueError("Legend is None")
        _ = legend.style_font_effect(
            color=StandardColor.PURPLE,
            underline=FontLine(
                line=FontUnderlineEnum.BOLDWAVE,
                color=StandardColor.GREEN_DARK2,
            ),
        )

        Lo.delay(1_000)
        doc.close()
    return 0

if __name__ == "__main__":
    SystemExit(main())

Apply the font effects to the Legend

Before formatting the chart is visible in Fig. 833.

from ooo.dyn.awt.font_underline import FontUnderlineEnum
from ooodev.format.inner.direct.write.char.font.font_effects import FontLine
# ... other code

_ = legend.style_font_effect(
    color=StandardColor.PURPLE,
    underline=FontLine(
        line=FontUnderlineEnum.BOLDWAVE,
        color=StandardColor.GREEN_DARK2,
    ),
)

Running the above code will produce the following output in Fig. 520 and Fig. 521.

Chart with Legend font effects applied

Fig. 520 Chart with Legend font effects applied

Chart Legend Font Effects Dialog

Fig. 521 Chart Legend Font Effects Dialog

Get the font effects for the Legend

# ... other code

f_style = legend.style_font_effect_get()
assert f_style is not None