2016-03-08 130 views
2

我剛從XlsxWriter(0.8.4)開始。我正在嘗試創建圖表,但x和y軸不正確,我想將它們交換,x代表y。 我使用這些代碼塊以創建片和chartsheet在xlsxwriter中交換X和Y軸

def new_sheet(self,sheetnm,sheetdata): 
    self.ws = self.wb.add_worksheet(sheetnm) 
    logging.info(self.ws) 
    metadata = sheetdata[1] 
    head = (colh[0] for colh in metadata) 
    self.ws.write_row(0,0,head) 
    rows = sheetdata[0] 
    for ix,row in enumerate(rows): 
     self.ws.write_row(ix+1,0,row)    

def new_chart(self,sheetnm,ctitle,xtitle,ytitle,rows,cols): 
    self.cs = self.wb.add_chartsheet(sheetnm+"_chart") 
    chart = self.wb.add_chart({'type': 'bar'}) 
    chart.set_title({'name': ctitle}) 
    for row in range(1,rows): 
     chart.add_series({'categories':[sheetnm,0,1,0,cols-1],'values':[sheetnm,row,1,row,cols-1],'name':[sheetnm,row,0,row,0]}) 
    chart.set_x_axis({'name': xtitle}) 
    chart.set_y_axis({'name': ytitle}) 
    self.cs.set_chart(chart) 

據工作,使得片材。如果我只是使用Excel來插入圖表,它會將它插入期望的x/y軸。我怎樣才能做到這一點?

Generated Chart Sheet

[Worksheet with data[2]

Inserted Chart with expected X/Y axis

+0

嘗試使用'column'而不是'bar'並關注系列使用的數據範圍。 – jmcnamara

回答

1

那偉大的工作。謝謝!我不習慣做圖表,所以不同類型的人會混淆我,列與垂直酒吧與水平酒吧。