hi,
i’m using aspose word for java(17) version 24.2 but the problem persist also in 25.3.
I need to put some data in a specific line chart and for a better visualization i set the MarkerSymbol.CIRCLE on every ChartDataPoint.
I have notice that if the chart series are more than one, the legend show correctly the series names but if i have only one serie the legend show the value on the Y axis.
If i remove the MarkerSymbol instruction the problem is gone also if the serie is just one, can someone have the same problem?
the basic code to reproduce problem
Document pDOCUMENT = new Document("C:\\my_document.docx");
DocumentBuilder b = new DocumentBuilder(pDOCUMENT);
String[] labelsVal = new String[]{"cat 1","cat 2","cat 3","cat 4","cat 5"};
double[] values2 = new double[]{1.0,0.0,3.0,3.0,3.0};
Chart c1 = retrieveChart("Grafico 1",pDOCUMENT);
c1.getSeries().clear();
ChartSeries cs1 = c1.getSeries().add("test 1",labelsVal,values2);
cs1.getDataPoints().forEach((ChartDataPoint dp)->{
dp.getMarker().setSymbol(MarkerSymbol.CIRCLE);
dp.getMarker().setSize(10);
});
pDOCUMENT.save(dataDir + "output"+dateForm+".docx");
this is the wrong legend
IF i add a new serie:
ChartSeries cs2 = c1.getSeries().add("test 2",labelsVal,new double[]{12.0,3.0,44.0,5.0,3.0});
cs2.getDataPoints().forEach((ChartDataPoint dp)->{
dp.getMarker().setSymbol(MarkerSymbol.CIRCLE);
dp.getMarker().setSize(10);
});
the legend is correct
@fabio.cappelli
It seems you are experiencing an issue with the chart legend in Aspose.Words for Java when using a single series with a specified marker symbol. Specifically, when you set the MarkerSymbol.CIRCLE
for each ChartDataPoint
, the legend displays the Y-axis value instead of the series name.
This behavior appears to be related to how the chart legend is generated when there is only one series. When you remove the marker symbol setting, the legend displays correctly.
To troubleshoot this issue, you might consider the following steps:
-
Check for Updates: Ensure you are using the latest version of Aspose.Words for Java, as updates may contain bug fixes related to chart rendering.
-
Modify Marker Settings: If the issue persists, try using a different marker symbol or adjusting the marker size to see if it affects the legend display.
-
Test with Additional Series: As you noted, adding a second series resolves the issue. If possible, consider structuring your chart to include at least two series, which may help maintain the expected legend behavior.
-
Contact Support: If none of the above solutions work, consider reaching out to Aspose support with a minimal reproducible example. This will help them investigate the issue further.
Here is a simplified version of your code that you can use to test the behavior:
Document pDOCUMENT = new Document("C:\\my_document.docx");
DocumentBuilder b = new DocumentBuilder(pDOCUMENT);
String[] labelsVal = new String[]{"cat 1", "cat 2", "cat 3", "cat 4", "cat 5"};
double[] values = new double[]{1.0, 0.0, 3.0, 3.0, 3.0};
Chart chart = retrieveChart("Grafico 1", pDOCUMENT);
chart.getSeries().clear();
ChartSeries series = chart.getSeries().add("test 1", labelsVal, values);
series.getDataPoints().forEach(dp -> {
dp.getMarker().setSymbol(MarkerSymbol.CIRCLE);
dp.getMarker().setSize(10);
});
pDOCUMENT.save("output.docx");
This code should help you verify if the issue is consistent across different configurations. If you continue to face problems, please provide additional details or examples to assist in further troubleshooting.
@fabio.cappelli To get the expected output should should set formatting of whole series not of individual data points:
Document doc = new Document("C:\\Temp\\in.docx");
String[] labelsVal = new String[] { "cat 1", "cat 2", "cat 3", "cat 4", "cat 5" };
double[] values2 = new double[] { 1.0, 0.0, 3.0, 3.0, 3.0 };
Chart c1 = ((Shape)doc.getChild(NodeType.SHAPE, 0, true)).getChart();
c1.getSeries().clear();
ChartSeries cs1 = c1.getSeries().add("test 1", labelsVal, values2);
cs1.getMarker().setSymbol(MarkerSymbol.CIRCLE);
cs1.getMarker().setSize(10);
doc.save("C:\\Temp\\out.docx");
1 Like