123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- /**
- * This is a sample chart export config file. It is provided as a reference on
- * how miscelaneous items in export menu can be used and set up.
- *
- * Please refer to README.md for more information.
- */
- /**
- * PDF-specfic configuration
- */
- AmCharts.exportDrawingMenu = [ {
- class: "export-drawing",
- label: "Export",
- menu: [ {
- label: "Undo",
- click: function() {
- this.drawing.undo();
- }
- }, {
- label: "Redo",
- click: function() {
- this.drawing.redo();
- }
- }, {
- label: "Cancel",
- click: function() {
- this.drawing.done();
- }
- }, {
- label: "Save",
- menu: [ {
- label: "JPG",
- click: function() {
- this.drawing.done();
- this.toJPG( {}, function( data ) {
- this.download( data, "image/jpg", "amCharts.jpg" );
- } );
- }
- }, {
- label: "PNG",
- click: function() {
- this.drawing.done();
- this.toPNG( {}, function( data ) {
- this.download( data, "image/png", "amCharts.png" );
- } );
- }
- }, {
- label: "PDF",
- click: function() {
- this.drawing.done();
- this.toPDF( {}, function( data ) {
- this.download( data, "application/pdf", "amCharts.pdf" );
- } );
- }
- }, {
- label: "SVG",
- click: function() {
- this.drawing.done();
- this.toSVG( {}, function( data ) {
- this.download( data, "text/xml", "amCharts.svg" );
- } );
- }
- } ]
- } ]
- } ];
- /**
- * Define main universal config
- */
- AmCharts.exportCFG = {
- enabled: true,
- libs: {
- path: "../libs/"
- },
- menu: [ {
- class: "export-main",
- label: "Export",
- menu: [
- /*
- ** DRAWING
- */
- {
- label: "Draw",
- click: function() {
- this.capture( {
- action: "draw",
- freeDrawingBrush: {
- width: 2,
- color: "#000000",
- shadow: {
- color: "rgba(0,0,0,0.3)",
- blur: 10,
- offsetX: 3,
- offsetY: 3
- }
- }
- }, function() {
- this.createMenu( AmCharts.exportDrawingMenu );
- } );
- }
- },
- /*
- ** DELAYED EXPORT
- */
- {
- label: "Delayed",
- click: function() {
- var _this = this;
- var delay = 2;
- var timer = 0;
- var starttime = Number( new Date() );
- var menu = this.createMenu( [ {
- label: "Capturing: " + delay,
- click: function() {
- clearTimeout( timer );
- this.createMenu( this.defaults.menu );
- }
- } ] );
- var label = menu.getElementsByTagName( "span" )[ 0 ];
- timer = setInterval( function() {
- diff = ( delay - ( Number( new Date() ) - starttime ) / 1000 );
- label.innerHTML = "Capturing: " + ( diff < 0 ? 0 : diff ).toFixed( 2 );
- if ( diff <= 0 ) {
- clearTimeout( timer );
- _this.capture( {}, function() {
- this.toJPG( {}, function( data ) {
- this.download( data, "image/jpg", "amCharts.jpg" );
- } );
- this.createMenu( this.defaults.menu );
- } );
- }
- }, 10 );
- }
- },
- /*
- ** DELAYED EXPORT WITH DRAWING
- */
- {
- label: "Delayed Draw",
- click: function() {
- var _this = this;
- var delay = 2;
- var timer = 0;
- var starttime = Number( new Date() );
- var menu = this.createMenu( [ {
- label: "Capturing: " + delay,
- click: function() {
- clearTimeout( timer );
- this.createMenu( this.defaults.menu );
- }
- } ] );
- var label = menu.getElementsByTagName( "span" )[ 0 ];
- timer = setInterval( function() {
- var diff = ( delay - ( Number( new Date() ) - starttime ) / 1000 );
- label.innerHTML = "Capturing: " + ( diff < 0 ? 0 : diff ).toFixed( 2 );
- if ( diff <= 0 ) {
- clearTimeout( timer );
- _this.capture( {
- action: "draw"
- }, function() {
- _this.createMenu( AmCharts.exportDrawingMenu );
- } );
- }
- }, 10 );
- }
- },
- /*
- ** DOWNLOAD
- */
- {
- label: "Download",
- menu: [ {
- label: "JPG",
- click: function() {
- this.capture( {}, function() {
- this.toJPG( {}, function( data ) {
- this.download( data, "image/jpg", "amCharts.jpg" );
- } );
- } );
- }
- }, {
- label: "PNG",
- click: function() {
- this.capture( {}, function() {
- this.toPNG( {}, function( data ) {
- this.download( data, "image/png", "amCharts.png" );
- } );
- } );
- }
- }, {
- label: "PDF",
- click: function() {
- this.capture( {}, function() {
- this.toPDF( {}, function( data ) {
- this.download( data, "application/pdf", "amCharts.pdf" );
- } );
- } );
- }
- }, {
- label: "PDF + data",
- click: function() {
- this.capture( {}, function() {
- var tableData = this.setup.chart.dataProvider;
- var tableBody = this.toArray( {
- withHeader: true,
- data: tableData
- } );
- var tableWidths = [];
- var content = [ {
- image: "reference",
- fit: [ 523.28, 769.89 ]
- } ];
- for ( i in tableBody[ 0 ] ) {
- tableWidths.push( "*" );
- }
- content.push( {
- table: {
- headerRows: 1,
- widths: tableWidths,
- body: tableBody
- },
- layout: 'lightHorizontalLines'
- } );
- this.toPDF( {
- content: content
- }, function( data ) {
- this.download( data, "application/pdf", "amCharts.pdf" );
- } );
- } );
- }
- }, {
- label: "SVG",
- click: function() {
- this.capture( {}, function() {
- this.toSVG( {}, function( data ) {
- this.download( data, "text/xml", "amCharts.svg" );
- } );
- } );
- }
- }, {
- label: "CSV",
- click: function() {
- this.toCSV( {}, function( data ) {
- this.download( data, "text/plain", "amCharts.csv" );
- } );
- }
- }, {
- label: "JSON",
- click: function() {
- this.toJSON( {}, function( data ) {
- this.download( data, "text/plain", "amCharts.json" );
- } );
- }
- }, {
- label: "XLSX",
- click: function() {
- this.toXLSX( {}, function( data ) {
- this.download( data, "application/octet-stream", "amCharts.xlsx" );
- } );
- }
- } ]
- }
- ]
- } ]
- };
|