Export Custom Size

Overview

By default, when exporting chart to a file of any format, for the width and height of the image or PDF document AnyChart Stock uses the width and height of the flash player for the moment the export is being called.

Some cases require greater flexibility in size when exporting charts. For example, inserting charts into a report as static images with a different layout.

AnyChart Stock gives complete and very flexible control over the size of images and PDF documents being exported. Besides the custom size, the component also allows defining the mode - how the chart would appear when exported at a certain custom size.

Just like the other export settings, the custom size and all the options related to it are configured for each file format individually.

For the sake of better clearness, the component comes with a number of examples; along the course of using them you can quickly familiarize yourself with all the export functions and in particular those that are related to using custom size when exporting.

Below are the links to these examples in all the formats:

Online HTML/JavaScript Sample
Online HTML/JavaScript Sample
Online HTML/JavaScript Sample
Online HTML/JavaScript Sample

to top

Setting Up Custom Size

To export a chart at a custom size, you need to switch the output size mode and set the desired width and height - in pixels - for the desired format.

Here is a sample syntax for setting up a custom size to the JPG/PNG and PDF formats:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <utils>
04     <export_settings>
05       <png_image size="Custom" width="640" height="480" />
06       <jpg_image size="Custom" width="640" height="480" />
07       <pdf size="Custom" width="640" height="480" />
08     </export_settings>
09   </utils>
10 </stock>
01{
02  utils: {
03    exportSettings: {
04      pngImage: {
05        size: "Custom",
06        width: 640,
07        height: 480
08      },
09      jpgImage: {
10        size: "Custom",
11        width: 640,
12        height: 480
13      },
14      pdf: {
15        size: "Custom",
16        width: 640,
17        height: 480
18      }
19    }
20  }
21}

As you can see it on the listing, to switch export to a custom size for all the formats, you need to use the size attribute and set its value to "Custom". After that, set the desired chart width and height in pixels with the width and height attributes respectively.

Here is a live example where you can try out this configuration in action. Right-click on the chart area, then select "Save as PNG..." on the menu that appears and save the chart to your hard drive or, save the chart using the "PNG" button on the toolbar under the chart. Once you have saved the chart, you can see for yourself that regardless of the size of the window displaying the chart, the size of the exported image will always be 640 by 480 pixels.

Live Sample:  Export - Using Custom Image Size

to top

Resizing Modes

When using a custom size, different than the original size of the chart, for the image or PDF document being exported, the component changes the appearance of the chart and makes it fit the new width and height. This operation can use several chart recalculation mechanisms, the so-called "resizing modes".

Here is a sample syntax for setting up the Resizing Mode by the example of exporting to a PNG image:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <utils>
04     <export_settings>
05       <png_image size="Custom" width="640" height="480" resizing_mode="RecalculateByProportions" />
06     </export_settings>
07   </utils>
08 </stock>
01{
02  utils: {
03    exportSettings: {
04      pngImage: {
05        size: "Custom",
06        width: 640,
07        height: 480,
08        resizingMode: "RecalculateByProportions"
09      }
10    }
11  }
12}

As you can see it on the listing, the mode is set by the resizing_mode attribute, which can accept the following values: Recalculate, Stretch, Fit, RecalculateByProportions and Combined. The Combined mode is supported exclusively for the Interactive PDF format. By default, for all the formats, the resizing_mode attribute is set to Fit.

The sections below provide vivid description and demonstration of the modes.

to top

Resizing Mode: Recalculate

In the Recalculate mode, the chart uses absolute coordinates for recalculating its content when obtaining a new width and height. All the elements on the chart, after the recalculation, have the same scale as on the original chart.

Here is a set of illustrations demonstrating the behavior of a chart when exporting in the Recalculate resizing mode using different input image dimensions (click on the thumbnails to view the illustrations in full size):

Original Exported: 1280x960 Exported: 350x250

Here is a sample syntax for enabling this mode for all the exported file types:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <utils>
04     <export_settings>
05       <png_image size="Custom" width="800" height="600" resizing_mode="Recalculate" />
06       <jpg_image size="Custom" width="800" height="600" resizing_mode="Recalculate" />
07       <pdf size="Custom" width="800" height="600" resizing_mode="Recalculate" />
08       <interactive_pdf size="Custom" width="800" height="600" resizing_mode="Recalculate" />
09     </export_settings>
10   </utils>
11 </stock>
01{
02  utils: {
03    exportSettings: {
04      pngImage: {
05        size: "Custom",
06        width: 800,
07        height: 600,
08        resizingMode: "Recalculate"
09      },
10      jpgImage: {
11        size: "Custom",
12        width: 800,
13        height: 600,
14        resizingMode: "Recalculate"
15      },
16      pdf: {
17        size: "Custom",
18        width: 800,
19        height: 600,
20        resizingMode: "Recalculate"
21      },
22      interactivePdf: {
23        size: "Custom",
24        width: 800,
25        height: 600,
26        resizingMode: "Recalculate"
27      }
28    }
29  }
30}

