Chart2 Direct Title/Subtitle Font Effects (Static)

Overview

The ooodev.format.chart2.direct.title.font.FontEffects class gives you the similar options as Fig. 818 Font Effects Dialog, but without the dialog.

Calls to the Chart2.style_title() and Chart2.style_subtitle() methods are used to set the Title and Subtitle font effects of a Chart.

Setup

General setup for this example.

import uno
from ooodev.format.chart2.direct.title.font import FontEffects as TitleFontEffects
from ooodev.format.chart2.direct.title.font import FontUnderlineEnum, FontLine
from ooodev.format.chart2.direct.general.borders import LineProperties as ChartLineProperties
from ooodev.format.chart2.direct.general.area import Gradient as ChartGradient
from ooodev.format.chart2.direct.general.area import GradientStyle, ColorRange
from ooodev.office.calc import Calc
from ooodev.office.chart2 import Chart2
from ooodev.utils.color import StandardColor
from ooodev.gui import GUI
from ooodev.loader.lo import Lo

def main() -> int:
    with Lo.Loader(connector=Lo.ConnectPipe()):
        doc = Calc.open_doc("pie_flat_chart.ods")
        GUI.set_visible(True, doc)
        Lo.delay(500)
        Calc.zoom(doc, GUI.ZoomEnum.ZOOM_100_PERCENT)

        sheet = Calc.get_active_sheet()

        Calc.goto_cell(cell_name="A1", doc=doc)
        chart_doc = Chart2.get_chart_doc(sheet=sheet, chart_name="pie_chart")

        chart_bdr_line = ChartLineProperties(color=StandardColor.PURPLE_DARK1, width=0.7)
        chart_grad = ChartGradient(
            chart_doc=chart_doc,
            step_count=64,
            style=GradientStyle.SQUARE,
            angle=45,
            grad_color=ColorRange(StandardColor.BLUE_DARK1, StandardColor.PURPLE_LIGHT2),
        )
        Chart2.style_background(chart_doc=chart_doc, styles=[chart_grad, chart_bdr_line])

        title_font_effect = TitleFontEffects(
            color=StandardColor.RED,
            underline=FontLine(line=FontUnderlineEnum.SINGLE, color=StandardColor.BLUE),
            shadowed=True,
        )
        Chart2.style_title(chart_doc=chart_doc, styles=[title_font_effect])

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

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

Apply the font effects to the data labels

Before formatting the chart is seen in Fig. 832.

Apply to Title

from ooodev.format.chart2.direct.title.font import FontEffects as TitleFontEffects
from ooodev.format.chart2.direct.title.font import FontUnderlineEnum, FontLine
# ... other code

title_font_effect = TitleFontEffects(
    color=StandardColor.RED,
    underline=FontLine(line=FontUnderlineEnum.SINGLE, color=StandardColor.BLUE),
    shadowed=True,
)
Chart2.style_title(chart_doc=chart_doc, styles=[title_font_effect])

Running the above code will produce the following output in Fig. 817 and Fig. 818.

Chart with title font effects applied

Fig. 817 Chart with title font effects applied

Chart Title Dialog Font Effects

Fig. 818 Chart Title Dialog Font Effects

Apply to Subtitle

# ... other code
Chart2.style_subtitle(chart_doc=chart_doc, styles=[title_font_effect])

Running the above code will produce the following output in Fig. 819.

Chart with subtitle font effects applied

Fig. 819 Chart with subtitle font effects applied