Chart2 Direct Legend Border

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. 697.

Setup

from __future__ import annotations
from pathlib import Path
import uno
from ooo.dyn.awt.gradient_style import GradientStyle
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_border_line(
            color=StandardColor.BRICK,
            width=0.8,
            transparency=20,
        )

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

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

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

Applying Border Style

The style_border_line() method is used to set the title and subtitle border line properties.

Before formatting the chart is seen in Fig. 833.

from ooodev.format.chart2.direct.legend.borders import LineProperties as LegendLineProperties
# ... other code

_ = legend.style_border_line(
    color=StandardColor.BRICK,
    width=0.8,
    transparency=20,
)

The results are seen in Fig. 517 and Fig. 518.

Chart with title border set

Fig. 517 Chart with title border set

Chart Data Series Borders Default Dialog

Fig. 518 Chart Data Series Borders Default Dialog

Getting Border Style

# ... other code

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