双Y轴图表,Y轴上添加单位如万,word可以正常显示,转PDF后显示存在问题。

双Y轴图表,Y轴上添加单位如万,word可以正常显示,转PDF后显示存在问题。微信图片_20240422181738.png (50.6 KB)
具体请看压缩文档https://f.ws59.cn/f/dxo6b5u3uz4 复制链接到浏览器打开

@SalesDhorde 使用您提供的代码,我得到了与您不同的结果。看起来遗漏了一些代码。

output.pdf (27.4 KB)

文叔叔 - 传文件,找文叔叔(永不限速) 复制链接到浏览器打开
按照如下方式生成图表后,使用office word 2016版本打开报错,使用wps 2019可以正常打开
微信图片_20240423093124.png (37.6 KB)

1ed136d0f62f0d8824ad629ade18f70.png (6.7 KB)

@SalesDhorde 在删除次坐标轴后,Aspose.Words 会更改图表类型。遗憾的是,Aspose.Words 无法更改复合图表。

双Y轴图表,Y轴上添加单位如万,word可以正常显示,转PDF后显示存在问题文叔叔 - 传文件,找文叔叔(永不限速) 复制链接到浏览器打开,这个是重新提供的代码,请帮忙看看

那么如下场景应该如何实现,1、word中插入图表为饼图默认有三个系列,如果数据内容只有一个系列,如何给图表进行赋值,请提供代码。
微信图片_20240424181644.png (40.7 KB)

@SalesDhorde 感谢您报告此问题。 我们已经在我们的内部问题跟踪系统中打开了以下新工单,并将根据 免费支持政策 中提到的条款提供它们的修复:

Issue ID(s): WORDSNET-26910

如果您需要优先支持以及直接联系我们的付费支持管理团队,您可以获得 付费支持服务

@SalesDhorde 您可以通过以下方法实现:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Chart chart = builder.insertChart(ChartType.PIE, ConvertUtil.pixelToPoint(300),
        ConvertUtil.pixelToPoint(300)).getChart();
chart.getSeries().clear();
chart.getSeries().add("My fruit",
        new String[] { "Apples", "Bananas", "Cherries" },
        new double[] { 1.3, 2.2, 1.5 });

doc.save("output.docx");

这个问题有个场景需要帮忙回答一下,我在word里插入一个饼图(不用aspose的insertchart方式插入)手动设置好样式如数据小数位数字体颜色等等,使用aspose读取饼图按这种方式给饼图赋值会导致样式不生效,该如何解决,请提供解决方案和代码

@SalesDhorde 好的,我会检查一下,然后给您回复。

@SalesDhorde 我用您之前提供的代码检查了 PieChart,没有发现任何样式问题。我创建了图表,并手动配置了我的样式。默认情况下,PieChart 有一个系列和四个类别。以下是我的输入和输出数据。

Artifacts.zip (32.7 KB)

这是您提供的代码:

Document doc = new Document(getMyDir() + "PieChart.docx");
double[] lstV1 = new double[]{71.0, 65.0, 200.0};

Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
Chart chart = shape.getChart();
for (ChartSeries series : chart.getSeries()){
    series.clearValues();
}

String[] categories1 = new String[]{"王小石", "南晓强", "吴贵福"};
ChartSeries series1 = chart.getSeries().get(0);

series1.setName("BNMB");

for (int i = 0; i < categories1.length; i++)
{
    ChartXValue x = ChartXValue.fromString(categories1[i]);
    series1.add(x, ChartYValue.fromDouble(lstV1[i]));
}

doc.save(getArtifactsDir() + "output.docx");

如果不一样,请分享您的文件和代码,以解决您遇到的相同问题。

目前有以下几个问题需要解答:
1、word中插入图表为组合图(折线+柱形)默认带三个系列,如果数据内容有2个系列或4个系列,如何使用aspose给图表进行赋值,
使用提供的实例生成的文档使用word打开报错,请提供代码;
微信图片_20240426154600.png (7.9 KB)

