Chart2 Direct Legend Transparency (Static)

Overview

Classes in the ooodev.format.chart2.direct.legend.transparency module can be used to set the legend transparency.

Calls to the Chart2.style_legend() and method is used to style legend.

Setup

General setup for examples.

import uno
from ooodev.format.chart2.direct.legend.area import Color as LegendAreaColor
from ooodev.format.chart2.direct.legend.transparency import (
    Transparency as LegendTransparency,
    Gradient as LegendGradient,
    IntensityRange,
)
from ooodev.format.chart2.direct.general.borders import LineProperties as ChartLineProperties
from ooodev.format.chart2.direct.general.area import Gradient as ChartGradient
from ooodev.format.chart2.direct.general.area import GradientStyle, ColorRange
from ooodev.office.calc import Calc
from ooodev.office.chart2 import Chart2
from ooodev.utils.color import StandardColor
from ooodev.gui import GUI
from ooodev.utils.kind.zoom_kind import ZoomKind
from ooodev.loader.lo import Lo

def main() -> int:
    with Lo.Loader(connector=Lo.ConnectPipe()):
        doc = Calc.open_doc("pie_chart.ods")
        GUI.set_visible(True, doc)
        Lo.delay(500)
        Calc.zoom(doc, ZoomKind.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="pie_chart")

        chart_bdr_line = ChartLineProperties(color=StandardColor.BRICK, width=1)
        chart_grad = ChartGradient(
            chart_doc=chart_doc,
            step_count=64,
            style=GradientStyle.SQUARE,
            angle=45,
            grad_color=ColorRange(StandardColor.GREEN_DARK4, StandardColor.TEAL_LIGHT2),
        )
        Chart2.style_background(chart_doc=chart_doc, styles=[chart_grad, chart_bdr_line])

        legend_color_style = LegendAreaColor(color=StandardColor.GREEN_LIGHT2)
        legend_bg_transparency_style = LegendTransparency(50)
        Chart2.style_legend(
            chart_doc=chart_doc, styles=[legend_bg_transparency_style, legend_color_style]
        )

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

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

.. only:: html

    .. cssclass:: tab-none

        .. group-tab:: None

Transparency

Before formatting the chart is seen in Fig. 833.

Setting Transparency

The ooodev.format.chart2.direct.legend.transparency.Transparency class can be used to set the transparency of a chart legend.

The Transparency needs a background color in order to view the transparency. See: Chart2 Direct Legend Area.

ooodev.format.chart2.direct.legend.transparency import Transparency as LegendTransparency

# ... other code
legend_bg_transparency_style = LegendTransparency(50)
Chart2.style_legend(
    chart_doc=chart_doc, styles=[legend_bg_transparency_style, legend_color_style]
)

The results can bee seen in Fig. 705 and Fig. 706.

Chart with transparency applied to legend

Fig. 705 Chart with transparency applied to legend

Chart Legend Transparency Dialog

Fig. 706 Chart Legend Transparency Dialog

Gradient Transparency

Before formatting the chart is seen in Fig. 833.

Setting Gradient

The ooodev.format.chart2.direct.legend.transparency.Gradient class can be used to set the gradient transparency of a legend.

Like the Transparency the Gradient Transparency needs a background color in order to view the transparency. See: Chart2 Direct Legend Area.

from ooodev.format.chart2.direct.legend.area import Color as LegendAreaColor
from ooodev.format.chart2.direct.legend.transparency import (
    Gradient as LegendGradient,
    IntensityRange,
)
# ... other code

legend_color_style = LegendAreaColor(color=StandardColor.GREEN_LIGHT2)
legend_transparency_gradient = LegendGradient(
    chart_doc, angle=90, grad_intensity=IntensityRange(0, 100)
)
Chart2.style_legend(
    chart_doc=chart_doc, styles=[legend_transparency_gradient, legend_color_style]
)

The results can bee seen in Fig. 707 and Fig. 708.

Chart with legend gradient transparency

Fig. 707 Chart with legend gradient transparency

Chart Legend Gradient Transparency Dialog

Fig. 708 Chart Legend Gradient Transparency Dialog