Chart2 Direct series Data Series Area
Overview
The Data Series and Data Point of a Chart can be styled using the various style_*
methods of
the ChartDataSeries
and ChartDataPoint
classes.
Setup
General setup for examples.
from __future__ import annotations
from pathlib import Path
import uno
from ooodev.calc import CalcDoc, ZoomKind
from ooodev.loader.lo import Lo
from ooodev.format.inner.preset.preset_gradient import PresetGradientKind
from ooodev.utils.color import StandardColor
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_border_line(
color=StandardColor.BLUE_LIGHT3,
width=0.7,
)
_ = chart_doc.style_area_gradient_from_preset(
preset=PresetGradientKind.TEAL_BLUE,
)
ds = chart_doc.get_data_series()[0]
ds.style_area_color(StandardColor.TEAL_DARK2)
Lo.delay(1_000)
doc.close()
return 0
if __name__ == "__main__":
SystemExit(main())
Color
The style_area_color()
method is called to set the background color of a data series in Chart.
Before formatting the chart is seen in Fig. 829.
Apply the background color to a data series
Style Data Series
# ... other code
ds = chart_doc.get_data_series()[0]
ds.style_area_color(StandardColor.TEAL_DARK2)
Style Data Point
# ... other code
ds = chart_doc.get_data_series()[0]
dp = ds[2]
dp.style_area_color(StandardColor.TEAL_DARK2)
The results are seen in Fig. 550.
Gradient
The style_area_gradient_from_preset()
method is called to set the background gradient of a Chart.
Before formatting the chart is seen in Fig. 829.
Gradient from preset
Apply the preset gradient to a data series
The PresetGradientKind
enum is used to select the preset gradient.
Style Data Series
from ooodev.format.inner.preset.preset_gradient import PresetGradientKind
# ... other code
ds = chart_doc.get_data_series()[0]
ds.style_area_gradient_from_preset(preset=PresetGradientKind.DEEP_OCEAN)
Style Data Point
from ooodev.format.inner.preset.preset_gradient import PresetGradientKind
# ... other code
ds = chart_doc.get_data_series()[0]
dp = ds[-1]
dp.style_area_gradient_from_preset(preset=PresetGradientKind.DEEP_OCEAN)
The results are seen in Fig. 553.
Apply a custom Gradient
Demonstrates how to create a custom gradient.
Apply the preset gradient to a data series
from ooo.dyn.awt.gradient_style import GradientStyle
from ooodev.utils.data_type.color_range import ColorRange
# ... other code
ds = chart_doc.get_data_series()[0]
ds.style_area_gradient(
style=GradientStyle.LINEAR,
angle=215,
grad_color=ColorRange(StandardColor.TEAL_DARK3, StandardColor.BLUE_LIGHT2),
)
The results are seen in Fig. 554
Image
The style_area_image_from_preset()
method is called to set the data series background image of a Chart.
Before formatting the chart is seen in Fig. 829.
Apply background image of a Chart
The PresetImageKind
enum is used to select an image preset.
Style Data Series
from ooodev.format.inner.preset.preset_image import PresetImageKind
# ... other code
dds = chart_doc.get_data_series()[0]
ds.style_area_image_from_preset(preset=PresetImageKind.POOL)
Style Data Point
from ooodev.format.inner.preset.preset_image import PresetImageKind
# ... other code
ds = chart_doc.get_data_series()[0]
dp = ds[0]
dp.style_area_image_from_preset(preset=PresetImageKind.POOL)
The results are seen in Fig. 557.
Pattern
The style_area_pattern_from_preset()
method is called to set the background pattern of a Chart.
Before formatting the chart is seen in Fig. 829.
Apply background pattern of a Chart
The PresetPatternKind
enum is used to select a pattern preset.
Style Data Series
from ooodev.format.chart2.direct.series.data_series.area import Pattern as SeriesPattern
from ooodev.format.inner.preset.preset_pattern import PresetPatternKind
# ... other code
ds = chart_doc.get_data_series()[0]
ds.style_area_pattern_from_preset(
preset=PresetPatternKind.ZIG_ZAG
)
Style Data Point
from ooodev.format.inner.preset.preset_pattern import PresetPatternKind
# ... other code
ds = chart_doc.get_data_series()[0]
dp = ds[4]
dp.style_area_pattern_from_preset(preset=PresetPatternKind.ZIG_ZAG)
The results are seen in Fig. 560.
Hatch
The style_area_hatch_from_preset()
method is called to set the background hatch of a Chart.
Before formatting the chart is seen in Fig. 829.
Apply background hatch of a Chart
The PresetHatchKind
enum is used to select a hatch preset.
Style Data Series
from ooodev.format.inner.preset.preset_hatch import PresetHatchKind
# ... other code
ds = chart_doc.get_data_series()[0]
ds.style_area_hatch_from_preset(
preset=PresetHatchKind.BLUE_45_DEGREES_CROSSED,
)
Style Data Point
from ooodev.format.inner.preset.preset_hatch import PresetHatchKind
# ... other code
ds = chart_doc.get_data_series()[0]
dp = ds[-1]
dp.style_area_hatch_from_preset(
preset=PresetHatchKind.BLUE_45_DEGREES_CROSSED,
)
The results are seen in Fig. 563.