Chart2 Direct Legend Font
Overview
The Legend parts of a Chart can be styled using the various style_*
methods of the ChartLegend
class.
The style_font_general()
method combines some of the option of style_font()
and style_font_effects()
into a single class. Also a few more options are added.
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.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_font_general(b=True, color=StandardColor.PURPLE, size=12)
# f_style = legend.style_font_get()
# assert f_style is not None
Lo.delay(1_000)
doc.close()
return 0
if __name__ == "__main__":
SystemExit(main())
Apply the font effects to the Legend
Before formatting the chart is visible in Fig. 833.
# ... other code
_ = legend.style_font_general(b=True, color=StandardColor.PURPLE, size=12)
Running the above code will produce the following output in Fig. 519.