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)
The results are seen in Fig. 548 and Fig. 549.
Fig. 548 Chart with data series color set to green
Fig. 549 Chart Area Color Dialog
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.
Fig. 550 Chart with data point color set to green
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)
The results are seen in Fig. 551 and Fig. 552.
Fig. 551 Chart with gradient data series modified
Fig. 552 Chart Data Series Area Gradient Dialog
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.
Fig. 553 Chart with gradient data point modified
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
Fig. 554 Chart with custom gradient data series formatting
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)
The results are seen in Fig. 555 and Fig. 556.
Fig. 555 Chart with data series background image
Fig. 556 Chart Data Series Area Image Dialog
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.
Fig. 557 Chart with data point background image
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
)
The results are seen in Fig. 558 and Fig. 559.
Fig. 558 Chart data series with background pattern
Fig. 559 Chart Data Series Area Pattern Dialog
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.
Fig. 560 Chart data point with background pattern
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,
)
The results are seen in Fig. 561 and Fig. 562.
Fig. 561 Chart with data series background hatch
Fig. 562 Chart Data Series Area Hatch Dialog
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.
Fig. 563 Chart with data point background hatch