2017-03-23 8 views
1

일부 데이터를 더 잘 시각화하기 위해 간단한 원형 차트를 생성하려고하지만 XlsxWriter는 동시에 두 개의 열에 데이터를 쓰지 않을 것입니다. 다른 예제가 잘 작동하는 곳. 코드를 검색>[10.3, 4.17, 58.68, 24.42, 0.02, 0.0, 2.31, 0.12] 기능 아래XlsxWriter 동시에 여러 열에 쓰지 않습니다.

에 -

{'core2': [10.3], 'core3': [4.17], 'core0': [58.68], 'core1': [24.42], 'core6': [0.02], 'core7': [0.0], 'core4': [2.31], 'core5': [0.12]}) 

실제 데이터를 목록으로 전달됩니다

내가 잘못

진행에 따라 할 수있는 위치 우둔 해요 데이터입니다 :

def draw_simultaneously_busy_cores(type_of_chart,data,workbook): 
    print data 
    worksheet = workbook.add_worksheet()#'simultaneously_busy_cores') 
    bold = workbook.add_format({'bold': 1}) 
    headings = [0, 1, 2, 3, 4, 5, 6, 7] 
    worksheet.write_column('$A$1', headings, bold) 
    worksheet.write_column('$B$1',headings) 

    chart1 = workbook.add_chart({'type': type_of_chart}) 

    chart1.add_series({ 
     'name':  'Simultaneous Busy Cores', 
     'categories': ['simultaneously_busy_cores', '=simultaneously_busy_cores!$A$1:$A$8'], 
     'values':  ['simultaneously_busy_cores', '=simultaneously_busy_cores!$B$1:$B$8'], 
     #'data_labels': {'percentage': True, } 
     }) 
    #Add a title. 
    chart1.set_title({'name': 'Simultaneous Busy Cores'}) 
    #Set an Excel chart style. Colors with white outline and shadow. 
    chart1.set_style(10) 
    #Insert the chart into the worksheet (with an offset). 
    worksheet.insert_chart('C2', chart1, {'x_offset': 25, 'y_offset': 10}) 

감사합니다. 이미지는 아웃풋을 보여줍니다 : enter image description here

답변

1

그래야합니다. 다음은 샘플 데이터의 예는 다음과 같습니다

import xlsxwriter 

def draw_simultaneously_busy_cores(type_of_chart, data, workbook): 

    worksheet = workbook.add_worksheet('simultaneously_busy_cores') 
    bold = workbook.add_format({'bold': 1}) 
    worksheet.write_column('A1', data, bold) 
    worksheet.write_column('B1', data) 

    chart1 = workbook.add_chart({'type': type_of_chart}) 

    chart1.add_series({ 
     'name':  'Simultaneous Busy Cores', 
     'categories': '=simultaneously_busy_cores!$A$1:$A$8', 
     'values':  '=simultaneously_busy_cores!$B$1:$B$8', 
     }) 

    #Add a title. 
    chart1.set_title({'name': 'Simultaneous Busy Cores'}) 

    #Set an Excel chart style. Colors with white outline and shadow. 
    chart1.set_style(10) 

    #Insert the chart into the worksheet (with an offset). 
    worksheet.insert_chart('C2', chart1, {'x_offset': 25, 'y_offset': 10}) 


workbook = xlsxwriter.Workbook('test.xlsx') 

data = [0, 1, 2, 3, 4, 5, 6, 7]  
draw_simultaneously_busy_cores('line', data, workbook) 

workbook.close() 

출력 : enter image description here

차트 categories하고 예 values 구문이 올바르지 않습니다. 목록 및 문자열 구문을 혼합합니다. 설명서와 예제를 다시 읽습니다.

+0

예, 목록 및 문자열에 대한 구문을 어떻게 혼합했는지 모릅니다. 어떻게 든 그것을 잡을 수 없었습니다. 감사합니다. – R2D2