Chart2 Direct Series Data Series Options

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. 567 whereas a column chart will have a dialog similar to Fig. 568.

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

Data Series Options Dialog Simple

Fig. 567 Data Series Options Dialog Simple

Data Series Options Dialog Complex

Fig. 568 Data Series Options Dialog Complex

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.office.chart2 import Chart2
from ooodev.utils.color import StandardColor
from ooodev.format.inner.preset.preset_gradient import PresetGradientKind
from ooodev.format.chart2.direct.series.data_series.options import Orientation

def main() -> int:
    with Lo.Loader(connector=Lo.ConnectPipe()):
        fnm = Path.cwd() / "tmp" / "piechart_3d.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,
        )

        orient = Orientation(chart_doc=chart_doc.component, clockwise=True, angle=45)
        Chart2.style_data_series(chart_doc=chart_doc.component, styles=[orient])

        # f_style = ds.style_label_border_line_get()
        # assert f_style is not None

        Lo.delay(1_000)
        doc.close()
    return 0

if __name__ == "__main__":
    SystemExit(main())

Options for Orientation

Charts such as Pie and Donut have a Orientation option as shown in Fig. 567.

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.component, clockwise=True, angle=45)
Chart2.style_data_series(chart_doc=chart_doc.component, styles=[orient])

The results are seen in Fig. 569 and Fig. 570.

Chart with orientation set to clockwise and angle set to 45 degrees

Fig. 569 Chart with orientation set to clockwise and angle set to 45 degrees

Chart Data Series options Dialog

Fig. 570 Chart Data Series options Dialog

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.component, primary_y_axis=False)
Chart2.style_data_series(chart_doc=chart_doc.component, styles=[align_options])

The results are seen in Fig. 571 and Fig. 572.

Chart with data series alignment set to secondary y-axis

Fig. 571 Chart with data series alignment set to secondary y-axis

Chart Data Series options Dialog

Fig. 572 Chart Data Series options Dialog

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.component, spacing=150, overlap=22, side_by_side=True
)
Chart2.style_data_series(chart_doc=chart_doc.component, styles=[setting_options])

The results are seen in Fig. 573 and Fig. 574.

Chart with data series without legend

Fig. 573 Chart with data series without legend

Chart Data Series options Dialog

Fig. 574 Chart Data Series options Dialog

Options for Plot

Some charts such as Pie and Donut have simple Plot options as shown in Fig. 567.

Other charts have more complex Plot options as shown in Fig. 568.

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.component, hidden_cell_values=False)
Chart2.style_data_series(chart_doc=chart_doc.component, styles=[plot_options])

The results are seen in Fig. 575.

Chart Data Series options Dialog

Fig. 575 Chart Data Series options Dialog

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.component,
    missing_values=MissingValueKind.USE_ZERO,
    hidden_cell_values=False,
)
Chart2.style_data_series(chart_doc=chart_doc.component, styles=[plot_options])

The results are seen in Fig. 576.

Chart Data Series options Dialog

Fig. 576 Chart Data Series options Dialog

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.component, hide_legend=True)
Chart2.style_data_series(chart_doc=chart_doc.component, styles=[legend_options])

The results are seen in Fig. 577 and Fig. 578.

Chart with data series without legend

Fig. 577 Chart with data series without legend

Chart Data Series options Dialog

Fig. 578 Chart Data Series options Dialog