2017-06-01 159 views
0

如何更改組合圖表上的y軸比例? 我有一個堆疊酒吧與第二個折線圖。我希望堆積的y軸位於左側,第二個折線圖的右側是刻度。所以這將是兩個y軸的交換。如何在python openpyxl中從左向右交換組合圖表的y軸?

這裏是我的圖表:

chart1 = BarChart() 
chart1.type = "col" 
chart1.style = 12 
chart1.grouping = "stacked" 
chart1.overlap = 100 

chart1.layout = Layout(
    ManualLayout(
    x=0.12, y=0.25, 
    h=0.9, w=0.75, 
    xMode="edge", 
    yMode="edge", 
    ) 
) 

...

chart2 = LineChart() 
chart2.style = 12 
chart2.y_axis.axId = 0 

...

chart1.y_axis.crosses = "max" 
chart1 += chart2 
    WorkSheetOne.add_chart(chart1, 'A1') 
+0

最好的辦法是改變圖表的順序。這個邏輯在庫中是硬編碼的,並且由於XML而難以改變。 –

+0

我試圖更改順序: chart1.y_axis.crosses = 「MAX」 chart2 + = chart1 WorkSheetOne.add_chart(chart2, 'A1') 但這並沒有工作,直到我也改變: chart2 .y_axis.crosses =「max」 而且我還必須更改: chart2.title,因爲現在忽略了chart1標題。 完美!謝謝!! –

+0

很高興你有一些工作。你會考慮提交文檔的更新嗎? –

回答

1

在評論中解決:

Best bet is to change the order of the charts. 
The logic for this is hard-coded in the library and difficult to change due to the XML. – Charlie Clark 

我試圖更改順序:

chart1.y_axis.crosses = "max" 
chart2 += chart1 
WorkSheetOne.add_chart(chart2, 'A1') 

但這並沒有工作,直到我也改變:

chart2.y_axis.crosses = "max" 

而且我也不得不改變:chart2.title因爲chart1.title現在忽略。完善!謝謝!! - 馬修考克斯