Chart2 Direct Series Data Labels Font Only

Overview

The ooodev.format.chart2.direct.series.data_labels.font.FontOnly class gives you similar options for data labels as Fig. 788 Font Dialog, but without the dialog.

Calls to the Chart2.style_data_series() and Chart2.style_data_point() methods are used to set the data labels font of a Chart.

Setup

General setup for this example.

from __future__ import annotations
from pathlib import Path
import uno
from ooodev.calc import CalcDoc, ZoomKind
from ooodev.loader.lo import Lo
from ooodev.format.inner.preset.preset_gradient import PresetGradientKind
from ooodev.utils.color import StandardColor

def main() -> int:
    with Lo.Loader(connector=Lo.ConnectPipe()):
        fnm = Path.cwd() / "tmp" / "col_chart.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.BLUE_LIGHT3,
            width=0.7,
        )
        _ = chart_doc.style_area_gradient_from_preset(
            preset=PresetGradientKind.TEAL_BLUE,
        )

        ds = chart_doc.get_data_series()[0]
        ds.style_font(name="Lucida Calligraphy", size=14, font_style="italic")

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

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

Apply the font to Data Labels

Before formatting the chart is seen in Fig. 829.

Style Data Series

# ... other code
ds = chart_doc.get_data_series()[0]
ds.style_font(name="Lucida Calligraphy", size=14, font_style="italic")

Running the above code will produce the following output shown in Fig. 607 and Fig. 608.

Chart with Data Series Labels Font set

Fig. 607 Chart with Data Series Labels Font set

Chart Data Labels Dialog Font

Fig. 608 Chart Data Labels Dialog Font

Style Data Point

# ... other code
ds = chart_doc.get_data_series()[0]
dp = ds[0]
dp.style_font(name="Lucida Calligraphy", size=14, font_style="italic")

Running the above code will produce the following output shown in Fig. 609.

Chart with Data Point Label Font set

Fig. 609 Chart with Data Point Label Font set