Chart2 Direct Title/Subtitle Area (Static)
Overview
The ooodev.format.chart2.direct.title.area
module is used to format the Title/Subtitle parts of a Chart.
Calls to the Chart2.style_title()
and
Chart2.style_subtitle()
methods are used to set the Title and Subtitle formatting of a Chart.
See also
Setup
General setup for examples.
import uno
from ooodev.format.chart2.direct.title.area import Color as TitleBgColor
from ooodev.format.chart2.direct.general.borders import LineProperties as ChartLineProperties
from ooodev.format.chart2.direct.general.area import Gradient as ChartGradient
from ooodev.format.chart2.direct.general.area import GradientStyle, ColorRange
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("pie_flat_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="pie_chart")
chart_bdr_line = ChartLineProperties(color=StandardColor.PURPLE_DARK1, width=0.7)
chart_grad = ChartGradient(
chart_doc=chart_doc,
step_count=64,
style=GradientStyle.SQUARE,
angle=45,
grad_color=ColorRange(StandardColor.BLUE_DARK1, StandardColor.PURPLE_LIGHT2),
)
Chart2.style_background(chart_doc=chart_doc, styles=[chart_grad, chart_bdr_line])
title_color = TitleBgColor(color=StandardColor.DEFAULT_BLUE)
Chart2.style_title(chart_doc=chart_doc, styles=[title_color])
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
SystemExit(main())
Color
The ooodev.format.chart2.direct.title.area.Color
class is used to set the background color of a Chart Title or Subtitle.
Before formatting the chart is seen in Fig. 832.
Apply to a Title
from ooodev.format.chart2.direct.title.area import Color as TitleBgColor
# ... other code
title_color = TitleBgColor(color=StandardColor.DEFAULT_BLUE)
Chart2.style_title(chart_doc=chart_doc, styles=[title_color])
The results are seen in Fig. 794 and Fig. 795.
Fig. 794 Chart with Title Area Color set
Fig. 795 Chart Title Color Dialog
Apply to a Subtitle
# ... other code
Chart2.style_subtitle(chart_doc=chart_doc, styles=[title_color])
The results are seen in Fig. 796.
Fig. 796 Chart with Subtitle Area Color set
Gradient
The ooodev.format.chart2.direct.title.area.Gradient
class is used to set the Title/Subtitle gradient of a Chart.
Before formatting the chart is seen in Fig. 832.
Gradient from preset
Apply the preset gradient
The PresetGradientKind
enum is used to select the preset gradient.
Apply to Title
from ooodev.format.chart2.direct.title.area import Gradient as TitleGrad, PresetGradientKind
# ... other code
title_grad = TitleGrad.from_preset(chart_doc, PresetGradientKind.PASTEL_DREAM)
Chart2.style_title(chart_doc=chart_doc, styles=[title_grad])
The results are seen in Fig. 797 and Fig. 798.
Fig. 797 Chart with gradient Title
Fig. 798 Chart Title Gradient Dialog
Apply to Subtitle
# ... other code
Chart2.style_subtitle(chart_doc=chart_doc, styles=[title_grad])
The results are seen in Fig. 799.
Fig. 799 Chart with gradient Title
Apply a custom Gradient
Demonstrates how to create a custom gradient.
Apply to Title
from ooodev.format.chart2.direct.title.area import Gradient as TitleGradient
from ooodev.format.chart2.direct.title.area import ColorRange
# ... other code
title_grad = TitleGradient(
chart_doc=chart_doc,
step_count=64,
style=GradientStyle.SQUARE,
angle=45,
grad_color=ColorRange(StandardColor.PURPLE_LIGHT2, StandardColor.BLUE_DARK1),
)
Chart2.style_title(chart_doc=chart_doc, styles=[title_grad])
The results are seen in Fig. 800 and Fig. 801.
Fig. 800 Chart with gradient Title
Fig. 801 Chart Title Gradient Dialog
Apply to Subtitle
# ... other code
Chart2.style_subtitle(chart_doc=chart_doc, styles=[title_grad])
The results are seen in Fig. 802.
Fig. 802 Chart with gradient Title
Image
The ooodev.format.chart2.direct.title.area.Img
class is used to set the background image of the Title and Subtitle.
Before formatting the chart is seen in Fig. 832.
Apply image
The PresetImageKind
enum is used to select an image preset.
Apply to Title
from ooodev.format.chart2.direct.title.area import Img as TitleImg, PresetImageKind
# ... other code
title_img = TitleImg.from_preset(chart_doc, PresetImageKind.SPACE)
Chart2.style_title(chart_doc=chart_doc, styles=[title_img])
The results are seen in Fig. 803 and Fig. 804.
Fig. 803 Chart with Title Image
Fig. 804 Chart Title Image Dialog
Apply to Subtitle
# ... other code
Chart2.style_subtitle(chart_doc=chart_doc, styles=[title_img])
The results are seen in Fig. 805.
Fig. 805 Chart with Title Image
Pattern
The ooodev.format.chart2.direct.title.area.Pattern
class is used to set the background pattern of a Chart.
Before formatting the chart is seen in Fig. 832.
The PresetPatternKind
enum is used to select a pattern preset.
Apply to Title
from ooodev.format.chart2.direct.title.area import Pattern as TitlePattern, PresetPatternKind
# ... other code
title_pattern = TitlePattern.from_preset(chart_doc, PresetPatternKind.HORIZONTAL_BRICK)
Chart2.style_title(chart_doc=chart_doc, styles=[title_pattern])
The results are seen in Fig. 806 and Fig. 807.
Fig. 806 Chart with Title pattern
Fig. 807 Chart Title Pattern Dialog
Apply to Subtitle
from ooodev.format.chart2.direct.title.area import Pattern as TitlePattern, PresetPatternKind
# ... other code
title_pattern = TitlePattern.from_preset(chart_doc, PresetPatternKind.HORIZONTAL_BRICK)
Chart2.style_title(chart_doc=chart_doc, styles=[title_pattern])
The results are seen in Fig. 808.
Fig. 808 Chart with Subtitle pattern
Hatch
The ooodev.format.chart2.direct.title.area.Hatch
class is used to set the Title and Subtitle hatch of a Chart.
Before formatting the chart is seen in Fig. 832.
The PresetHatchKind
enum is used to select a hatch preset.
Apply to Title
from ooodev.format.chart2.direct.title.area import Hatch as TitleHatch, PresetHatchKind
# ... other code
title_hatch = TitleHatch.from_preset(chart_doc, PresetHatchKind.YELLOW_45_DEGREES_CROSSED)
Chart2.style_title(chart_doc=chart_doc, styles=[title_hatch])
The results are seen in Fig. 809 and Fig. 810.
Fig. 809 Chart with Title hatch
Fig. 810 Chart Title Hatch Dialog
Apply to Subtitle
Chart2.style_subtitle(chart_doc=chart_doc, styles=[title_hatch])
The results are seen in Fig. 811.
Fig. 811 Chart with Title hatch