Here is a live sample that demonstrates the functioning of the Recalculate mode: Open the sample, resize the window as required and then save the chart to any format using the context menu or the toolbar under the chart:

Live Sample:  Export - Using Custom Size with Recalculate Mode

to top

Resizing Mode: Stretch

In the Stretch mode, the chart, obtaining a new width and height, stretches all the elements, maintaining their original geometrical shape. For example, if the original chart height was 400 pixels, and the exported chart height was 800 pixels, provided that the exported chart width is identical to the original one - after exporting the chart becomes two times higher, and all the elements on it are stretched vertically, yet maintaining their original dimensions horizontally.

Here is a set of illustrations demonstrating the behavior of a chart when exporting in the Stretch resizing mode using different input image dimensions (click on the thumbnails to view the illustrations in full size):

Original Exported: 1280x960 Exported: 350x250

Here is a sample syntax for enabling this mode for all the exported file types:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <utils>
04     <export_settings>
05       <png_image size="Custom" width="800" height="600" resizing_mode="Stretch" />
06       <jpg_image size="Custom" width="800" height="600" resizing_mode="Stretch" />
07       <pdf size="Custom" width="800" height="600" resizing_mode="Stretch" />
08       <interactive_pdf size="Custom" width="800" height="600" resizing_mode="Stretch" />
09     </export_settings>
10   </utils>
11 </stock>
01{
02  utils: {
03    exportSettings: {
04      pngImage: {
05        size: "Custom",
06        width: 800,
07        height: 600,
08        resizingMode: "Stretch"
09      },
10      jpgImage: {
11        size: "Custom",
12        width: 800,
13        height: 600,
14        resizingMode: "Stretch"
15      },
16      pdf: {
17        size: "Custom",
18        width: 800,
19        height: 600,
20        resizingMode: "Stretch"
21      },
22      interactivePdf: {
23        size: "Custom",
24        width: 800,
25        height: 600,
26        resizingMode: "Stretch"
27      }
28    }
29  }
30}

Here is a live sample that demonstrates the functioning of the Stretch mode: Open the sample, resize the window as required and then save the chart to any format using the context menu or the toolbar under the chart:

Live Sample:  Export - Using Custom Size with Stretch Mode

to top

Resizing Mode: Fit

When exporting in the Fit mode, the chart embeds into the exported image or PDF document with specified custom width and height. In such case, the only thing that changes is the scale of the chart elements - upwards or downwards against the original chart size.

Here is a set of illustrations demonstrating the behavior of a chart when exporting in the Fit resizing mode using different input image dimensions (click on the thumbnails to view the illustrations in full size):

Original Exported: 1280x960 Exported: 350x250

Here is a sample syntax for enabling this mode for all the exported file types:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <utils>
04     <export_settings>
05       <png_image size="Custom" width="800" height="600" resizing_mode="Fit" />
06       <jpg_image size="Custom" width="800" height="600" resizing_mode="Fit" />
07       <pdf size="Custom" width="800" height="600" resizing_mode="Fit" />
08       <interactive_pdf size="Custom" width="800" height="600" resizing_mode="Fit" />
09     </export_settings>
10   </utils>
11 </stock>
01{
02  utils: {
03    exportSettings: {
04      pngImage: {
05        size: "Custom",
06        width: 800,
07        height: 600,
08        resizingMode: "Fit"
09      },
10      jpgImage: {
11        size: "Custom",
12        width: 800,
13        height: 600,
14        resizingMode: "Fit"
15      },
16      pdf: {
17        size: "Custom",
18        width: 800,
19        height: 600,
20        resizingMode: "Fit"
21      },
22      interactivePdf: {
23        size: "Custom",
24        width: 800,
25        height: 600,
26        resizingMode: "Fit"
27      }
28    }
29  }
30}

Here is a live sample that demonstrates the functioning of the Fit mode: Open the sample, resize the window as required and then save the chart to any format using the context menu or the toolbar under the chart:

Live Sample:  Export - Using Custom Size with Fit Mode

When using the Fit mode, if the original chart size and the exported chart size are disproportional - the chart will be embedded by the bounds of the exported image, and the vertical or horizontal sides will have blank areas filled with the background color. These areas can be cropped automatically. To find out how to do that, please refer to the Using the cut_extra_space Attribute section.

to top

