Aspose.Slides Python折线图数据标签格式设置问题
折线图数据标签格式设置方案
针对你需要的数据标签字体加粗和添加带颜色的边框/背景需求,修正后的代码及关键说明如下:
修正后的完整代码
series = chart.chart_data.series.add(fact.get_cell(defaultWorksheetIndex, 0, 4, "asdf"), charts.ChartType.LINE) series.data_points.add_data_point_for_line_series(fact.get_cell(defaultWorksheetIndex, 1, 4, 80)) series.data_points.add_data_point_for_line_series(fact.get_cell(defaultWorksheetIndex, 2, 4, 77)) series.data_points.add_data_point_for_line_series(fact.get_cell(defaultWorksheetIndex, 3, 4, 83)) series.data_points.add_data_point_for_line_series(fact.get_cell(defaultWorksheetIndex, 4, 4, 80)) series.format.line.fill_format.fill_type = slides.FillType.SOLID series.format.line.fill_format.solid_fill_color.color = draw.Color.from_argb(79, 129, 189) series.plot_on_second_axis = True # 数据标签基础设置 series.labels.default_data_label_format.show_value = True series.labels.default_data_label_format.is_number_format_linked_to_source = False # 1. 设置字体粗体(修正赋值方式) series.labels.default_data_label_format.text_format.portion_format.font_height = 10 series.labels.default_data_label_format.text_format.portion_format.font_bold = slides.NullableBool.TRUE series.labels.default_data_label_format.text_format.portion_format.fill_format.fill_type = slides.FillType.SOLID series.labels.default_data_label_format.text_format.portion_format.fill_format.solid_fill_color.color = draw.Color.from_argb(31, 73, 125) # 2. 设置标签背景填充和边框 # 启用标签背景填充 series.labels.default_data_label_format.fill_format.fill_type = slides.FillType.SOLID series.labels.default_data_label_format.fill_format.solid_fill_color.color = draw.Color.from_argb(240, 240, 240) # 自定义背景色 # 设置标签边框格式 series.labels.default_data_label_format.line.fill_format.fill_type = slides.FillType.SOLID series.labels.default_data_label_format.line.fill_format.solid_fill_color.color = draw.Color.from_argb(31, 73, 125) series.labels.default_data_label_format.line.width = 1 # 设置边框宽度确保可见
关键修改说明
- 字体粗体修正:Aspose的
font_bold属性需赋值为slides.NullableBool.TRUE枚举值,而非直接写1,这是API标准用法,能正确触发粗体效果。 - 标签背景填充:数据标签的背景需通过
default_data_label_format.fill_format设置(而非文本段落的填充),可根据需求自定义背景色。 - 标签边框设置:取消原代码中边框设置的注释,同时添加
line.width指定边框粗细(默认可能过细不可见),边框颜色可按需调整。
内容的提问来源于stack exchange,提问作者Марлен Каримов
相关产品推荐
相关产品推荐

