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)
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)
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
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)
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)
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)