تصدير الرسم البياني إلى SVG مع خاصية viewBox

بشكل افتراضي، عند تصدير الرسم البياني إلى تنسيق SVG، فإن سمة viewBox لا تكون مُدرجة في XML. ومع ذلك، توفر Aspose.Cells خاصية ImageOrPrintOptions.setSVGFitToViewPort() التي عند ضبطها على true يتم تصدير الرسم البياني إلى SVG مع سمة viewBox.

إذا فتحت ملف SVG الخاص بالرسم البياني في المفكرة، فستجد سمة viewBox مماثلة لهذه.

 <svg xmlns="http://www.w3.org/2000/svg"

     xmlns:xlink="http://www.w3.org/1999/xlink"

     width="100%" height="100%"

     viewBox="0 0 480 288">

مقتطف الكود

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ExportCharttoSVG.class);
// Create workbook object from source file
Workbook workbook = new Workbook(dataDir + "source.xlsx");
// Access first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Access first chart inside the worksheet
Chart chart = worksheet.getCharts().get(0);
// Set image or print options
// with SVGFitToViewPort true
ImageOrPrintOptions opts = new ImageOrPrintOptions();
opts.setSaveFormat(SaveFormat.SVG);
opts.setSVGFitToViewPort(true);
// Save the chart to svg format
chart.toImage(dataDir + "out.svg", opts);

مقالات ذات صلة