Chart2 Direct Axis Numbers (Static)

Overview

The ooodev.format.chart2.direct.axis.numbers.Numbers class is used to format the number of an axis.

Methods for formatting the number of an axis are:

Setup

General setup for examples.

import uno
from ooodev.format.chart2.direct.axis.numbers import Numbers, NumberFormatIndexEnum
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, Offset
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(Path.cwd() / "tmp" / "bon_voyage.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="Object 1")

        chart_bdr_line = ChartLineProperties(color=StandardColor.GREEN_DARK2, width=0.9)
        chart_grad = ChartGradient(
            chart_doc=chart_doc,
            step_count=0,
            offset=Offset(41, 50),
            style=GradientStyle.RADIAL,
            grad_color=ColorRange(StandardColor.TEAL, StandardColor.YELLOW_DARK1),
        )
        Chart2.style_background(chart_doc=chart_doc, styles=[chart_grad, chart_bdr_line])

        num_style = Numbers(
            chart_doc, source_format=False, num_format_index=NumberFormatIndexEnum.CURRENCY_1000DEC2
        )
        Chart2.style_y_axis(chart_doc=chart_doc, styles=[num_style])

        Lo.delay(1_000)
        Lo.close_doc(doc)
    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 ooodev.format.chart2.direct.axis.numbers import Numbers, NumberFormatIndexEnum
# .. other code

num_style = Numbers(
    chart_doc, source_format=False, num_format_index=NumberFormatIndexEnum.CURRENCY_1000DEC2
)
Chart2.style_y_axis(chart_doc=chart_doc, styles=[num_style])

The results are seen in Fig. 672 and Fig. 673.

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

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

Chart Area Borders Default Dialog

Fig. 673 Chart Area Borders Default Dialog

Apply to Secondary Y-Axis

# ... other code
Chart2.style_y_axis2(chart_doc=chart_doc, styles=[num_style])

The results are seen in Fig. 674.

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

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