Chart2 Direct Axis Positioning (Static)
Overview
The ooodev.format.chart2.direct.axis.positioning
namespace gives you the similar options for axis positioning
as Fig. 675 Axis Positioning Dialog, but without the dialog.
See also
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 ooodev.format.chart2.direct.axis.positioning.AxisLine
class.
from ooodev.format.chart2.direct.axis.positioning import AxisLine, ChartAxisPosition
# ... other code
axis_line_style = AxisLine(cross=ChartAxisPosition.VALUE, value=2000)
Chart2.style_x_axis(chart_doc=chart_doc, styles=[axis_line_style])
The result of running the above can be seen in Fig. 676 and Fig. 677.
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 ooodev.format.chart2.direct.axis.positioning.PositionAxis
class.
from ooodev.format.chart2.direct.axis.positioning import PositionAxis
# ... other code
position_axis_style = PositionAxis(False)
Chart2.style_x_axis(chart_doc=chart_doc, styles=[position_axis_style])
The result of running the above can be seen in Fig. 678.
Apply Positioning Labels
Before formatting the chart is seen in Fig. 827.
The Label position can be set using the ooodev.format.chart2.direct.axis.positioning.LabelPosition
class.
from ooodev.format.chart2.direct.axis.positioning import LabelPosition, ChartAxisLabelPosition
# ... other code
label_position_style = LabelPosition(ChartAxisLabelPosition.NEAR_AXIS_OTHER_SIDE)
Chart2.style_y_axis(chart_doc=chart_doc, styles=[label_position_style])
The result of running the above can be seen in Fig. 679 and Fig. 680.
Apply Interval Marks
Interval marks can be set using the ooodev.format.chart2.direct.axis.positioning.IntervalMarks
class.
from ooodev.format.chart2.direct.axis.positioning import IntervalMarks
from ooodev.format.chart2.direct.axis.positioning import MarkKind, ChartAxisMarkPosition
from ooodev.format.chart2.direct.axis.positioning import LabelPosition, ChartAxisLabelPosition
# ... other code
label_position_style = LabelPosition(ChartAxisLabelPosition.NEAR_AXIS_OTHER_SIDE)
interval_marks_style = IntervalMarks(
major=MarkKind.OUTSIDE, minor=MarkKind.NONE, pos=ChartAxisMarkPosition.AT_LABELS_AND_AXIS
)
Chart2.style_y_axis(chart_doc=chart_doc, styles=[label_position_style, interval_marks_style])
The result of running the above can be seen in Fig. 681.