def ronava_bar_chart(writingSheet, dataSheet, params): # TODO add dictionary in parameters to avoid overlapping if params["use"] == "bars": data = Reference( dataSheet, min_col=params["data_min_col"], min_row=params["data_min_row"], max_row=params["data_max_row"], max_col=params["data_max_col"], ) cats = Reference( dataSheet, min_col=params["cats_min_col"], min_row=params["cats_min_row"], max_row=params["cats_max_row"], max_col=params["cats_max_col"], ) chart = BarChart() chart.type = params["type"] chart.style = 12 # chart.grouping = "stacked" chart.title = params["title"] chart.y_axis.title = params["y_axis"] chart.x_axis.title = params["x_axis"] chart.add_data(data, titles_from_data=True) chart.set_categories(cats) chart.height = params["heigth"] chart.width = params["width"] writingSheet.add_chart(chart, "D2") elif params["use"] == "single": c1 = BarChart() v1 = Reference( dataSheet, min_col=params["data_min_col"], min_row=params["data_min_row"], max_col=params["data_max_col"] ) cats = Reference( dataSheet, min_col=params["cats_min_col"], min_row=params["cats_min_row"], max_col=params["cats_max_col"] ) c1.series = [Series(v1, title_from_data=True)] c1.style = 12 c1.set_categories(cats) c1.x_axis.title = params["x_axis"] c1.y_axis.title = params["y_axis"] c1.height = params["heigth"] c1.width = params["width"] c1.title = params["title"] writingSheet.add_chart(c1, "D4") else: c1 = BarChart() v1 = Reference( dataSheet, min_col=params["data_min_col"], min_row=params["data_min_row"], max_col=params["data_max_col"] ) cats = Reference( dataSheet, min_col=params["cats_min_col"], min_row=params["cats_min_row"], max_col=params["cats_max_col"] ) c1.series = [Series(v1, title_from_data=True)] c1.y_axis.majorGridlines = None c1.set_categories(cats) c1.x_axis.title = params["x_axis"] c1.y_axis.title = params["y_axis"] c1.height = params["heigth"] c1.width = params["width"] c1.title = params["title"] c1.style = 12 # Create a second chart c2 = LineChart() v2 = Reference( dataSheet, min_col=params["data_min_col"], min_row=params["data_min_row"] + 1, max_col=params["data_max_col"], ) c2.series = [Series(v2, title_from_data=True)] c2.y_axis.axId = 20 c2.y_axis.title = "Porcentaje Produccion" # Assign the y-axis of the second chart to the third axis of the first chart c1.z_axis = c2.y_axis c1.y_axis.crosses = "max" c1 += c2 writingSheet.add_chart(c1, "D4")
['Humans', 10, 40, 50, 20, 10, 50], ] for row in rows: ws.append(row) c1 = BarChart() v1 = Reference(ws, min_col=1, min_row=1, max_col=7) c1.series = [Series(v1, title_from_data=True)] c1.x_axis.title = 'Days' c1.y_axis.title = 'Aliens' c1.y_axis.majorGridlines = None c1.title = 'Survey results' # Create a second chart c2 = LineChart() v2 = Reference(ws, min_col=1, min_row=2, max_col=7) c2.series = [Series(v2, title_from_data=True)] c2.y_axis.axId = 20 c2.y_axis.title = "Humans" # Assign the y-axis of the second chart to the third axis of the first chart c1.z_axis = c2.y_axis c1.y_axis.crosses = "max" c1 += c2 ws.add_chart(c1, "D4") wb.save("secondary.xlsx")