Chart2 Direct Series Data Series Options (Static)
Overview
Depending on the chart type the Data Series Options dialog will have different options. For example a Pie chart will have a options dialog similar to Fig. 747 whereas a column chart will have a dialog similar to Fig. 748.
The ooodev.format.chart2.direct.series.data_series.options
module contains classes for the various options.
Calls to the Chart2.style_data_series()
method are used to set the data series options of a Chart.
Figures
Setup
General setup for examples.
import uno
from ooodev.format.chart2.direct.series.data_series.options import Orientation
from ooodev.utils.data_type.angle import Angle
from ooodev.format.chart2.direct.general.borders import LineProperties as ChartLineProperties
from ooodev.format.chart2.direct.general.area import Gradient as ChartGradient, PresetGradientKind
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_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.BLUE_LIGHT3, width=0.7)
chart_grad = ChartGradient.from_preset(chart_doc, PresetGradientKind.TEAL_BLUE)
Chart2.style_background(chart_doc=chart_doc, styles=[chart_grad, chart_bdr_line])
orient = Orientation(chart_doc=chart_doc, clockwise=True, angle=Angle(45))
Chart2.style_data_series(chart_doc=chart_doc, styles=[orient])
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
SystemExit(main())
Options for Orientation
Charts such as Pie and Donut have a Orientation option as shown in Fig. 747.
With the Orientation
class we can set the angle and direction of the chart.
Before formatting the chart is seen in Fig. 833.
from ooodev.format.chart2.direct.series.data_series.options import Orientation
# ... other code
orient = Orientation(chart_doc=chart_doc, clockwise=True, angle=Angle(45))
Chart2.style_data_series(chart_doc=chart_doc, styles=[orient])
Align Data Series
The AlignSeries
class can be used to align the data series.
In this example we set the plot options of a column chart as seen in Fig. 829.
The primary_y_axis
parameter is used to set the alignment of the data series.
If True
this the primary y-axis is used, if False
the secondary y-axis is used.
from ooodev.format.chart2.direct.series.data_series.options import AlignSeries
# ... other code
align_options = AlignSeries(chart_doc, primary_y_axis=False)
Chart2.style_data_series(chart_doc=chart_doc, styles=[align_options])
Settings Options
The Settings
class can be used to set the settings of the data series.
In this example we set the plot options of a column chart as seen in Fig. 829.
from ooodev.format.chart2.direct.series.data_series.options import Settings
# ... other code
setting_options = Settings(
chart_doc=chart_doc, spacing=150, overlap=22, side_by_side=True
)
Chart2.style_data_series(chart_doc=chart_doc, styles=[setting_options])
Options for Plot
Some charts such as Pie and Donut have simple Plot options as shown in Fig. 747.
Other charts have more complex Plot options as shown in Fig. 748.
Before formatting the chart is seen in Fig. 833.
Simple Plot Options
The PlotSimple
class can be used to set the hidden cell values.
from ooodev.format.chart2.direct.series.data_series.options import PlotSimple
# ... other code
plot_options = PlotSimple(chart_doc=chart_doc, hidden_cell_values=False)
Chart2.style_data_series(chart_doc=chart_doc, styles=[plot_options])
The results are seen in Fig. 755.
Complex Plot Options
The Plot
class can be used to set the complex options.
In this example we set the plot options of a column chart as seen in Fig. 829.
from ooodev.format.chart2.direct.series.data_series.options import Plot, MissingValueKind
# ... other code
plot_options = Plot(
chart_doc=chart_doc, missing_values=MissingValueKind.USE_ZERO, hidden_cell_values=False
)
Chart2.style_data_series(chart_doc=chart_doc, styles=[plot_options])
The results are seen in Fig. 756.
Legend Options
The LegendEntry
class can be used to set the legend visibility of the data series.
In this example we set the plot options of a column chart as seen in Fig. 829.
from ooodev.format.chart2.direct.series.data_series.options import LegendEntry
# ... other code
legend_options = LegendEntry(chart_doc, hide_legend=True)
Chart2.style_data_series(chart_doc=chart_doc, styles=[legend_options])