Chart2 Direct Axis Font Effects
Overview
The style_font_effect()
method gives similar options for data labels
as Fig. 664 Font Effects 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 ooo.dyn.awt.font_underline import FontUnderlineEnum
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
from ooodev.format.inner.direct.write.char.font.font_effects import FontLine
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_color(
color=StandardColor.GREEN_LIGHT2
)
_ = 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_effect(
color=StandardColor.RED,
underline=FontLine(
line=FontUnderlineEnum.SINGLE, color=StandardColor.BLUE
),
shadowed=True,
)
Lo.delay(1_000)
doc.close()
return 0
if __name__ == "__main__":
SystemExit(main())
Apply the font effects Axis
Before formatting the chart is seen in Fig. 827.
Style Y-Axis
from ooo.dyn.awt.font_underline import FontUnderlineEnum
from ooodev.format.inner.direct.write.char.font.font_effects import FontLine
# ... other code
_ = chart_doc.axis_y.style_font_effect(
color=StandardColor.RED,
underline=FontLine(
line=FontUnderlineEnum.SINGLE, color=StandardColor.BLUE
),
shadowed=True,
)
Running the above code will produce the following output in Fig. 484 and Fig. 485.
Fig. 484 Chart with Y-Axis font effects applied
Fig. 485 Chart Data Labels Dialog Font Effects
Style Secondary Y-Axis
# ... other code
y2_axis = chart_doc.axis2_y
if y2_axis is not None:
_ = y2_axis.style_font_effect(
color=StandardColor.RED,
underline=FontLine(line=FontUnderlineEnum.SINGLE, color=StandardColor.BLUE),
shadowed=True,
)
Running the above code will produce the following output in Fig. 486.
Fig. 486 Chart with Y-Axis font effects applied
Getting the font effects style
For all Axis properties you can get the font effects style using the style_font_effect_get()
method.
# ... other code
y2_axis = chart_doc.axis2_y
if y2_axis is not None:
f_style = chart_doc.axis_y.style_font_effect_get()
assert f_style is not None