Chart2 Direct General Area

Overview

Various style_* method of Class ChartDoc are used to set the background of a Chart.

Setup

General setup for examples.

from __future__ import annotations
import uno
from pathlib import Path
from ooodev.calc import CalcDoc, ZoomKind
from ooodev.utils.color import StandardColor
from ooodev.loader.lo import Lo


def main() -> int:
    with Lo.Loader(connector=Lo.ConnectPipe()):
        fnm = Path.cwd() / "tmp" / "col_chart.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_area_color(StandardColor.GREEN_LIGHT2)
        _ = chart_doc.style_border_line(color=StandardColor.GREEN_DARK3, width=0.7)

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


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

Color

The style_area_color() method is used to set the background color of a Chart.

Before setting the background color of the chart is seen in Fig. 829.

Apply the background color to a Chart

# ... other code

_ = chart_doc.style_area_color(StandardColor.GREEN_LIGHT2)
_ = chart_doc.style_border_line(color=StandardColor.GREEN_DARK3, width=0.7)

The results are seen in Fig. 466 and Fig. 467

Chart with color set to green

Fig. 466 Chart with color set to green

Chart Area Color Dialog

Fig. 467 Chart Area Color Dialog

Getting the color From a Chart

# ... other code

f_style = chart_doc.style_area_color_get()
assert f_style is not None

Gradient

The style_area_gradient_from_preset() method is used to set the background gradient of a Chart.

Before setting the background color of the chart is seen in Fig. 829.

Gradient from preset

Apply the preset gradient to a Chart

The PresetGradientKind enum is used to select the preset gradient.

from ooodev.format.inner.preset.preset_gradient import PresetGradientKind

# ... other code
_ = chart_doc.style_border_line(color=StandardColor.GREEN_DARK3, width=0.7)
_ = chart_doc.style_area_gradient_from_preset(preset=PresetGradientKind.NEON_LIGHT)

The results are seen in Fig. 468 and Fig. 469

Chart with gradient background

Fig. 468 Chart with gradient background

Chart Area Gradient Dialog

Fig. 469 Chart Area Gradient Dialog

Apply a custom Gradient

Demonstrates how to create a custom gradient.

Apply the preset gradient to a Chart

from ooo.dyn.awt.gradient_style import GradientStyle
from ooodev.utils.data_type.color_range import ColorRange

# ... other code
_ = chart_doc.style_border_line(color=StandardColor.GREEN_DARK3, width=0.7)
_ = chart_doc.style_area_gradient(
    style=GradientStyle.LINEAR,
    angle=45,
    grad_color=ColorRange(StandardColor.GREEN_DARK3, StandardColor.GREEN_LIGHT2),
)

The results are seen in Fig. 470

Chart with custom gradient background

Fig. 470 Chart with custom gradient background

Getting the gradient from a chart

# ... other code

f_style = chart_doc.style_area_gradient_get()
assert f_style is not None

Image

The style_area_image_from_preset() method is used to set the background image of a Chart.

Before setting the background image of the chart is seen in Fig. 829.

Apply background image of a Chart

The PresetImageKind enum is used to select an image preset.

from ooodev.format.inner.preset.preset_image import PresetImageKind
# ... other code

_ = chart_doc.style_border_line(color=StandardColor.BLUE_LIGHT2, width=0.7)
_ = chart_doc.style_area_image_from_preset(PresetImageKind.ICE_LIGHT)

The results are seen in Fig. 471 and Fig. 472

Chart with background image

Fig. 471 Chart with background image

Chart Area Image Dialog

Fig. 472 Chart Area Image Dialog

Getting the image from a Chart

# ... other code

f_style = chart_doc.style_area_image_get()
assert f_style is not None

Pattern

The style_area_pattern_from_preset() method is used to set the background pattern of a Chart.

Before setting the background pattern of the chart is seen in Fig. 829.

Apply background pattern of a Chart

The PresetPatternKind enum is used to select a pattern preset.

from ooodev.format.inner.preset.preset_pattern import PresetPatternKind
# ... other code

_ = chart_doc.style_border_line(color=StandardColor.BLUE_LIGHT2, width=0.7)
_ = chart_doc.style_area_pattern_from_preset(PresetPatternKind.ZIG_ZAG)

The results are seen in Fig. 473 and Fig. 474

Chart with background pattern

Fig. 473 Chart with background pattern

Chart Area Pattern Dialog

Fig. 474 Chart Area Pattern Dialog

Getting the pattern from a Chart

# ... other code

f_style = chart_doc.style_area_pattern_get()
assert f_style is not None

Hatch

The ooodev.format.chart2.direct.general.area.Hatch class is used to set the background hatch of a Chart.

Before setting the background hatch of the chart is seen in Fig. 829.

Apply background hatch of a Chart

The PresetHatchKind enum is used to select a hatch preset.

from ooodev.format.inner.preset.preset_hatch import PresetHatchKind
# ... other code

_ = chart_doc.style_border_line(color=StandardColor.GREEN_DARK3, width=0.7)
_ = chart_doc.style_area_hatch_from_preset(PresetHatchKind.GREEN_30_DEGREES)

The results are seen in Fig. 475 and Fig. 476

Chart with background hatch

Fig. 475 Chart with background hatch

Chart Area Hatch Dialog

Fig. 476 Chart Area Hatch Dialog