如何关闭(或隐藏)openpyxl中组合图表上的秒y轴刻度?

时间:2017-06-06 16:14:44

标签: python openpyxl

如何在openpyxl中关闭(或隐藏)组合图表上的秒y轴刻度?

我可以通过比较之前和之后的更改来隐藏比例来找到xml差异(我只需将excel文件扩展名更改为' .zip'以访问xml):

    -<c:valAx>
<c:axId val="156672520"/>
-<c:scaling>
<c:orientation val="minMax"/>
</c:scaling>
<c:delete val="0"/>
<c:axPos val="r"/>
<c:majorGridlines/>
<c:numFmt sourceLinked="1" formatCode="0.0"/>
<c:majorTickMark val="out"/>
<c:minorTickMark val="none"/>
<c:tickLblPos val="none"/>     # this changes from 'nextTo'
<c:crossAx val="207247000"/>
<c:crosses val="max"/>
<c:crossBetween val="between"/>
</c:valAx>

我已经尝试过了(最后几行是&#39; tickLblPos&#39;):

    mainchart = LineChart()
mainchart.style = 12
v2 = Reference(WorkSheetOne, min_col=1, min_row=2+CombBarLineDataOffsetFromTop, max_row=3+CombBarLineDataOffsetFromTop, max_col=13)
mainchart.add_data(v2, titles_from_data=True, from_rows=True)

mainchart.layout = Layout(
    ManualLayout(
    x=0.12, y=0.25, # position from the top
    h=0.9, w=0.75, # this is scaling the chart into the container
    xMode="edge",
    yMode="edge",
    )
)

mainchart.title = "Chart Title"

# Style the lines
s1 = mainchart.series[0]
#Marker type
s1.marker.symbol = "diamond" # triangle
s1.marker.size = 9
s1.marker.graphicalProperties.solidFill = "C00000" # Marker filling
s1.marker.graphicalProperties.line.solidFill = "000000" # Marker outline
s1.graphicalProperties.line.noFill = False
# Line color
s1.graphicalProperties.line.solidFill = "000000" # line color

s2 = mainchart.series[1]
s2.graphicalProperties.line.solidFill = "000000" 
s2.graphicalProperties.line.dashStyle = "dash"

mainchart.dataLabels = DataLabelList()

mainchart.dataLabels.showVal = False
mainchart.dataLabels.dLblPos = 't' 
mainchart.height = 15 
mainchart.width = 39 

#Create the Chart
chart2 = BarChart()
chart2.type = "col"
chart2.style = 10  # simple bar
chart2.y_axis.axId = 0

dataone = Reference(WorkSheetOne, min_col=2, min_row=CombBarLineDataOffsetFromTop+1, max_row=CombBarLineDataOffsetFromTop+1, max_col=13 )
doneseries = Series(dataone, title="Series Title")
chart2.append(doneseries)


cats = Reference(WorkSheetOne, min_col=2, min_row=CombBarLineDataOffsetFromTop, max_row=CombBarLineDataOffsetFromTop, max_col=13)
chart2.set_categories(cats)

# Set the series for the chart data
series3Total = chart2.series[0]
fill3Total =  PatternFillProperties(prst="pct5")
fill3Total.foreground = ColorChoice(srgbClr='996633') # brown
fill3Total.background = ColorChoice(srgbClr='996633')
series3Total.graphicalProperties.pattFill = fill3Total

chart2.dataLabels = DataLabelList()
chart2.dataLabels.showVal = False 
chart2.shape = 2 

mainchart.y_axis.crosses = "max"
mainchart.y_axis.tickLblPos = "none" # nextTo -- this doesn't work

mainchart += chart2

WorkSheetOne.add_chart(mainchart, 'A1')

如何使用openpyxl将XML中的差异转换为属性?

1 个答案:

答案 0 :(得分:1)

这里的问题是某些属性的某些默认值有时使用3值逻辑,因此None!= "none",即。 <c:tickLblPos /> != <c:tickLblPos val="none"/>因为默认值为&#34; nextTo&#34;。这会破坏Python的语义(3值逻辑总是错误的),默认情况下,如果Python中的值为None,则不设置属性。这实际上只影响ChartML,并且我已经为相关对象的描述符添加了一些逻辑,因此&#34; none&#34;将在必要时写出。

但此代码尚未公开发布。如果您想要预览,请通过电子邮件与我联系。