2、word中插入图表为折线图默认带三个系列,如果数据内容有1个系列或4个系列,如何使用aspose给图表进行赋值,请提供代码;

3、word中插入图表为饼图默认带三个系列,如果数据内容只有1个系列或4个系列,如何使用aspose给图表进行赋值,请提供代码;

4.4、什么场景下用 chart.getSeries().clear(),什么场景下用chart.getSeries().get(i).clearValues()

代码:https://f.ws59.cn/f/dysayabza45 复制链接到浏览器打开

@SalesDhorde 如上所述,我们并不完全支持编辑组合图表。但在任何情况下,您都可以使用以下代码删除或添加系列:

Document doc = new Document("input.docx");
double[] lstV1 = new double[]{71.0, 65.0, 200.0};
double[] lstV2 = new double[]{14.0, 0.0, 74.0,0.0,68.0};
double[] lstV3 = new double[]{1.0, 2.0, 7.0,0.0,8.0};
Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
Chart chart = shape.getChart();
for (ChartSeries series : chart.getSeries()){
    series.clearValues();
}

String[] categories1 = new String[]{"王小石", "南晓强", "吴贵福"};
ChartSeries series1 = chart.getSeries().get(0);
ChartSeries series2 = chart.getSeries().get(1);
ChartSeries series3 = chart.getSeries().get(2);        

series1.setName("BNMB");
series2.setName("LJWC");
series3.setName("GL");

for (int i = 0; i < categories1.length; i++)
{
    ChartXValue x = ChartXValue.fromString(categories1[i]);
    series1.add(x, ChartYValue.fromDouble(lstV1[i]));
    series2.add(x, ChartYValue.fromDouble(lstV2[i]));
    series3.add(x, ChartYValue.fromDouble(lstV3[i]));
}

ChartSeries series = chart.getSeries().add("ANMB",
        new String[]{"Word", "PDF", "Excel"},
        new double[]{2.7, 3.2, 0.8});

// Enable data labels that will display both percentage and frequency of each sector, and modify their appearance.
series.hasDataLabels(true);
ChartDataLabelCollection dataLabels = series.getDataLabels();
dataLabels.setShowLeaderLines(true);
dataLabels.setShowLegendKey(true);
dataLabels.setShowPercentage(true);
dataLabels.setShowValue(true);
dataLabels.setSeparator("; ");

chart.getSeries().removeAt(1);

doc.save("output.docx");

使用 ChartSeriesCollection | Aspose.Words for Java 删除不需要的系列。

使用 ChartSeriesCollection | Aspose.Words for Java 添加您需要的系列和数据。

clearValues()用于只删除不保留任何格式化的值。 clear() 用于删除带有数据标签和其他格式化的值。

对于组合图(双Y轴)默认带了三个系列,如果数据内容有4个系列,使用aspose新增的第4个系列如何指定属于次坐标轴还是主坐标轴,请提供代码。

@SalesDhorde 我们将在下一个版本 24.5 中提供使用辅助轴组的权限。当前版本不支持。

下面的示例说明了如何使用它。真正的代码将在移植到 Java 后提供。

Document doc = new Document("input.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
Chart chart = shape.getChart();

for (ChartSeriesGroup secondaryAxisGroup : chart.getSeriesGroups())
{
    if (secondaryAxisGroup.getAxisGroup() == AxisGroup.SECONDARY)
    {
        // Hide the secondary X axis.
        secondaryAxisGroup.getAxisX().setHidden(true);
        // Define title of the secondary Y axis.
        secondaryAxisGroup.getAxisY().getTitle().setShow(true);
        secondaryAxisGroup.getAxisY().getTitle().setText("Secondary Y axis");
    }
}

doc.save("ComboChart.docx");

获得次轴后,可以像使用主轴一样使用主题。

The issues you have found earlier (filed as WORDSNET-20209) have been fixed in this Aspose.Words for .NET 24.5 update also available on NuGet.