Chart2 Direct Series Data Labels Font Effects (Static)

Overview

The ooodev.format.chart2.direct.series.data_labels.font.FontEffects class gives you the similar options for data labels as Fig. 786 Font Effects 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 effects of a Chart.

Setup

General setup for this example.

import uno
from ooodev.format.chart2.direct.general.area import Gradient as ChartGradient, PresetGradientKind
from ooodev.format.chart2.direct.general.borders import LineProperties as ChartLineProperties
from ooodev.format.chart2.direct.series.data_labels.font import FontEffects as LblFontEffects
from ooodev.format.chart2.direct.series.data_labels.font import FontLine, FontUnderlineEnum
from ooodev.office.calc import Calc
from ooodev.office.chart2 import Chart2
from ooodev.utils.color import CommonColor
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(Path.cwd() / "tmp" / "col_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="col_chart")

        chart_bdr_line = ChartLineProperties(color=StandardColor.BLUE_LIGHT3, width=0.7)
        chart_grad = ChartGradient.from_preset(chart_doc, PresetGradientKind.TEAL_BLUE)
        Chart2.style_background(chart_doc=chart_doc, styles=[chart_grad, chart_bdr_line])

        data_lbl_font = LblFontEffects(
            color=CommonColor.RED,
            underline=FontLine(line=FontUnderlineEnum.SINGLE, color=CommonColor.BLUE),
            shadowed=True,
        )
        Chart2.style_data_series(chart_doc=chart_doc, styles=[data_lbl_font])

        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. 829.

Style Data Series

# ... other code
data_lbl_font = LblFontEffects(
    color=CommonColor.RED,
    underline=FontLine(line=FontUnderlineEnum.SINGLE, color=CommonColor.BLUE),
    shadowed=True,
)
Chart2.style_data_series(chart_doc=chart_doc, styles=[data_lbl_font])

Running the above code will produce the following output in Fig. 785 and Fig. 786.

Chart with data series labels with font effects applied

Fig. 785 Chart with data series labels with font effects applied

Chart Data Labels Dialog Font Effects

Fig. 786 Chart Data Labels Dialog Font Effects

Style Data Point

# ... other code
Chart2.style_data_point(
    chart_doc=chart_doc, series_idx=0, idx=4, styles=[data_lbl_font]
)

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

Chart with data point label with font effects applied

Fig. 787 Chart with data point label with font effects applied