Chart2 Direct Axis Numbers

Overview

The style_numbers_numbers() method is used to format the number of an axis.

Setup

General setup for examples.

from __future__ import annotations
from pathlib import Path
import uno
from ooo.dyn.awt.gradient_style import GradientStyle
from ooo.dyn.i18n.number_format_index import NumberFormatIndexEnum
from ooodev.calc import CalcDoc, ZoomKind
from ooodev.utils.color import StandardColor
from ooodev.loader.lo import Lo
from ooodev.utils.data_type.color_range import ColorRange
from ooodev.utils.data_type.offset import Offset

def main() -> int:
    with Lo.Loader(connector=Lo.ConnectPipe()):
        fnm = Path.cwd() / "tmp" / "bon_voyage.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.GREEN_DARK2,
            width=0.9,
        )
        _ = chart_doc.style_area_gradient(
            step_count=0,
            offset=Offset(41, 50),
            style=GradientStyle.RADIAL,
            grad_color=ColorRange(
                StandardColor.TEAL,
                StandardColor.YELLOW_DARK1,
            ),
        )
        _ = chart_doc.axis_y.style_numbers_numbers(
            source_format=False,
            num_format_index=NumberFormatIndexEnum.CURRENCY_1000DEC2,
        )

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

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

Apply to Axis

Before formatting the chart is seen in Fig. 827.

Apply to Y-Axis

The NumberFormatIndexEnum enum contains the values in API NumberFormatIndex for easy lookup.

from ooo.dyn.i18n.number_format_index import NumberFormatIndexEnum
# .. other code

_ = chart_doc.axis_y.style_numbers_numbers(
    source_format=False,
    num_format_index=NumberFormatIndexEnum.CURRENCY_1000DEC2,
)

The results are seen in Fig. 493 and Fig. 494.

Chart with Y-Axis Formatted to Currency with two decimal places

Fig. 493 Chart with Y-Axis Formatted to Currency with two decimal places

Chart Area Borders Default Dialog

Fig. 494 Chart Area Borders Default Dialog

Apply to Secondary Y-Axis

# ... other code
y2_axis = chart_doc.axis2_y
if y2_axis is not None:
    _ = y2_axis.style_numbers_numbers(
        source_format=False,
        num_format_index=NumberFormatIndexEnum.CURRENCY_1000DEC2,
    )

The results are seen in Fig. 495.

Chart with Y-Axis Formatted to Currency with two decimal places

Fig. 495 Chart with Y-Axis Formatted to Currency with two decimal places