Chart2 Direct Axis Font Only

Overview

The style_font() method gives similar options as Fig. 667 Font Dialog, but without the dialog.

Setup

General setup for this example.

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.utils.color import StandardColor
from ooodev.loader.lo import Lo
from ooodev.utils.data_type.color_range import ColorRange
from ooodev.utils.data_type.offset import Offset

def main() -> int:
    with Lo.Loader(connector=Lo.ConnectPipe()):
        fnm = Path.cwd() / "tmp" / "bon_voyage.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.GREEN_DARK2, width=0.9)
        _ = chart_doc.style_area_gradient(
            step_count=0,
            offset=Offset(41, 50),
            style=GradientStyle.RADIAL,
            grad_color=ColorRange(StandardColor.TEAL, StandardColor.YELLOW_DARK1),
        )
        _ = chart_doc.axis_y.style_font(
            name="Lucida Calligraphy", size=14, font_style="italic"
        )

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


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

Apply Font Only

Before formatting the chart is seen in Fig. 827.

Apply to Y-Axis

# ... other code

_ = chart_doc.axis_y.style_font(
    name="Lucida Calligraphy", size=14, font_style="italic"
)

Running the above code will produce the following output shown in Fig. 487 and Fig. 488.

Chart with Y-Axis Font set

Fig. 487 Chart with Y-Axis Font set

Chart Y-Axis Dialog Font

Fig. 488 Chart Y-Axis Dialog Font

Apply to X-Axis

# ... other code
_ = chart_doc.axis_x.style_font(
    name="Lucida Calligraphy", size=14, font_style="italic"
)

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

Chart with Y-Axis Font set

Fig. 489 Chart with Y-Axis Font set

Getting the font style

For for all the Axis properties you can get the font style using the style_font_get() method.

# ... other code
f_style = chart_doc.axis_y.style_font_get()
assert f_style is not None