Chart2 Direct Axis Positioning
Overview
The style_axis_pos_*
methods gives similar options for axis positioning
as Fig. 496 Axis Positioning Dialog, but without the dialog.
Setup
General setup for this example.
import uno
from ooodev.format.chart2.direct.axis.positioning import AxisLine, ChartAxisPosition
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.utils.kind.zoom_kind import ZoomKind
from ooodev.loader.lo import Lo
def main() -> int:
with Lo.Loader(connector=Lo.ConnectPipe()):
doc = Calc.open_doc("bon_voyage.ods")
GUI.set_visible(True, doc)
Lo.delay(500)
Calc.zoom(doc, ZoomKind.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])
axis_line_style = AxisLine(cross=ChartAxisPosition.VALUE, value=2000)
Chart2.style_x_axis(chart_doc=chart_doc, styles=[axis_line_style])
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
SystemExit(main())
Positioning
Apply Axis Line
Before formatting the chart is seen in Fig. 827.
In this example the axis line is positioned at the value 2000
and applied to the x-axis.
The axis position is set using the style_axis_pos_axis_line()
method.
from ooo.dyn.chart.chart_axis_position import ChartAxisPosition
# ... other code
chart_doc.axis_x.style_axis_pos_axis_line(
cross=ChartAxisPosition.VALUE, value=2000
)
The result of running the above can be seen in Fig. 497 and Fig. 498.
Apply Axis Position
Before formatting the chart is seen in Fig. 827.
For x-axis Position Dialog the Axis position can be set using the style_axis_pos_position_axis()
method.
# ... other code
chart_doc.axis_x.style_axis_pos_position_axis(on_mark=False)
The result of running the above can be seen in Fig. 499.
Apply Positioning Labels
Before formatting the chart is seen in Fig. 827.
The Label position can be set using the style_axis_pos_label_position()
method.
from ooo.dyn.chart.chart_axis_label_position import ChartAxisLabelPosition
# ... other code
chart_doc.axis_y.style_axis_pos_label_position(
ChartAxisLabelPosition.NEAR_AXIS_OTHER_SIDE
)
The result of running the above can be seen in Fig. 500 and Fig. 501.
Apply Interval Marks
Interval marks can be set using the style_axis_pos_interval_marks()
method.
from ooo.dyn.chart.chart_axis_mark_position import ChartAxisMarkPosition
from ooodev.format.inner.direct.chart2.axis.positioning.interval_marks import MarkKind
# ... other code
chart_doc.axis_y.style_axis_pos_interval_marks(
major=MarkKind.OUTSIDE,
minor=MarkKind.NONE,
pos=ChartAxisMarkPosition.AT_LABELS_AND_AXIS,
)
The result of running the above can be seen in Fig. 502.