Date Axis in a Chart Does Not Work Correctly in a PowerPoint Presentation

Hi! I’m trying to make a chart that uses a date category axis type on the x axis, but I’m struggling to get the chart to correctly read my date data. I followed the example code (from Chart Axis|Aspose.Slides for Python Documentation) and found that the resulting graph (shown in the picture) also does not have the correct label format of “yyyy” that is specified in the code.

image.png (14.3 KB)

When I went to see the chart data behind the graph, it does not show the date data as was inputted in to the program, and instead shows all 1s. All the date labels on the chart also disappear after closing the edit data window, so it looks like the data isn’t being read correctly at all.

image.png (8.1 KB)

Is there a different example available that works? If not, I would appreciate any help with how to make the date axis work correctly.

Thanks!

@AQU89,
Thank you for contacting support. I am working on the issue and will get back to you as soon as possible.

@AQU89,
I’ve reproduced the problem you described.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESPYNET-134

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@AQU89,
Our developers have investigated the case.

The Python version of Aspose.Slides requires a little extra date manipulation. Please check the corrected code snippet in the documentation.

import aspose.slides.charts as charts
import aspose.slides as slides
from datetime import date

def to_oadate(dt):
    delta = dt - date(1899, 12, 30)
    return delta.days + (delta.seconds + delta.microseconds / 1e6) / (24 * 3600)

with slides.Presentation() as pres:
    chart = pres.slides[0].shapes.add_chart(charts.ChartType.AREA, 50, 50, 450, 300)

    wb = chart.chart_data.chart_data_workbook

    wb.clear(0)

    chart.chart_data.categories.clear()
    chart.chart_data.series.clear()

    chart.chart_data.categories.add(wb.get_cell(0, "A2", to_oadate(date(2015, 1, 1))))
    chart.chart_data.categories.add(wb.get_cell(0, "A3", to_oadate(date(2016, 1, 1))))
    chart.chart_data.categories.add(wb.get_cell(0, "A4", to_oadate(date(2017, 1, 1))))
    chart.chart_data.categories.add(wb.get_cell(0, "A5", to_oadate(date(2018, 1, 1))))

    series = chart.chart_data.series.add(charts.ChartType.LINE)
    series.data_points.add_data_point_for_line_series(wb.get_cell(0, "B2", 1))
    series.data_points.add_data_point_for_line_series(wb.get_cell(0, "B3", 2))
    series.data_points.add_data_point_for_line_series(wb.get_cell(0, "B4", 3))
    series.data_points.add_data_point_for_line_series(wb.get_cell(0, "B5", 4))
    chart.axes.horizontal_axis.category_axis_type = charts.CategoryAxisType.DATE
    chart.axes.horizontal_axis.is_number_format_linked_to_source = False
    chart.axes.horizontal_axis.number_format = "yyyy"
    pres.save("test.pptx", slides.export.SaveFormat.PPTX)