Resizing Mode: RecalculateByProportions

The RecalculateByProportions mode is a sort of a combination of the two modes: Recalculate and Fit. The chart is embedded by the bounds of the new width and height; at the same time, it is not scaled - instead, it is recalculated using the absolute coordinates.

Here is a set of illustrations demonstrating the behavior of a chart when exporting in the RecalculateByProportions resizing mode using different input image dimensions (click on the thumbnails to view the illustrations in full size):

Original Exported: 1280x960 Exported: 350x250

Here is a sample syntax for enabling this mode for all the exported file types:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <utils>
04     <export_settings>
05       <png_image size="Custom" width="800" height="600" resizing_mode="RecalculateByProportions" />
06       <jpg_image size="Custom" width="800" height="600" resizing_mode="RecalculateByProportions" />
07       <pdf size="Custom" width="800" height="600" resizing_mode="RecalculateByProportions" />
08       <interactive_pdf size="Custom" width="800" height="600" resizing_mode="RecalculateByProportions" />
09     </export_settings>
10   </utils>
11 </stock>
01{
02  utils: {
03    exportSettings: {
04      pngImage: {
05        size: "Custom",
06        width: 800,
07        height: 600,
08        resizingMode: "RecalculateByProportions"
09      },
10      jpgImage: {
11        size: "Custom",
12        width: 800,
13        height: 600,
14        resizingMode: "RecalculateByProportions"
15      },
16      pdf: {
17        size: "Custom",
18        width: 800,
19        height: 600,
20        resizingMode: "RecalculateByProportions"
21      },
22      interactivePdf: {
23        size: "Custom",
24        width: 800,
25        height: 600,
26        resizingMode: "RecalculateByProportions"
27      }
28    }
29  }
30}

Here is a live sample that demonstrates the functioning of the RecalculateByProportions mode: Open the sample, resize the window as required and then save the chart to any format using the context menu or the toolbar under the chart:

Live Sample:  Export - Using Custom Size with RecalculateByProportions Mode

When using the RecalculateByProportions mode, if the original chart size and the exported chart size are disproportional - the chart will be embedded by the bounds of the exported image, and the vertical or horizontal sides will have blank areas filled with the background color. These areas can be cropped automatically. To find out how to do that, please refer to the Using the cut_extra_space Attribute section.

to top

Resizing Mode: Combined (Interactive PDF format only)

Combined Mode can also have fixed width set, though it is intended for use with unknown variable width and height.

Syntax:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <utils>
04     <export_settings>
05       <interactive_pdf size="Custom" width="800" height="600" resizing_mode="Combined" />
06     </export_settings>
07   </utils>
08 </stock>
01{
02  utils: {
03    exportSettings: {
04      interactivePdf: {
05        size: "Custom",
06        width: 800,
07        height: 600,
08        resizingMode: "Combined"
09      }
10    }
11  }
12}

to top

Using the "cut_extra_space" Attribute

When using the RecalculateByProportions or Fit modes, if the original chart size and the exported chart size are disproportional - the chart will be embedded by the bounds of the exported image, and the vertical or horizontal sides will have blank areas filled with the background color. These areas can be cropped automatically.

To enable cropping blank areas automatically, set the cut_extra_space attribute to true in the node for the respective format.

Illustrations below show how the exported chart looks like with and without extra space:

Original Exported: 500x500
with extra space
Exported:500x500
extra space cut

Here is a sample syntax for enabling this option for all the exported formats:

XML/JSON Syntax
Plain code
01 <?xml version="1.0" encoding="UTF-8"?>
02 <stock xmlns="http://anychart.com/products/stock/schemas/1.9.0/schema.xsd">
03   <utils>
04     <export_settings>
05       <png_image size="Custom" width="500" height="500" resizing_mode="Fit" cut_extra_space="true" />
06       <jpg_image size="Custom" width="500" height="500" resizing_mode="Fit" cut_extra_space="true" />
07       <pdf size="Custom" width="800" height="600" resizing_mode="Fit" cut_extra_space="true" />
08     </export_settings>
09   </utils>
10 </stock>
01{
02  utils: {
03    exportSettings: {
04      pngImage: {
05        size: "Custom",
06        width: 500,
07        height: 500,
08        resizingMode: "Fit",
09        cutExtraSpace: true
10      },
11      jpgImage: {
12        size: "Custom",
13        width: 500,
14        height: 500,
15        resizingMode: "Fit",
16        cutExtraSpace: true
17      },
18      pdf: {
19        size: "Custom",
20        width: 800,
21        height: 600,
22        resizingMode: "Fit",
23        cutExtraSpace: true
24      }
25    }
26  }
27}

to top