I am creating a bubble chart using OpenXML and then utilizing Aspose.Cells and Aspose.Imaging for extracting the chart from excel and saving it as SVG. I am using C# with Aspose.Cells version 22.1.0 and Aspose.Imaging version 22.4.0.
Since bubble charts do not support symbols directly, I am adding Plus.png as external images. However, when the SVG is generated, the Plus.png image appears in a different location compared to its position in Excel.
Below is an image of the chart in Excel: image.png (26.1 KB)
And here is the generated SVG using Aspose: image.png (33.0 KB)
Any guidance on resolving this issue would be greatly appreciated.
@John.He Thanks for the reply, I am adding some snippets of how I add image to Aspose.Cells.Charts.Chart. I had to add external image because Aspose does not recognize the marker symbols from an excel document.
///
/// Identify the series and add external image as shape fill to it.
/// We are adding images to Aspose Chart as well due to the limitation where
/// Aspose does not recognize the marker symbols from an excel document.
///
///
///
private void AddExternalImages(Chart chart, IEnumerable externalImageSeries)
{
foreach (var image in externalImageSeries)
{
var chartSeries = chart.NSeries.Find(s => s.Name == image.ExternalMarkerImage.SeriesName);
chartSeries.Area.FillFormat.FillType = Aspose.Cells.Drawing.FillType.Texture;
chartSeries.Area.FillFormat.ImageData = File.ReadAllBytes(image.ExternalMarkerImage.ImagePath);
}
}
double chartWidth = 0;
double chartHeight = 0;
double chartWidthInch = 0;
double chartHeightInch = 0;
// Iterate over the range of cells to calculate the total width and height
for (int i = chart.ChartObject.UpperLeftColumn; i <= (chart.ChartObject.LowerRightColumn); i++)
{
chartWidth += worksheet.Cells.GetColumnWidthPixel(i);
chartWidthInch += worksheet.Cells.GetColumnWidthInch(i);
}
for (int i = chart.ChartObject.UpperLeftRow; i <= (chart.ChartObject.LowerRightRow); i++)
{
chartHeight += worksheet.Cells.GetRowHeightPixel(i);
chartHeightInch += worksheet.Cells.GetRowHeightInch(i);
}
// Save the chart as SVG with the calculated dimensions
ImageOrPrintOptions opts = new ()
{
OnePagePerSheet = true,
// Set the custom width and height
HorizontalResolution = (int)chartWidth,
VerticalResolution = (int)chartHeight,
SaveFormat = Aspose.Cells.SaveFormat.Svg,
SVGFitToViewPort = true
};
chart.ChartObject.HeightInch = chartHeightInch;
chart.ChartObject.WidthInch = chartWidthInch;
//Resize chart Object based on height and width.
//ReSizeChartObject(chart, chartFormat);
chart.ToImage(newFile.FullName, opts);
return newFile;
After an initial testing, I was able to reproduce the issue as you mentioned by using the following sample code with your template file. I found external image is placed at wrong position in Excel chart to SVG rendering.
Workbook workbook = new Workbook("e:\\test2\\sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
Chart chart = worksheet.Charts[0];
double chartWidth = 0;
double chartHeight = 0;
double chartWidthInch = 0;
double chartHeightInch = 0;
// Iterate over the range of cells to calculate the total width and height
for (int i = chart.ChartObject.UpperLeftColumn; i <= (chart.ChartObject.LowerRightColumn); i++)
{
chartWidth += worksheet.Cells.GetColumnWidthPixel(i);
chartWidthInch += worksheet.Cells.GetColumnWidthInch(i);
}
for (int i = chart.ChartObject.UpperLeftRow; i <= (chart.ChartObject.LowerRightRow); i++)
{
chartHeight += worksheet.Cells.GetRowHeightPixel(i);
chartHeightInch += worksheet.Cells.GetRowHeightInch(i);
}
// Save the chart as SVG with the calculated dimensions
ImageOrPrintOptions opts = new ()
{
OnePagePerSheet = true,
// Set the custom width and height
HorizontalResolution = (int)chartWidth,
VerticalResolution = (int)chartHeight,
ImageType = ImageType.Svg,
SVGFitToViewPort = true
};
chart.ChartObject.HeightInch = chartHeightInch;
chart.ChartObject.WidthInch = chartWidthInch;
chart.ToImage("e:\\test2\\out1.svg", opts);
We require thorough evaluation of the issue. 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): CELLSNET-56197
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.
@amjad.sahi Thanks for your reply. I verified that my company has opted for paid support, but I am unable to log in. Does access need to be initiated by a specific person within the company?
And we will try our best to reslove this Bug of chart2image.
BTW the series is filled by image in the attached file . We can directly export the chart to svg with 24.7 though there are still two issues: image position and axis’ title position.
Could you post a template file with the marker symbols ?
Please note that your company has active Business Support linked to the email address shisoftwarepurchases@broadridge.com.
The helpdesk supports sub-accounts and the owner of the subscription (shisoftwarepurchases@broadridge.com) can add you as a subaccount so you can access the Paid Support ticket system. For more information, kindly check the following guide: Paid Support Helpdesk - aspose.com
If you encounter any issues or have questions, please let me know.