export.config.advanced.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /**
  2. * This is a sample chart export config file. It is provided as a reference on
  3. * how miscelaneous items in export menu can be used and set up.
  4. *
  5. * Please refer to README.md for more information.
  6. */
  7. /**
  8. * PDF-specfic configuration
  9. */
  10. AmCharts.exportDrawingMenu = [ {
  11. class: "export-drawing",
  12. label: "Export",
  13. menu: [ {
  14. label: "Undo",
  15. click: function() {
  16. this.drawing.undo();
  17. }
  18. }, {
  19. label: "Redo",
  20. click: function() {
  21. this.drawing.redo();
  22. }
  23. }, {
  24. label: "Cancel",
  25. click: function() {
  26. this.drawing.done();
  27. }
  28. }, {
  29. label: "Save",
  30. menu: [ {
  31. label: "JPG",
  32. click: function() {
  33. this.drawing.done();
  34. this.toJPG( {}, function( data ) {
  35. this.download( data, "image/jpg", "amCharts.jpg" );
  36. } );
  37. }
  38. }, {
  39. label: "PNG",
  40. click: function() {
  41. this.drawing.done();
  42. this.toPNG( {}, function( data ) {
  43. this.download( data, "image/png", "amCharts.png" );
  44. } );
  45. }
  46. }, {
  47. label: "PDF",
  48. click: function() {
  49. this.drawing.done();
  50. this.toPDF( {}, function( data ) {
  51. this.download( data, "application/pdf", "amCharts.pdf" );
  52. } );
  53. }
  54. }, {
  55. label: "SVG",
  56. click: function() {
  57. this.drawing.done();
  58. this.toSVG( {}, function( data ) {
  59. this.download( data, "text/xml", "amCharts.svg" );
  60. } );
  61. }
  62. } ]
  63. } ]
  64. } ];
  65. /**
  66. * Define main universal config
  67. */
  68. AmCharts.exportCFG = {
  69. enabled: true,
  70. libs: {
  71. path: "../libs/"
  72. },
  73. menu: [ {
  74. class: "export-main",
  75. label: "Export",
  76. menu: [
  77. /*
  78. ** DRAWING
  79. */
  80. {
  81. label: "Draw",
  82. click: function() {
  83. this.capture( {
  84. action: "draw",
  85. freeDrawingBrush: {
  86. width: 2,
  87. color: "#000000",
  88. shadow: {
  89. color: "rgba(0,0,0,0.3)",
  90. blur: 10,
  91. offsetX: 3,
  92. offsetY: 3
  93. }
  94. }
  95. }, function() {
  96. this.createMenu( AmCharts.exportDrawingMenu );
  97. } );
  98. }
  99. },
  100. /*
  101. ** DELAYED EXPORT
  102. */
  103. {
  104. label: "Delayed",
  105. click: function() {
  106. var _this = this;
  107. var delay = 2;
  108. var timer = 0;
  109. var starttime = Number( new Date() );
  110. var menu = this.createMenu( [ {
  111. label: "Capturing: " + delay,
  112. click: function() {
  113. clearTimeout( timer );
  114. this.createMenu( this.defaults.menu );
  115. }
  116. } ] );
  117. var label = menu.getElementsByTagName( "span" )[ 0 ];
  118. timer = setInterval( function() {
  119. diff = ( delay - ( Number( new Date() ) - starttime ) / 1000 );
  120. label.innerHTML = "Capturing: " + ( diff < 0 ? 0 : diff ).toFixed( 2 );
  121. if ( diff <= 0 ) {
  122. clearTimeout( timer );
  123. _this.capture( {}, function() {
  124. this.toJPG( {}, function( data ) {
  125. this.download( data, "image/jpg", "amCharts.jpg" );
  126. } );
  127. this.createMenu( this.defaults.menu );
  128. } );
  129. }
  130. }, 10 );
  131. }
  132. },
  133. /*
  134. ** DELAYED EXPORT WITH DRAWING
  135. */
  136. {
  137. label: "Delayed Draw",
  138. click: function() {
  139. var _this = this;
  140. var delay = 2;
  141. var timer = 0;
  142. var starttime = Number( new Date() );
  143. var menu = this.createMenu( [ {
  144. label: "Capturing: " + delay,
  145. click: function() {
  146. clearTimeout( timer );
  147. this.createMenu( this.defaults.menu );
  148. }
  149. } ] );
  150. var label = menu.getElementsByTagName( "span" )[ 0 ];
  151. timer = setInterval( function() {
  152. var diff = ( delay - ( Number( new Date() ) - starttime ) / 1000 );
  153. label.innerHTML = "Capturing: " + ( diff < 0 ? 0 : diff ).toFixed( 2 );
  154. if ( diff <= 0 ) {
  155. clearTimeout( timer );
  156. _this.capture( {
  157. action: "draw"
  158. }, function() {
  159. _this.createMenu( AmCharts.exportDrawingMenu );
  160. } );
  161. }
  162. }, 10 );
  163. }
  164. },
  165. /*
  166. ** DOWNLOAD
  167. */
  168. {
  169. label: "Download",
  170. menu: [ {
  171. label: "JPG",
  172. click: function() {
  173. this.capture( {}, function() {
  174. this.toJPG( {}, function( data ) {
  175. this.download( data, "image/jpg", "amCharts.jpg" );
  176. } );
  177. } );
  178. }
  179. }, {
  180. label: "PNG",
  181. click: function() {
  182. this.capture( {}, function() {
  183. this.toPNG( {}, function( data ) {
  184. this.download( data, "image/png", "amCharts.png" );
  185. } );
  186. } );
  187. }
  188. }, {
  189. label: "PDF",
  190. click: function() {
  191. this.capture( {}, function() {
  192. this.toPDF( {}, function( data ) {
  193. this.download( data, "application/pdf", "amCharts.pdf" );
  194. } );
  195. } );
  196. }
  197. }, {
  198. label: "PDF + data",
  199. click: function() {
  200. this.capture( {}, function() {
  201. var tableData = this.setup.chart.dataProvider;
  202. var tableBody = this.toArray( {
  203. withHeader: true,
  204. data: tableData
  205. } );
  206. var tableWidths = [];
  207. var content = [ {
  208. image: "reference",
  209. fit: [ 523.28, 769.89 ]
  210. } ];
  211. for ( i in tableBody[ 0 ] ) {
  212. tableWidths.push( "*" );
  213. }
  214. content.push( {
  215. table: {
  216. headerRows: 1,
  217. widths: tableWidths,
  218. body: tableBody
  219. },
  220. layout: 'lightHorizontalLines'
  221. } );
  222. this.toPDF( {
  223. content: content
  224. }, function( data ) {
  225. this.download( data, "application/pdf", "amCharts.pdf" );
  226. } );
  227. } );
  228. }
  229. }, {
  230. label: "SVG",
  231. click: function() {
  232. this.capture( {}, function() {
  233. this.toSVG( {}, function( data ) {
  234. this.download( data, "text/xml", "amCharts.svg" );
  235. } );
  236. } );
  237. }
  238. }, {
  239. label: "CSV",
  240. click: function() {
  241. this.toCSV( {}, function( data ) {
  242. this.download( data, "text/plain", "amCharts.csv" );
  243. } );
  244. }
  245. }, {
  246. label: "JSON",
  247. click: function() {
  248. this.toJSON( {}, function( data ) {
  249. this.download( data, "text/plain", "amCharts.json" );
  250. } );
  251. }
  252. }, {
  253. label: "XLSX",
  254. click: function() {
  255. this.toXLSX( {}, function( data ) {
  256. this.download( data, "application/octet-stream", "amCharts.xlsx" );
  257. } );
  258. }
  259. } ]
  260. }
  261. ]
  262. } ]
  263. };