Chart2 Direct General Area (Static)
Overview
The ooodev.format.chart2.direct.general.area
module is used to set the background of a Chart.
Since version 0.28.0
it is recommended to use the built in methods for setting the background of a Chart.
See Chart2 Direct General Area.
See also
Setup
General setup for examples.
import uno
from ooodev.format.chart2.direct.general.area import Color as ChartColor
from ooodev.format.chart2.direct.general.borders import LineProperties as ChartLineProperties
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.loader.lo import Lo
def main() -> int:
with Lo.Loader(connector=Lo.ConnectPipe()):
doc = Calc.open_doc("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.GREEN_DARK3, width=0.7)
chart_color = ChartColor(color=StandardColor.GREEN_LIGHT2)
Chart2.style_background(chart_doc=chart_doc, styles=[chart_color, chart_bdr_line])
f_style = ChartColor.from_obj(chart_doc.getPageBackground())
assert f_style is not None
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
SystemExit(main())
Color
The ooodev.format.chart2.direct.general.area.Color
class 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
from ooodev.format.chart2.direct.general.area import Color as ChartColor
# ... other code
chart_bdr_line = ChartLineProperties(color=StandardColor.GREEN_DARK3, width=0.7)
chart_color = ChartColor(color=StandardColor.GREEN_LIGHT2)
Chart2.style_background(chart_doc=chart_doc, styles=[chart_color, chart_bdr_line])
Getting the color From a Chart
# ... other code
f_style = ChartColor.from_obj(chart_doc.getPageBackground())
assert f_style is not None
Gradient
The ooodev.format.chart2.direct.general.area.Gradient
class 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.chart2.direct.general.area import Gradient as ChartGradient, PresetGradientKind
# ... other code
chart_bdr_line = ChartLineProperties(color=StandardColor.GREEN_DARK3, width=0.7)
chart_grad = ChartGradient.from_preset(chart_doc, PresetGradientKind.NEON_LIGHT)
Chart2.style_background(chart_doc=chart_doc, styles=[chart_grad, chart_bdr_line])
Apply a custom Gradient
Demonstrates how to create a custom gradient.
Apply the preset gradient to a Chart
from ooodev.format.chart2.direct.general.area import Gradient as ChartGradient, GradientStyle
from ooodev.format.chart2.direct.general.area import ColorRange
# ... other code
chart_bdr_line = ChartLineProperties(color=StandardColor.GREEN_DARK3, width=0.7)
chart_grad = ChartGradient(
chart_doc=chart_doc,
style=GradientStyle.LINEAR,
angle=45,
grad_color=ColorRange(StandardColor.GREEN_DARK3, StandardColor.GREEN_LIGHT2),
)
Chart2.style_background(chart_doc=chart_doc, styles=[chart_grad, chart_bdr_line])
The results are seen in Fig. 649
Getting the gradient from a chart
# ... other code
f_style = ChartGradient.from_obj(chart_doc, chart_doc.getPageBackground())
assert f_style.prop_name == chart_grad.prop_name
Image
The ooodev.format.chart2.direct.general.area.Img
class 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.chart2.direct.general.area import Img as ChartImg, PresetImageKind
# ... other code
chart_bdr_line = ChartLineProperties(color=StandardColor.GREEN_DARK3, width=0.7)
chart_img = ChartImg.from_preset(chart_doc, PresetImageKind.ICE_LIGHT)
Chart2.style_background(chart_doc=chart_doc, styles=[chart_img, chart_bdr_line])
Getting the image from a Chart
# ... other code
f_style = ChartImg.from_obj(chart_doc, chart_doc.getPageBackground())
assert f_style is not None
Pattern
The ooodev.format.chart2.direct.general.area.Pattern
class 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.chart2.direct.general.area import Pattern as ChartPattern, PresetPatternKind
# ... other code
chart_bdr_line = ChartLineProperties(color=StandardColor.BLUE_LIGHT2, width=0.7)
chart_pattern = ChartPattern.from_preset(chart_doc, PresetPatternKind.ZIG_ZAG)
Chart2.style_background(chart_doc=chart_doc, styles=[chart_pattern, chart_bdr_line])
Getting the pattern from a Chart
# ... other code
f_style = ChartPattern.from_obj(chart_doc, chart_doc.getPageBackground())
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.chart2.direct.general.area import Hatch as ChartHatch, PresetHatchKind
# ... other code
chart_bdr_line = ChartLineProperties(color=StandardColor.GREEN_DARK3, width=0.7)
chart_hatch = ChartHatch.from_preset(chart_doc, PresetHatchKind.GREEN_30_DEGREES)
Chart2.style_background(chart_doc=chart_doc, styles=[chart_hatch, chart_bdr_line])