I’m using the Aspose library to generate line with marker charts and programmatically setting custom marker shapes for data points. However, when opening the generated file in Excel, the selected marker shapes are not applied or do not appear as expected. This issue persists across different marker shape types.
I have attached Excel file and code here. I have used Star and Plus shapes but in output file I see square.
linewithmakeraspose.zip (10.4 KB)
It seems that you are experiencing an issue where the custom marker shapes set for line with marker charts are not being reflected in the Excel output generated using the Aspose library. This can be frustrating, especially when you have specific visual requirements for your charts.
To troubleshoot this issue, you can follow these steps:
-
Ensure Correct Marker Type: Make sure that you are setting the marker type correctly for each data series in your chart. For example, you can set the marker style using the
Marker.MarkerStyle
property for each series.Here’s a sample code snippet that demonstrates how to set different marker styles for a line chart with data markers:
// Assuming 'chart' is your Chart object chart.NSeries[0].Marker.MarkerStyle = Aspose.Cells.Charts.ChartMarkerType.Triangle; chart.NSeries[1].Marker.MarkerStyle = Aspose.Cells.Charts.ChartMarkerType.Circle;
-
Check Excel Compatibility: Sometimes, certain features may not be fully supported in the version of Excel you are using to open the file. Ensure that you are using a compatible version of Excel that supports the marker styles you are applying.
-
Update Aspose.Cells Library: Ensure that you are using the latest version of the Aspose.Cells library. Updates often include bug fixes and improvements that may resolve your issue.
-
Review Documentation: You can refer to the Aspose.Cells documentation for setting chart appearances, which includes details on customizing chart markers. This can provide additional insights into the properties you can set and their expected behavior.
-
Test with Sample Data: If possible, create a simple test case with minimal data to isolate the issue. This can help determine if the problem lies with the data or the chart configuration.
If the issue persists after trying these steps, consider sharing your code snippet and any specific details about the marker shapes you are trying to apply. This will help in diagnosing the problem more effectively.
For further assistance, you might want to check similar discussions in the Aspose forums, as other users may have encountered and resolved similar issues.
Sources:
[1]: Set Chart Lines | Aspose.Cells .NET Excel Processing API
I’ve reviewed your sample code and the Excel file with the chart. Could you also provide us with an Excel file that includes the chart with your desired formatted markers? You may update the marker styles and formatting in the output Excel file (by Aspose.Cells) using Ms Excel manually and re-save the file. We’ll evaluate it and assist you in creating the chart with the specified formatted markers.
Thanks for the sample file having your desired formatted markers for the chart.
Please see the following sample code to accomplish your task for your reference. You may refer to the code segment and write/update it accordingly for your needs (if required).
e.g.,
Sample code:
// ExStart:1
// Instantiate a workbook
Workbook workbook = new Workbook();
// Access first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Set columns title
worksheet.getCells().get(0, 0).setValue("X");
worksheet.getCells().get(0, 1).setValue("Y");
// Create random data and save in the cells
for (int i = 1; i < 21; i++)
{
worksheet.getCells().get(i, 0).setValue(i);
worksheet.getCells().get(i, 1).setValue(0.8);
}
for (int i = 21; i < 41; i++)
{
worksheet.getCells().get(i, 0).setValue(i - 20);
worksheet.getCells().get(i, 1).setValue(0.9);
}
// Add a chart to the worksheet
int idx = worksheet.getCharts().add(com.aspose.cells.ChartType.LINE_WITH_DATA_MARKERS, 1, 3, 20, 20);
// Access the newly created chart
Chart chart = worksheet.getCharts().get(idx);
// Set chart style
chart.setStyle(3);
// Set autoscaling value to true
chart.setAutoScaling(true);
// Set foreground color white
chart.getPlotArea().getArea().setForegroundColor(com.aspose.cells.Color.getWhite());
// Set Properties of chart title
chart.getTitle().setText("Sample Chart");
// Set chart type
chart.setType(com.aspose.cells.ChartType.LINE_WITH_DATA_MARKERS);
// Set Properties of categoryaxis title
chart.getCategoryAxis().getTitle().setText("Units");
//Set Properties of nseries
int s2_idx = chart.getNSeries().add("A2: A2", true);
int s3_idx = chart.getNSeries().add("A22: A22", true);
// Set X and Y values of series chart
chart.getNSeries().get(s2_idx).setXValues("A2: A21");
chart.getNSeries().get(s2_idx).setValues("B2: B21");
// Set X and Y values of series chart
chart.getNSeries().get(s3_idx).setXValues("A22: A41");
chart.getNSeries().get(s3_idx).setValues("B22: B41");
// Set IsColorVaried to true for varied points color
chart.getNSeries().setColorVaried(true);
// Set properties of background area and series markers
chart.getNSeries().get(s2_idx).getMarker().setMarkerStyle(ChartMarkerType.SQUARE_STAR);
chart.getNSeries().get(s2_idx).getMarker().setMarkerSize(11);
chart.getNSeries().get(s2_idx).getArea().setFormatting(FormattingType.CUSTOM);
chart.getNSeries().get(s2_idx).getBorder().setColor(com.aspose.cells.Color.getYellow());
chart.getNSeries().get(s2_idx).getMarker().getArea().setFormatting(FormattingType.NONE);
chart.getNSeries().get(s2_idx).getMarker().getBorder().setVisible(true);
chart.getNSeries().get(s2_idx).getMarker().getBorder().setColor(com.aspose.cells.Color.getYellow());
// Set properties of background area and series markers
chart.getNSeries().get(s3_idx).getMarker().setMarkerStyle(ChartMarkerType.SQUARE_PLUS);
chart.getNSeries().get(s3_idx).getMarker().setMarkerSize(5);
chart.getNSeries().get(s3_idx).getArea().setFormatting(FormattingType.CUSTOM);
chart.getNSeries().get(s3_idx).getBorder().setColor(com.aspose.cells.Color.getGreen());
chart.getNSeries().get(s3_idx).getMarker().getArea().setFormatting(FormattingType.NONE);
chart.getNSeries().get(s3_idx).getMarker().getBorder().setVisible(true);
chart.getNSeries().get(s3_idx).getMarker().getBorder().setColor(com.aspose.cells.Color.getGreen());
// Save the workbook
workbook.save( "d:\\files\\LineWithDataMarkerChart1.xlsx", SaveFormat.XLSX);
// ExEnd:1
// Print message
System.out.println("CreateLineWithDataMarkerChart executed successfully.");
Hope, this helps a bit.