Category Axis, Value Axis Tick Label Position not assigned properly
See original GitHub issueI think I found an issue with setting axis tick label position. The resulting XML shows the tickLblPos as “nextTo” instead of “low”. (This is a stacked column chart with positive and negative values, so the category axis labels need to be beneath the plot area, not alongside/next to the axis line.)
<c:catAx>
<c:axId val="-2068027336"/>
<c:scaling>
<c:orientation val="minMax"/>
</c:scaling>
<c:delete val="0"/>
<c:axPos val="b"/>
<c:majorTickMark val="out"/>
<c:minorTickMark val="none"/>
<c:tickLblPos val="nextTo"/>
I’m formatting the chart with this method:
def format_chart(t, chart):
"""
applies some default formatting to the chart
t is a DimTable object which is not currently used
, but we may leverage that in thefuture to do conditional formatting.
"""
plot = chart.plots[0]
# by default, a chart with single series will vary color per category.
#plot.vary_by_categories = False
plot.has_data_labels = True
set_label_position(t, chart)
if t.custom_properties['showNegativeLabelsAsPositive']:
override_negative_value_labels(t, chart)
set_label_font_format(plot.data_labels, False, 14, MSO_THEME_COLOR_INDEX.TEXT_1)
set_series_overlap(t, chart)
category_axis = chart.category_axis
set_axis_line_format(category_axis, False, MSO_THEME_COLOR_INDEX.BACKGROUND_2)
set_label_font_format(category_axis.tick_labels, False, 14, MSO_THEME_COLOR_INDEX.TEXT_1)
if t.custom_properties['categoryAxisLabelPosition']:
category_axis.tick_labels.position = t.custom_properties['categoryAxisLabelPosition']
value_axis = chart.value_axis
set_axis_line_format(value_axis, True, MSO_THEME_COLOR_INDEX.BACKGROUND_2)
set_label_font_format(value_axis.tick_labels, False, 14, MSO_THEME_COLOR_INDEX.BACKGROUND_2)
value_axis.visible = not t.custom_properties['hideValueAxis']
the t.custom_properties
is a defaultdict(bool)
and assigned in another class, using the enumeration:
self.Tables[4].custom_properties['categoryAxisLabelPosition'] = XL_TICK_LABEL_POSITION.LOW
If I manually edit that node in the XML to “low” instead of “nextTo”, then the axis tick labels appear correctly.
I believe this also affects the value_axis
, though I did not test it as thoroughly in that regard.
I am able to do this with a workaround function:
def set_axis_tick_label_position(xpath, position, chart):
"""
Workaround function to assign tick label position to category or value axis.
xpath: an x-path specification for the axis' tick labels
position: an XL_TICK_LABEL_POSITION
chart: a chart object
This function accesses the element specified by xpath and assigns the appropriate attribute value based
on the XL_TICK_LABEL_POSITION
We should be able to assign directly, but for at least some charts, the output XML has "nextTo" (default) instead of the specified position
chart.category_axis.tick_labels.position = t.custom_properties['categoryAxisLabelPosition']
"""
ele = chart._chartSpace.xpath(xpath)[0]
val = "nextTo" # default
if position == XL_TICK_LABEL_POSITION.LOW:
val = "low"
if position == XL_TICK_LABEL_POSITION.HIGH:
val = "high"
if position == XL_TICK_LABEL_POSITION.NONE:
val = "none"
ele.set("val", val)
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Change the display of chart axes - Microsoft Support
You can change the alignment of axis labels on both horizontal (category) and vertical (value) axes. When you have multiple-level category labels in...
Read more >Move x-axis tick labels one position to left [duplicate]
The problem is that the labels are centered horizontally, so when you rotate them 45°, they appear to be aligned with the wrong...
Read more >Options for specifying axis labels - Title Syntax
axis label options control the placement and the look of ticks and labels on an axis. axis label options. Description. { y |...
Read more >X-Axis labels in excel graph are showing sequence of ...
Edit the chart data and check the entries for "Horizontal (Category) Axis Labels". If you see numbers there instead of the desired text, ......
Read more >Axis Options for LAYOUT OVERLAY - SAS Help Center
The label is positioned to the left of the tick values for the Y axis or to the right of the axis values...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The line:
should be:
Yes, that’s one of the disadvantages of a dynamic language I suppose, that happens from time to time 😃