Hi, guys
I want to use Aspose to create a combo chart with bar chart and line chart. I’d like to set the y-axis of series 1,2 on the left, and the y-axis of series_3 on the left. Like the below.
image.png (48.7 KB)
However, I found I couldn’t adjust the y-axis of series_3 data, to set it on the right.
Here is what i got:
image.png (206.6 KB)
it can be easily set by manually.
image.jpg (127.3 KB)
Here is my code, that following the sample code. Could you please tell me if i have missed something? I’d like to purchase ASPOSE after i solve the problem.
Thanks
import aspose.slides as slides
import aspose.slides.charts as charts
def create_combo_chart():
pres = slides.Presentation()
chart = create_chart(pres.slides[0])
add_first_series_to_chart(chart)
#add_second_series_to_chart(chart)
pres.save("combo-chart.pptx", slides.export.SaveFormat.PPTX)
def create_chart(slide):
chart = slide.shapes.add_chart(charts.ChartType.CLUSTERED_COLUMN, 50, 50, 500, 400)
chart.chart_data.series.clear()
chart.chart_data.categories.clear()
workbook = chart.chart_data.chart_data_workbook
worksheet_index = 0
chart.chart_data.series.add(workbook.get_cell(worksheet_index, 0, 1, "Series 1"), chart.type)
chart.chart_data.series.add(workbook.get_cell(worksheet_index, 0, 2, "Series 2"), chart.type)
chart.chart_data.categories.add(workbook.get_cell(worksheet_index, 1, 0, "Caetegoty 1"))
chart.chart_data.categories.add(workbook.get_cell(worksheet_index, 2, 0, "Caetegoty 2"))
chart.chart_data.categories.add(workbook.get_cell(worksheet_index, 3, 0, "Caetegoty 3"))
series = chart.chart_data.series[0]
print(workbook.get_cell(worksheet_index, 1, 1, 20))
series.data_points.add_data_point_for_bar_series(workbook.get_cell(worksheet_index, 1, 1, 20))
series.data_points.add_data_point_for_bar_series(workbook.get_cell(worksheet_index, 2, 1, 50))
series.data_points.add_data_point_for_bar_series(workbook.get_cell(worksheet_index, 3, 1, 30))
series = chart.chart_data.series[1]
series.data_points.add_data_point_for_bar_series(workbook.get_cell(worksheet_index, 1, 2, 30))
series.data_points.add_data_point_for_bar_series(workbook.get_cell(worksheet_index, 2, 2, 10))
series.data_points.add_data_point_for_bar_series(workbook.get_cell(worksheet_index, 3, 2, 60))
return chart
def add_first_series_to_chart(chart):
workbook = chart.chart_data.chart_data_workbook
worksheet_index = 0
series = chart.chart_data.series.add(workbook.get_cell(worksheet_index, 0, 3, "Series 3"), charts.ChartType.LINE)
series.data_points.add_data_point_for_line_series(workbook.get_cell(worksheet_index, 1, 3, 0.3))
series.data_points.add_data_point_for_line_series(workbook.get_cell(worksheet_index, 2, 3, 0.1))
series.data_points.add_data_point_for_line_series(workbook.get_cell(worksheet_index, 3, 3, 0.5))
series.plot_on_second_axis = True
def add_second_series_to_chart(chart):
workbook = chart.chart_data.chart_data_workbook
worksheet_index = 0
series = chart.chart_data.series.add(workbook.get_cell(worksheet_index, 0, 5, "Series 4"), charts.ChartType.SCATTER_WITH_STRAIGHT_LINES_AND_MARKERS)
series.data_points.add_data_point_for_scatter_series(workbook.get_cell(worksheet_index, 1, 3, 5), workbook.get_cell(worksheet_index, 1, 4, 2))
series.data_points.add_data_point_for_scatter_series(workbook.get_cell(worksheet_index, 1, 5, 10), workbook.get_cell(worksheet_index, 1, 6, 7))
series.data_points.add_data_point_for_scatter_series(workbook.get_cell(worksheet_index, 2, 5, 15), workbook.get_cell(worksheet_index, 2, 6, 12))
series.data_points.add_data_point_for_scatter_series(workbook.get_cell(worksheet_index, 3, 5, 12), workbook.get_cell(worksheet_index, 3, 6, 9))
series.plot_on_second_axis = True
create_combo_chart()