chart.go 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693
  1. // Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of
  2. // this source code is governed by a BSD-style license that can be found in
  3. // the LICENSE file.
  4. //
  5. // Package excelize providing a set of functions that allow you to write to
  6. // and read from XLSX files. Support reads and writes XLSX file generated by
  7. // Microsoft Excel™ 2007 and later. Support save file without losing original
  8. // charts of XLSX. This library needs Go version 1.8 or later.
  9. package excelize
  10. import (
  11. "encoding/json"
  12. "encoding/xml"
  13. "errors"
  14. "strconv"
  15. "strings"
  16. )
  17. // This section defines the currently supported chart types.
  18. const (
  19. Area = "area"
  20. AreaStacked = "areaStacked"
  21. AreaPercentStacked = "areaPercentStacked"
  22. Area3D = "area3D"
  23. Area3DStacked = "area3DStacked"
  24. Area3DPercentStacked = "area3DPercentStacked"
  25. Bar = "bar"
  26. BarStacked = "barStacked"
  27. BarPercentStacked = "barPercentStacked"
  28. Bar3DClustered = "bar3DClustered"
  29. Bar3DStacked = "bar3DStacked"
  30. Bar3DPercentStacked = "bar3DPercentStacked"
  31. Bar3DConeClustered = "bar3DConeClustered"
  32. Bar3DConeStacked = "bar3DConeStacked"
  33. Bar3DConePercentStacked = "bar3DConePercentStacked"
  34. Bar3DPyramidClustered = "bar3DPyramidClustered"
  35. Bar3DPyramidStacked = "bar3DPyramidStacked"
  36. Bar3DPyramidPercentStacked = "bar3DPyramidPercentStacked"
  37. Bar3DCylinderClustered = "bar3DCylinderClustered"
  38. Bar3DCylinderStacked = "bar3DCylinderStacked"
  39. Bar3DCylinderPercentStacked = "bar3DCylinderPercentStacked"
  40. Col = "col"
  41. ColStacked = "colStacked"
  42. ColPercentStacked = "colPercentStacked"
  43. Col3D = "col3D"
  44. Col3DClustered = "col3DClustered"
  45. Col3DStacked = "col3DStacked"
  46. Col3DPercentStacked = "col3DPercentStacked"
  47. Col3DCone = "col3DCone"
  48. Col3DConeClustered = "col3DConeClustered"
  49. Col3DConeStacked = "col3DConeStacked"
  50. Col3DConePercentStacked = "col3DConePercentStacked"
  51. Col3DPyramid = "col3DPyramid"
  52. Col3DPyramidClustered = "col3DPyramidClustered"
  53. Col3DPyramidStacked = "col3DPyramidStacked"
  54. Col3DPyramidPercentStacked = "col3DPyramidPercentStacked"
  55. Col3DCylinder = "col3DCylinder"
  56. Col3DCylinderClustered = "col3DCylinderClustered"
  57. Col3DCylinderStacked = "col3DCylinderStacked"
  58. Col3DCylinderPercentStacked = "col3DCylinderPercentStacked"
  59. Doughnut = "doughnut"
  60. Line = "line"
  61. Pie = "pie"
  62. Pie3D = "pie3D"
  63. Radar = "radar"
  64. Scatter = "scatter"
  65. )
  66. // This section defines the default value of chart properties.
  67. var (
  68. chartView3DRotX = map[string]int{
  69. Area: 0,
  70. AreaStacked: 0,
  71. AreaPercentStacked: 0,
  72. Area3D: 15,
  73. Area3DStacked: 15,
  74. Area3DPercentStacked: 15,
  75. Bar: 0,
  76. BarStacked: 0,
  77. BarPercentStacked: 0,
  78. Bar3DClustered: 15,
  79. Bar3DStacked: 15,
  80. Bar3DPercentStacked: 15,
  81. Bar3DConeClustered: 15,
  82. Bar3DConeStacked: 15,
  83. Bar3DConePercentStacked: 15,
  84. Bar3DPyramidClustered: 15,
  85. Bar3DPyramidStacked: 15,
  86. Bar3DPyramidPercentStacked: 15,
  87. Bar3DCylinderClustered: 15,
  88. Bar3DCylinderStacked: 15,
  89. Bar3DCylinderPercentStacked: 15,
  90. Col: 0,
  91. ColStacked: 0,
  92. ColPercentStacked: 0,
  93. Col3D: 15,
  94. Col3DClustered: 15,
  95. Col3DStacked: 15,
  96. Col3DPercentStacked: 15,
  97. Col3DCone: 15,
  98. Col3DConeClustered: 15,
  99. Col3DConeStacked: 15,
  100. Col3DConePercentStacked: 15,
  101. Col3DPyramid: 15,
  102. Col3DPyramidClustered: 15,
  103. Col3DPyramidStacked: 15,
  104. Col3DPyramidPercentStacked: 15,
  105. Col3DCylinder: 15,
  106. Col3DCylinderClustered: 15,
  107. Col3DCylinderStacked: 15,
  108. Col3DCylinderPercentStacked: 15,
  109. Doughnut: 0,
  110. Line: 0,
  111. Pie: 0,
  112. Pie3D: 30,
  113. Radar: 0,
  114. Scatter: 0,
  115. }
  116. chartView3DRotY = map[string]int{
  117. Area: 0,
  118. AreaStacked: 0,
  119. AreaPercentStacked: 0,
  120. Area3D: 20,
  121. Area3DStacked: 20,
  122. Area3DPercentStacked: 20,
  123. Bar: 0,
  124. BarStacked: 0,
  125. BarPercentStacked: 0,
  126. Bar3DClustered: 20,
  127. Bar3DStacked: 20,
  128. Bar3DPercentStacked: 20,
  129. Bar3DConeClustered: 20,
  130. Bar3DConeStacked: 20,
  131. Bar3DConePercentStacked: 20,
  132. Bar3DPyramidClustered: 20,
  133. Bar3DPyramidStacked: 20,
  134. Bar3DPyramidPercentStacked: 20,
  135. Bar3DCylinderClustered: 20,
  136. Bar3DCylinderStacked: 20,
  137. Bar3DCylinderPercentStacked: 20,
  138. Col: 0,
  139. ColStacked: 0,
  140. ColPercentStacked: 0,
  141. Col3D: 20,
  142. Col3DClustered: 20,
  143. Col3DStacked: 20,
  144. Col3DPercentStacked: 20,
  145. Col3DCone: 20,
  146. Col3DConeClustered: 20,
  147. Col3DConeStacked: 20,
  148. Col3DConePercentStacked: 20,
  149. Col3DPyramid: 20,
  150. Col3DPyramidClustered: 20,
  151. Col3DPyramidStacked: 20,
  152. Col3DPyramidPercentStacked: 20,
  153. Col3DCylinder: 20,
  154. Col3DCylinderClustered: 20,
  155. Col3DCylinderStacked: 20,
  156. Col3DCylinderPercentStacked: 20,
  157. Doughnut: 0,
  158. Line: 0,
  159. Pie: 0,
  160. Pie3D: 0,
  161. Radar: 0,
  162. Scatter: 0,
  163. }
  164. chartView3DDepthPercent = map[string]int{
  165. Area: 100,
  166. AreaStacked: 100,
  167. AreaPercentStacked: 100,
  168. Area3D: 100,
  169. Area3DStacked: 100,
  170. Area3DPercentStacked: 100,
  171. Bar: 100,
  172. BarStacked: 100,
  173. BarPercentStacked: 100,
  174. Bar3DClustered: 100,
  175. Bar3DStacked: 100,
  176. Bar3DPercentStacked: 100,
  177. Bar3DConeClustered: 100,
  178. Bar3DConeStacked: 100,
  179. Bar3DConePercentStacked: 100,
  180. Bar3DPyramidClustered: 100,
  181. Bar3DPyramidStacked: 100,
  182. Bar3DPyramidPercentStacked: 100,
  183. Bar3DCylinderClustered: 100,
  184. Bar3DCylinderStacked: 100,
  185. Bar3DCylinderPercentStacked: 100,
  186. Col: 100,
  187. ColStacked: 100,
  188. ColPercentStacked: 100,
  189. Col3D: 100,
  190. Col3DClustered: 100,
  191. Col3DStacked: 100,
  192. Col3DPercentStacked: 100,
  193. Col3DCone: 100,
  194. Col3DConeClustered: 100,
  195. Col3DConeStacked: 100,
  196. Col3DConePercentStacked: 100,
  197. Col3DPyramid: 100,
  198. Col3DPyramidClustered: 100,
  199. Col3DPyramidStacked: 100,
  200. Col3DPyramidPercentStacked: 100,
  201. Col3DCylinder: 100,
  202. Col3DCylinderClustered: 100,
  203. Col3DCylinderStacked: 100,
  204. Col3DCylinderPercentStacked: 100,
  205. Doughnut: 100,
  206. Line: 100,
  207. Pie: 100,
  208. Pie3D: 100,
  209. Radar: 100,
  210. Scatter: 100,
  211. }
  212. chartView3DRAngAx = map[string]int{
  213. Area: 0,
  214. AreaStacked: 0,
  215. AreaPercentStacked: 0,
  216. Area3D: 1,
  217. Area3DStacked: 1,
  218. Area3DPercentStacked: 1,
  219. Bar: 0,
  220. BarStacked: 0,
  221. BarPercentStacked: 0,
  222. Bar3DClustered: 1,
  223. Bar3DStacked: 1,
  224. Bar3DPercentStacked: 1,
  225. Bar3DConeClustered: 1,
  226. Bar3DConeStacked: 1,
  227. Bar3DConePercentStacked: 1,
  228. Bar3DPyramidClustered: 1,
  229. Bar3DPyramidStacked: 1,
  230. Bar3DPyramidPercentStacked: 1,
  231. Bar3DCylinderClustered: 1,
  232. Bar3DCylinderStacked: 1,
  233. Bar3DCylinderPercentStacked: 1,
  234. Col: 0,
  235. ColStacked: 0,
  236. ColPercentStacked: 0,
  237. Col3D: 1,
  238. Col3DClustered: 1,
  239. Col3DStacked: 1,
  240. Col3DPercentStacked: 1,
  241. Col3DCone: 1,
  242. Col3DConeClustered: 1,
  243. Col3DConeStacked: 1,
  244. Col3DConePercentStacked: 1,
  245. Col3DPyramid: 1,
  246. Col3DPyramidClustered: 1,
  247. Col3DPyramidStacked: 1,
  248. Col3DPyramidPercentStacked: 1,
  249. Col3DCylinder: 1,
  250. Col3DCylinderClustered: 1,
  251. Col3DCylinderStacked: 1,
  252. Col3DCylinderPercentStacked: 1,
  253. Doughnut: 0,
  254. Line: 0,
  255. Pie: 0,
  256. Pie3D: 0,
  257. Radar: 0,
  258. Scatter: 0,
  259. }
  260. chartLegendPosition = map[string]string{
  261. "bottom": "b",
  262. "left": "l",
  263. "right": "r",
  264. "top": "t",
  265. "top_right": "tr",
  266. }
  267. chartValAxNumFmtFormatCode = map[string]string{
  268. Area: "General",
  269. AreaStacked: "General",
  270. AreaPercentStacked: "0%",
  271. Area3D: "General",
  272. Area3DStacked: "General",
  273. Area3DPercentStacked: "0%",
  274. Bar: "General",
  275. BarStacked: "General",
  276. BarPercentStacked: "0%",
  277. Bar3DClustered: "General",
  278. Bar3DStacked: "General",
  279. Bar3DPercentStacked: "0%",
  280. Bar3DConeClustered: "General",
  281. Bar3DConeStacked: "General",
  282. Bar3DConePercentStacked: "0%",
  283. Bar3DPyramidClustered: "General",
  284. Bar3DPyramidStacked: "General",
  285. Bar3DPyramidPercentStacked: "0%",
  286. Bar3DCylinderClustered: "General",
  287. Bar3DCylinderStacked: "General",
  288. Bar3DCylinderPercentStacked: "0%",
  289. Col: "General",
  290. ColStacked: "General",
  291. ColPercentStacked: "0%",
  292. Col3D: "General",
  293. Col3DClustered: "General",
  294. Col3DStacked: "General",
  295. Col3DPercentStacked: "0%",
  296. Col3DCone: "General",
  297. Col3DConeClustered: "General",
  298. Col3DConeStacked: "General",
  299. Col3DConePercentStacked: "0%",
  300. Col3DPyramid: "General",
  301. Col3DPyramidClustered: "General",
  302. Col3DPyramidStacked: "General",
  303. Col3DPyramidPercentStacked: "0%",
  304. Col3DCylinder: "General",
  305. Col3DCylinderClustered: "General",
  306. Col3DCylinderStacked: "General",
  307. Col3DCylinderPercentStacked: "0%",
  308. Doughnut: "General",
  309. Line: "General",
  310. Pie: "General",
  311. Pie3D: "General",
  312. Radar: "General",
  313. Scatter: "General",
  314. }
  315. chartValAxCrossBetween = map[string]string{
  316. Area: "midCat",
  317. AreaStacked: "midCat",
  318. AreaPercentStacked: "midCat",
  319. Area3D: "midCat",
  320. Area3DStacked: "midCat",
  321. Area3DPercentStacked: "midCat",
  322. Bar: "between",
  323. BarStacked: "between",
  324. BarPercentStacked: "between",
  325. Bar3DClustered: "between",
  326. Bar3DStacked: "between",
  327. Bar3DPercentStacked: "between",
  328. Bar3DConeClustered: "between",
  329. Bar3DConeStacked: "between",
  330. Bar3DConePercentStacked: "between",
  331. Bar3DPyramidClustered: "between",
  332. Bar3DPyramidStacked: "between",
  333. Bar3DPyramidPercentStacked: "between",
  334. Bar3DCylinderClustered: "between",
  335. Bar3DCylinderStacked: "between",
  336. Bar3DCylinderPercentStacked: "between",
  337. Col: "between",
  338. ColStacked: "between",
  339. ColPercentStacked: "between",
  340. Col3D: "between",
  341. Col3DClustered: "between",
  342. Col3DStacked: "between",
  343. Col3DPercentStacked: "between",
  344. Col3DCone: "between",
  345. Col3DConeClustered: "between",
  346. Col3DConeStacked: "between",
  347. Col3DConePercentStacked: "between",
  348. Col3DPyramid: "between",
  349. Col3DPyramidClustered: "between",
  350. Col3DPyramidStacked: "between",
  351. Col3DPyramidPercentStacked: "between",
  352. Col3DCylinder: "between",
  353. Col3DCylinderClustered: "between",
  354. Col3DCylinderStacked: "between",
  355. Col3DCylinderPercentStacked: "between",
  356. Doughnut: "between",
  357. Line: "between",
  358. Pie: "between",
  359. Pie3D: "between",
  360. Radar: "between",
  361. Scatter: "between",
  362. }
  363. plotAreaChartGrouping = map[string]string{
  364. Area: "standard",
  365. AreaStacked: "stacked",
  366. AreaPercentStacked: "percentStacked",
  367. Area3D: "standard",
  368. Area3DStacked: "stacked",
  369. Area3DPercentStacked: "percentStacked",
  370. Bar: "clustered",
  371. BarStacked: "stacked",
  372. BarPercentStacked: "percentStacked",
  373. Bar3DClustered: "clustered",
  374. Bar3DStacked: "stacked",
  375. Bar3DPercentStacked: "percentStacked",
  376. Bar3DConeClustered: "clustered",
  377. Bar3DConeStacked: "stacked",
  378. Bar3DConePercentStacked: "percentStacked",
  379. Bar3DPyramidClustered: "clustered",
  380. Bar3DPyramidStacked: "stacked",
  381. Bar3DPyramidPercentStacked: "percentStacked",
  382. Bar3DCylinderClustered: "clustered",
  383. Bar3DCylinderStacked: "stacked",
  384. Bar3DCylinderPercentStacked: "percentStacked",
  385. Col: "clustered",
  386. ColStacked: "stacked",
  387. ColPercentStacked: "percentStacked",
  388. Col3D: "standard",
  389. Col3DClustered: "clustered",
  390. Col3DStacked: "stacked",
  391. Col3DPercentStacked: "percentStacked",
  392. Col3DCone: "standard",
  393. Col3DConeClustered: "clustered",
  394. Col3DConeStacked: "stacked",
  395. Col3DConePercentStacked: "percentStacked",
  396. Col3DPyramid: "standard",
  397. Col3DPyramidClustered: "clustered",
  398. Col3DPyramidStacked: "stacked",
  399. Col3DPyramidPercentStacked: "percentStacked",
  400. Col3DCylinder: "standard",
  401. Col3DCylinderClustered: "clustered",
  402. Col3DCylinderStacked: "stacked",
  403. Col3DCylinderPercentStacked: "percentStacked",
  404. Line: "standard",
  405. }
  406. plotAreaChartBarDir = map[string]string{
  407. Bar: "bar",
  408. BarStacked: "bar",
  409. BarPercentStacked: "bar",
  410. Bar3DClustered: "bar",
  411. Bar3DStacked: "bar",
  412. Bar3DPercentStacked: "bar",
  413. Bar3DConeClustered: "bar",
  414. Bar3DConeStacked: "bar",
  415. Bar3DConePercentStacked: "bar",
  416. Bar3DPyramidClustered: "bar",
  417. Bar3DPyramidStacked: "bar",
  418. Bar3DPyramidPercentStacked: "bar",
  419. Bar3DCylinderClustered: "bar",
  420. Bar3DCylinderStacked: "bar",
  421. Bar3DCylinderPercentStacked: "bar",
  422. Col: "col",
  423. ColStacked: "col",
  424. ColPercentStacked: "col",
  425. Col3D: "col",
  426. Col3DClustered: "col",
  427. Col3DStacked: "col",
  428. Col3DPercentStacked: "col",
  429. Col3DCone: "col",
  430. Col3DConeStacked: "col",
  431. Col3DConeClustered: "col",
  432. Col3DConePercentStacked: "col",
  433. Col3DPyramid: "col",
  434. Col3DPyramidClustered: "col",
  435. Col3DPyramidStacked: "col",
  436. Col3DPyramidPercentStacked: "col",
  437. Col3DCylinder: "col",
  438. Col3DCylinderClustered: "col",
  439. Col3DCylinderStacked: "col",
  440. Col3DCylinderPercentStacked: "col",
  441. Line: "standard",
  442. }
  443. orientation = map[bool]string{
  444. true: "maxMin",
  445. false: "minMax",
  446. }
  447. catAxPos = map[bool]string{
  448. true: "t",
  449. false: "b",
  450. }
  451. valAxPos = map[bool]string{
  452. true: "r",
  453. false: "l",
  454. }
  455. )
  456. // parseFormatChartSet provides a function to parse the format settings of the
  457. // chart with default value.
  458. func parseFormatChartSet(formatSet string) (*formatChart, error) {
  459. format := formatChart{
  460. Dimension: formatChartDimension{
  461. Width: 480,
  462. Height: 290,
  463. },
  464. Format: formatPicture{
  465. FPrintsWithSheet: true,
  466. FLocksWithSheet: false,
  467. NoChangeAspect: false,
  468. OffsetX: 0,
  469. OffsetY: 0,
  470. XScale: 1.0,
  471. YScale: 1.0,
  472. },
  473. Legend: formatChartLegend{
  474. Position: "bottom",
  475. ShowLegendKey: false,
  476. },
  477. Title: formatChartTitle{
  478. Name: " ",
  479. },
  480. ShowBlanksAs: "gap",
  481. }
  482. err := json.Unmarshal([]byte(formatSet), &format)
  483. return &format, err
  484. }
  485. // AddChart provides the method to add chart in a sheet by given chart format
  486. // set (such as offset, scale, aspect ratio setting and print settings) and
  487. // properties set. For example, create 3D clustered column chart with data
  488. // Sheet1!$A$29:$D$32:
  489. //
  490. // package main
  491. //
  492. // import (
  493. // "fmt"
  494. //
  495. // "github.com/360EntSecGroup-Skylar/excelize/v2"
  496. // )
  497. //
  498. // func main() {
  499. // categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
  500. // values := map[string]int{"B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8}
  501. // f := excelize.NewFile()
  502. // for k, v := range categories {
  503. // f.SetCellValue("Sheet1", k, v)
  504. // }
  505. // for k, v := range values {
  506. // f.SetCellValue("Sheet1", k, v)
  507. // }
  508. // err := f.AddChart("Sheet1", "E1", `{"type":"col3DClustered","dimension":{"width":640,"height":480},"series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"bottom","show_legend_key":false},"title":{"name":"Fruit 3D Clustered Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero","x_axis":{"reverse_order":true},"y_axis":{"maximum":7.5,"minimum":0.5}}`)
  509. // if err != nil {
  510. // fmt.Println(err)
  511. // return
  512. // }
  513. // // Save xlsx file by the given path.
  514. // err = xlsx.SaveAs("./Book1.xlsx")
  515. // if err != nil {
  516. // fmt.Println(err)
  517. // }
  518. // }
  519. //
  520. // The following shows the type of chart supported by excelize:
  521. //
  522. // Type | Chart
  523. // -----------------------------+------------------------------
  524. // area | 2D area chart
  525. // areaStacked | 2D stacked area chart
  526. // areaPercentStacked | 2D 100% stacked area chart
  527. // area3D | 3D area chart
  528. // area3DStacked | 3D stacked area chart
  529. // area3DPercentStacked | 3D 100% stacked area chart
  530. // bar | 2D clustered bar chart
  531. // barStacked | 2D stacked bar chart
  532. // barPercentStacked | 2D 100% stacked bar chart
  533. // bar3DClustered | 3D clustered bar chart
  534. // bar3DStacked | 3D stacked bar chart
  535. // bar3DPercentStacked | 3D 100% stacked bar chart
  536. // bar3DConeClustered | 3D cone clustered bar chart
  537. // bar3DConeStacked | 3D cone stacked bar chart
  538. // bar3DConePercentStacked | 3D cone percent bar chart
  539. // bar3DPyramidClustered | 3D pyramid clustered bar chart
  540. // bar3DPyramidStacked | 3D pyramid stacked bar chart
  541. // bar3DPyramidPercentStacked | 3D pyramid percent stacked bar chart
  542. // bar3DCylinderClustered | 3D cylinder clustered bar chart
  543. // bar3DCylinderStacked | 3D cylinder stacked bar chart
  544. // bar3DCylinderPercentStacked | 3D cylinder percent stacked bar chart
  545. // col | 2D clustered column chart
  546. // colStacked | 2D stacked column chart
  547. // colPercentStacked | 2D 100% stacked column chart
  548. // col3DClustered | 3D clustered column chart
  549. // col3D | 3D column chart
  550. // col3DStacked | 3D stacked column chart
  551. // col3DPercentStacked | 3D 100% stacked column chart
  552. // col3DCone | 3D cone column chart
  553. // col3DConeClustered | 3D cone clustered column chart
  554. // col3DConeStacked | 3D cone stacked column chart
  555. // col3DConePercentStacked | 3D cone percent stacked column chart
  556. // col3DPyramid | 3D pyramid column chart
  557. // col3DPyramidClustered | 3D pyramid clustered column chart
  558. // col3DPyramidStacked | 3D pyramid stacked column chart
  559. // col3DPyramidPercentStacked | 3D pyramid percent stacked column chart
  560. // col3DCylinder | 3D cylinder column chart
  561. // col3DCylinderClustered | 3D cylinder clustered column chart
  562. // col3DCylinderStacked | 3D cylinder stacked column chart
  563. // col3DCylinderPercentStacked | 3D cylinder percent stacked column chart
  564. // doughnut | doughnut chart
  565. // line | line chart
  566. // pie | pie chart
  567. // pie3D | 3D pie chart
  568. // radar | radar chart
  569. // scatter | scatter chart
  570. //
  571. // In Excel a chart series is a collection of information that defines which data is plotted such as values, axis labels and formatting.
  572. //
  573. // The series options that can be set are:
  574. //
  575. // name
  576. // categories
  577. // values
  578. //
  579. // name: Set the name for the series. The name is displayed in the chart legend and in the formula bar. The name property is optional and if it isn't supplied it will default to Series 1..n. The name can also be a formula such as Sheet1!$A$1
  580. //
  581. // categories: This sets the chart category labels. The category is more or less the same as the X axis. In most chart types the categories property is optional and the chart will just assume a sequential series from 1..n.
  582. //
  583. // values: This is the most important property of a series and is the only mandatory option for every chart object. This option links the chart with the worksheet data that it displays.
  584. //
  585. // Set properties of the chart legend. The options that can be set are:
  586. //
  587. // position
  588. // show_legend_key
  589. //
  590. // position: Set the position of the chart legend. The default legend position is right. The available positions are:
  591. //
  592. // top
  593. // bottom
  594. // left
  595. // right
  596. // top_right
  597. //
  598. // show_legend_key: Set the legend keys shall be shown in data labels. The default value is false.
  599. //
  600. // Set properties of the chart title. The properties that can be set are:
  601. //
  602. // title
  603. //
  604. // name: Set the name (title) for the chart. The name is displayed above the chart. The name can also be a formula such as Sheet1!$A$1 or a list with a sheetname. The name property is optional. The default is to have no chart title.
  605. //
  606. // Specifies how blank cells are plotted on the chart by show_blanks_as. The default value is gap. The options that can be set are:
  607. //
  608. // gap
  609. // span
  610. // zero
  611. //
  612. // gap: Specifies that blank values shall be left as a gap.
  613. //
  614. // sapn: Specifies that blank values shall be spanned with a line.
  615. //
  616. // zero: Specifies that blank values shall be treated as zero.
  617. //
  618. // Set chart offset, scale, aspect ratio setting and print settings by format, same as function AddPicture.
  619. //
  620. // Set the position of the chart plot area by plotarea. The properties that can be set are:
  621. //
  622. // show_bubble_size
  623. // show_cat_name
  624. // show_leader_lines
  625. // show_percent
  626. // show_series_name
  627. // show_val
  628. //
  629. // show_bubble_size: Specifies the bubble size shall be shown in a data label. The show_bubble_size property is optional. The default value is false.
  630. //
  631. // show_cat_name: Specifies that the category name shall be shown in the data label. The show_cat_name property is optional. The default value is true.
  632. //
  633. // show_leader_lines: Specifies leader lines shall be shown for data labels. The show_leader_lines property is optional. The default value is false.
  634. //
  635. // show_percent: Specifies that the percentage shall be shown in a data label. The show_percent property is optional. The default value is false.
  636. //
  637. // show_series_name: Specifies that the series name shall be shown in a data label. The show_series_name property is optional. The default value is false.
  638. //
  639. // show_val: Specifies that the value shall be shown in a data label. The show_val property is optional. The default value is false.
  640. //
  641. // Set the primary horizontal and vertical axis options by x_axis and y_axis. The properties that can be set are:
  642. //
  643. // reverse_order
  644. // maximum
  645. // minimum
  646. //
  647. // reverse_order: Specifies that the categories or values on reverse order (orientation of the chart). The reverse_order property is optional. The default value is false.
  648. //
  649. // maximum: Specifies that the fixed maximum, 0 is auto. The maximum property is optional. The default value is auto.
  650. //
  651. // minimum: Specifies that the fixed minimum, 0 is auto. The minimum property is optional. The default value is auto.
  652. //
  653. // Set chart size by dimension property. The dimension property is optional. The default width is 480, and height is 290.
  654. //
  655. func (f *File) AddChart(sheet, cell, format string) error {
  656. formatSet, err := parseFormatChartSet(format)
  657. if err != nil {
  658. return err
  659. }
  660. // Read sheet data.
  661. xlsx, err := f.workSheetReader(sheet)
  662. if err != nil {
  663. return err
  664. }
  665. if _, ok := chartValAxNumFmtFormatCode[formatSet.Type]; !ok {
  666. return errors.New("unsupported chart type " + formatSet.Type)
  667. }
  668. // Add first picture for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder.
  669. drawingID := f.countDrawings() + 1
  670. chartID := f.countCharts() + 1
  671. drawingXML := "xl/drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
  672. drawingID, drawingXML = f.prepareDrawing(xlsx, drawingID, sheet, drawingXML)
  673. drawingRID := f.addDrawingRelationships(drawingID, SourceRelationshipChart, "../charts/chart"+strconv.Itoa(chartID)+".xml", "")
  674. err = f.addDrawingChart(sheet, drawingXML, cell, formatSet.Dimension.Width, formatSet.Dimension.Height, drawingRID, &formatSet.Format)
  675. if err != nil {
  676. return err
  677. }
  678. f.addChart(formatSet)
  679. f.addContentTypePart(chartID, "chart")
  680. f.addContentTypePart(drawingID, "drawings")
  681. return err
  682. }
  683. // countCharts provides a function to get chart files count storage in the
  684. // folder xl/charts.
  685. func (f *File) countCharts() int {
  686. count := 0
  687. for k := range f.XLSX {
  688. if strings.Contains(k, "xl/charts/chart") {
  689. count++
  690. }
  691. }
  692. return count
  693. }
  694. // prepareDrawing provides a function to prepare drawing ID and XML by given
  695. // drawingID, worksheet name and default drawingXML.
  696. func (f *File) prepareDrawing(xlsx *xlsxWorksheet, drawingID int, sheet, drawingXML string) (int, string) {
  697. sheetRelationshipsDrawingXML := "../drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
  698. if xlsx.Drawing != nil {
  699. // The worksheet already has a picture or chart relationships, use the relationships drawing ../drawings/drawing%d.xml.
  700. sheetRelationshipsDrawingXML = f.getSheetRelationshipsTargetByID(sheet, xlsx.Drawing.RID)
  701. drawingID, _ = strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(sheetRelationshipsDrawingXML, "../drawings/drawing"), ".xml"))
  702. drawingXML = strings.Replace(sheetRelationshipsDrawingXML, "..", "xl", -1)
  703. } else {
  704. // Add first picture for given sheet.
  705. rID := f.addSheetRelationships(sheet, SourceRelationshipDrawingML, sheetRelationshipsDrawingXML, "")
  706. f.addSheetDrawing(sheet, rID)
  707. }
  708. return drawingID, drawingXML
  709. }
  710. // addChart provides a function to create chart as xl/charts/chart%d.xml by
  711. // given format sets.
  712. func (f *File) addChart(formatSet *formatChart) {
  713. count := f.countCharts()
  714. xlsxChartSpace := xlsxChartSpace{
  715. XMLNSc: NameSpaceDrawingMLChart,
  716. XMLNSa: NameSpaceDrawingML,
  717. XMLNSr: SourceRelationship,
  718. XMLNSc16r2: SourceRelationshipChart201506,
  719. Date1904: &attrValBool{Val: false},
  720. Lang: &attrValString{Val: "en-US"},
  721. RoundedCorners: &attrValBool{Val: false},
  722. Chart: cChart{
  723. Title: &cTitle{
  724. Tx: cTx{
  725. Rich: &cRich{
  726. P: aP{
  727. PPr: &aPPr{
  728. DefRPr: aRPr{
  729. Kern: 1200,
  730. Strike: "noStrike",
  731. U: "none",
  732. Sz: 1400,
  733. SolidFill: &aSolidFill{
  734. SchemeClr: &aSchemeClr{
  735. Val: "tx1",
  736. LumMod: &attrValInt{
  737. Val: 65000,
  738. },
  739. LumOff: &attrValInt{
  740. Val: 35000,
  741. },
  742. },
  743. },
  744. Ea: &aEa{
  745. Typeface: "+mn-ea",
  746. },
  747. Cs: &aCs{
  748. Typeface: "+mn-cs",
  749. },
  750. Latin: &aLatin{
  751. Typeface: "+mn-lt",
  752. },
  753. },
  754. },
  755. R: &aR{
  756. RPr: aRPr{
  757. Lang: "en-US",
  758. AltLang: "en-US",
  759. },
  760. T: formatSet.Title.Name,
  761. },
  762. },
  763. },
  764. },
  765. TxPr: cTxPr{
  766. P: aP{
  767. PPr: &aPPr{
  768. DefRPr: aRPr{
  769. Kern: 1200,
  770. U: "none",
  771. Sz: 14000,
  772. Strike: "noStrike",
  773. },
  774. },
  775. EndParaRPr: &aEndParaRPr{
  776. Lang: "en-US",
  777. },
  778. },
  779. },
  780. },
  781. View3D: &cView3D{
  782. RotX: &attrValInt{Val: chartView3DRotX[formatSet.Type]},
  783. RotY: &attrValInt{Val: chartView3DRotY[formatSet.Type]},
  784. DepthPercent: &attrValInt{Val: chartView3DDepthPercent[formatSet.Type]},
  785. RAngAx: &attrValInt{Val: chartView3DRAngAx[formatSet.Type]},
  786. },
  787. Floor: &cThicknessSpPr{
  788. Thickness: &attrValInt{Val: 0},
  789. },
  790. SideWall: &cThicknessSpPr{
  791. Thickness: &attrValInt{Val: 0},
  792. },
  793. BackWall: &cThicknessSpPr{
  794. Thickness: &attrValInt{Val: 0},
  795. },
  796. PlotArea: &cPlotArea{},
  797. Legend: &cLegend{
  798. LegendPos: &attrValString{Val: chartLegendPosition[formatSet.Legend.Position]},
  799. Overlay: &attrValBool{Val: false},
  800. },
  801. PlotVisOnly: &attrValBool{Val: false},
  802. DispBlanksAs: &attrValString{Val: formatSet.ShowBlanksAs},
  803. ShowDLblsOverMax: &attrValBool{Val: false},
  804. },
  805. SpPr: &cSpPr{
  806. SolidFill: &aSolidFill{
  807. SchemeClr: &aSchemeClr{Val: "bg1"},
  808. },
  809. Ln: &aLn{
  810. W: 9525,
  811. Cap: "flat",
  812. Cmpd: "sng",
  813. Algn: "ctr",
  814. SolidFill: &aSolidFill{
  815. SchemeClr: &aSchemeClr{Val: "tx1",
  816. LumMod: &attrValInt{
  817. Val: 15000,
  818. },
  819. LumOff: &attrValInt{
  820. Val: 85000,
  821. },
  822. },
  823. },
  824. },
  825. },
  826. PrintSettings: &cPrintSettings{
  827. PageMargins: &cPageMargins{
  828. B: 0.75,
  829. L: 0.7,
  830. R: 0.7,
  831. T: 0.7,
  832. Header: 0.3,
  833. Footer: 0.3,
  834. },
  835. },
  836. }
  837. plotAreaFunc := map[string]func(*formatChart) *cPlotArea{
  838. Area: f.drawBaseChart,
  839. AreaStacked: f.drawBaseChart,
  840. AreaPercentStacked: f.drawBaseChart,
  841. Area3D: f.drawBaseChart,
  842. Area3DStacked: f.drawBaseChart,
  843. Area3DPercentStacked: f.drawBaseChart,
  844. Bar: f.drawBaseChart,
  845. BarStacked: f.drawBaseChart,
  846. BarPercentStacked: f.drawBaseChart,
  847. Bar3DClustered: f.drawBaseChart,
  848. Bar3DStacked: f.drawBaseChart,
  849. Bar3DPercentStacked: f.drawBaseChart,
  850. Bar3DConeClustered: f.drawBaseChart,
  851. Bar3DConeStacked: f.drawBaseChart,
  852. Bar3DConePercentStacked: f.drawBaseChart,
  853. Bar3DPyramidClustered: f.drawBaseChart,
  854. Bar3DPyramidStacked: f.drawBaseChart,
  855. Bar3DPyramidPercentStacked: f.drawBaseChart,
  856. Bar3DCylinderClustered: f.drawBaseChart,
  857. Bar3DCylinderStacked: f.drawBaseChart,
  858. Bar3DCylinderPercentStacked: f.drawBaseChart,
  859. Col: f.drawBaseChart,
  860. ColStacked: f.drawBaseChart,
  861. ColPercentStacked: f.drawBaseChart,
  862. Col3D: f.drawBaseChart,
  863. Col3DClustered: f.drawBaseChart,
  864. Col3DStacked: f.drawBaseChart,
  865. Col3DPercentStacked: f.drawBaseChart,
  866. Col3DCone: f.drawBaseChart,
  867. Col3DConeClustered: f.drawBaseChart,
  868. Col3DConeStacked: f.drawBaseChart,
  869. Col3DConePercentStacked: f.drawBaseChart,
  870. Col3DPyramid: f.drawBaseChart,
  871. Col3DPyramidClustered: f.drawBaseChart,
  872. Col3DPyramidStacked: f.drawBaseChart,
  873. Col3DPyramidPercentStacked: f.drawBaseChart,
  874. Col3DCylinder: f.drawBaseChart,
  875. Col3DCylinderClustered: f.drawBaseChart,
  876. Col3DCylinderStacked: f.drawBaseChart,
  877. Col3DCylinderPercentStacked: f.drawBaseChart,
  878. Doughnut: f.drawDoughnutChart,
  879. Line: f.drawLineChart,
  880. Pie3D: f.drawPie3DChart,
  881. Pie: f.drawPieChart,
  882. Radar: f.drawRadarChart,
  883. Scatter: f.drawScatterChart,
  884. }
  885. xlsxChartSpace.Chart.PlotArea = plotAreaFunc[formatSet.Type](formatSet)
  886. chart, _ := xml.Marshal(xlsxChartSpace)
  887. media := "xl/charts/chart" + strconv.Itoa(count+1) + ".xml"
  888. f.saveFileList(media, chart)
  889. }
  890. // drawBaseChart provides a function to draw the c:plotArea element for bar,
  891. // and column series charts by given format sets.
  892. func (f *File) drawBaseChart(formatSet *formatChart) *cPlotArea {
  893. c := cCharts{
  894. BarDir: &attrValString{
  895. Val: "col",
  896. },
  897. Grouping: &attrValString{
  898. Val: "clustered",
  899. },
  900. VaryColors: &attrValBool{
  901. Val: true,
  902. },
  903. Ser: f.drawChartSeries(formatSet),
  904. Shape: f.drawChartShape(formatSet),
  905. DLbls: f.drawChartDLbls(formatSet),
  906. AxID: []*attrValInt{
  907. {Val: 754001152},
  908. {Val: 753999904},
  909. },
  910. }
  911. var ok bool
  912. c.BarDir.Val, ok = plotAreaChartBarDir[formatSet.Type]
  913. if !ok {
  914. c.BarDir = nil
  915. }
  916. c.Grouping.Val = plotAreaChartGrouping[formatSet.Type]
  917. if formatSet.Type == "colStacked" || formatSet.Type == "barStacked" || formatSet.Type == "barPercentStacked" || formatSet.Type == "colPercentStacked" || formatSet.Type == "areaPercentStacked" {
  918. c.Overlap = &attrValInt{Val: 100}
  919. }
  920. catAx := f.drawPlotAreaCatAx(formatSet)
  921. valAx := f.drawPlotAreaValAx(formatSet)
  922. charts := map[string]*cPlotArea{
  923. "area": {
  924. AreaChart: &c,
  925. CatAx: catAx,
  926. ValAx: valAx,
  927. },
  928. "areaStacked": {
  929. AreaChart: &c,
  930. CatAx: catAx,
  931. ValAx: valAx,
  932. },
  933. "areaPercentStacked": {
  934. AreaChart: &c,
  935. CatAx: catAx,
  936. ValAx: valAx,
  937. },
  938. "area3D": {
  939. Area3DChart: &c,
  940. CatAx: catAx,
  941. ValAx: valAx,
  942. },
  943. "area3DStacked": {
  944. Area3DChart: &c,
  945. CatAx: catAx,
  946. ValAx: valAx,
  947. },
  948. "area3DPercentStacked": {
  949. Area3DChart: &c,
  950. CatAx: catAx,
  951. ValAx: valAx,
  952. },
  953. "bar": {
  954. BarChart: &c,
  955. CatAx: catAx,
  956. ValAx: valAx,
  957. },
  958. "barStacked": {
  959. BarChart: &c,
  960. CatAx: catAx,
  961. ValAx: valAx,
  962. },
  963. "barPercentStacked": {
  964. BarChart: &c,
  965. CatAx: catAx,
  966. ValAx: valAx,
  967. },
  968. "bar3DClustered": {
  969. Bar3DChart: &c,
  970. CatAx: catAx,
  971. ValAx: valAx,
  972. },
  973. "bar3DStacked": {
  974. Bar3DChart: &c,
  975. CatAx: catAx,
  976. ValAx: valAx,
  977. },
  978. "bar3DPercentStacked": {
  979. Bar3DChart: &c,
  980. CatAx: catAx,
  981. ValAx: valAx,
  982. },
  983. "bar3DConeClustered": {
  984. Bar3DChart: &c,
  985. CatAx: catAx,
  986. ValAx: valAx,
  987. },
  988. "bar3DConeStacked": {
  989. Bar3DChart: &c,
  990. CatAx: catAx,
  991. ValAx: valAx,
  992. },
  993. "bar3DConePercentStacked": {
  994. Bar3DChart: &c,
  995. CatAx: catAx,
  996. ValAx: valAx,
  997. },
  998. "bar3DPyramidClustered": {
  999. Bar3DChart: &c,
  1000. CatAx: catAx,
  1001. ValAx: valAx,
  1002. },
  1003. "bar3DPyramidStacked": {
  1004. Bar3DChart: &c,
  1005. CatAx: catAx,
  1006. ValAx: valAx,
  1007. },
  1008. "bar3DPyramidPercentStacked": {
  1009. Bar3DChart: &c,
  1010. CatAx: catAx,
  1011. ValAx: valAx,
  1012. },
  1013. "bar3DCylinderClustered": {
  1014. Bar3DChart: &c,
  1015. CatAx: catAx,
  1016. ValAx: valAx,
  1017. },
  1018. "bar3DCylinderStacked": {
  1019. Bar3DChart: &c,
  1020. CatAx: catAx,
  1021. ValAx: valAx,
  1022. },
  1023. "bar3DCylinderPercentStacked": {
  1024. Bar3DChart: &c,
  1025. CatAx: catAx,
  1026. ValAx: valAx,
  1027. },
  1028. "col": {
  1029. BarChart: &c,
  1030. CatAx: catAx,
  1031. ValAx: valAx,
  1032. },
  1033. "colStacked": {
  1034. BarChart: &c,
  1035. CatAx: catAx,
  1036. ValAx: valAx,
  1037. },
  1038. "colPercentStacked": {
  1039. BarChart: &c,
  1040. CatAx: catAx,
  1041. ValAx: valAx,
  1042. },
  1043. "col3D": {
  1044. Bar3DChart: &c,
  1045. CatAx: catAx,
  1046. ValAx: valAx,
  1047. },
  1048. "col3DClustered": {
  1049. Bar3DChart: &c,
  1050. CatAx: catAx,
  1051. ValAx: valAx,
  1052. },
  1053. "col3DStacked": {
  1054. Bar3DChart: &c,
  1055. CatAx: catAx,
  1056. ValAx: valAx,
  1057. },
  1058. "col3DPercentStacked": {
  1059. Bar3DChart: &c,
  1060. CatAx: catAx,
  1061. ValAx: valAx,
  1062. },
  1063. "col3DCone": {
  1064. Bar3DChart: &c,
  1065. CatAx: catAx,
  1066. ValAx: valAx,
  1067. },
  1068. "col3DConeClustered": {
  1069. Bar3DChart: &c,
  1070. CatAx: catAx,
  1071. ValAx: valAx,
  1072. },
  1073. "col3DConeStacked": {
  1074. Bar3DChart: &c,
  1075. CatAx: catAx,
  1076. ValAx: valAx,
  1077. },
  1078. "col3DConePercentStacked": {
  1079. Bar3DChart: &c,
  1080. CatAx: catAx,
  1081. ValAx: valAx,
  1082. },
  1083. "col3DPyramid": {
  1084. Bar3DChart: &c,
  1085. CatAx: catAx,
  1086. ValAx: valAx,
  1087. },
  1088. "col3DPyramidClustered": {
  1089. Bar3DChart: &c,
  1090. CatAx: catAx,
  1091. ValAx: valAx,
  1092. },
  1093. "col3DPyramidStacked": {
  1094. Bar3DChart: &c,
  1095. CatAx: catAx,
  1096. ValAx: valAx,
  1097. },
  1098. "col3DPyramidPercentStacked": {
  1099. Bar3DChart: &c,
  1100. CatAx: catAx,
  1101. ValAx: valAx,
  1102. },
  1103. "col3DCylinder": {
  1104. Bar3DChart: &c,
  1105. CatAx: catAx,
  1106. ValAx: valAx,
  1107. },
  1108. "col3DCylinderClustered": {
  1109. Bar3DChart: &c,
  1110. CatAx: catAx,
  1111. ValAx: valAx,
  1112. },
  1113. "col3DCylinderStacked": {
  1114. Bar3DChart: &c,
  1115. CatAx: catAx,
  1116. ValAx: valAx,
  1117. },
  1118. "col3DCylinderPercentStacked": {
  1119. Bar3DChart: &c,
  1120. CatAx: catAx,
  1121. ValAx: valAx,
  1122. },
  1123. }
  1124. return charts[formatSet.Type]
  1125. }
  1126. // drawDoughnutChart provides a function to draw the c:plotArea element for
  1127. // doughnut chart by given format sets.
  1128. func (f *File) drawDoughnutChart(formatSet *formatChart) *cPlotArea {
  1129. return &cPlotArea{
  1130. DoughnutChart: &cCharts{
  1131. VaryColors: &attrValBool{
  1132. Val: true,
  1133. },
  1134. Ser: f.drawChartSeries(formatSet),
  1135. HoleSize: &attrValInt{Val: 75},
  1136. },
  1137. }
  1138. }
  1139. // drawLineChart provides a function to draw the c:plotArea element for line
  1140. // chart by given format sets.
  1141. func (f *File) drawLineChart(formatSet *formatChart) *cPlotArea {
  1142. return &cPlotArea{
  1143. LineChart: &cCharts{
  1144. Grouping: &attrValString{
  1145. Val: plotAreaChartGrouping[formatSet.Type],
  1146. },
  1147. VaryColors: &attrValBool{
  1148. Val: false,
  1149. },
  1150. Ser: f.drawChartSeries(formatSet),
  1151. DLbls: f.drawChartDLbls(formatSet),
  1152. Smooth: &attrValBool{
  1153. Val: false,
  1154. },
  1155. AxID: []*attrValInt{
  1156. {Val: 754001152},
  1157. {Val: 753999904},
  1158. },
  1159. },
  1160. CatAx: f.drawPlotAreaCatAx(formatSet),
  1161. ValAx: f.drawPlotAreaValAx(formatSet),
  1162. }
  1163. }
  1164. // drawPieChart provides a function to draw the c:plotArea element for pie
  1165. // chart by given format sets.
  1166. func (f *File) drawPieChart(formatSet *formatChart) *cPlotArea {
  1167. return &cPlotArea{
  1168. PieChart: &cCharts{
  1169. VaryColors: &attrValBool{
  1170. Val: true,
  1171. },
  1172. Ser: f.drawChartSeries(formatSet),
  1173. },
  1174. }
  1175. }
  1176. // drawPie3DChart provides a function to draw the c:plotArea element for 3D
  1177. // pie chart by given format sets.
  1178. func (f *File) drawPie3DChart(formatSet *formatChart) *cPlotArea {
  1179. return &cPlotArea{
  1180. Pie3DChart: &cCharts{
  1181. VaryColors: &attrValBool{
  1182. Val: true,
  1183. },
  1184. Ser: f.drawChartSeries(formatSet),
  1185. },
  1186. }
  1187. }
  1188. // drawRadarChart provides a function to draw the c:plotArea element for radar
  1189. // chart by given format sets.
  1190. func (f *File) drawRadarChart(formatSet *formatChart) *cPlotArea {
  1191. return &cPlotArea{
  1192. RadarChart: &cCharts{
  1193. RadarStyle: &attrValString{
  1194. Val: "marker",
  1195. },
  1196. VaryColors: &attrValBool{
  1197. Val: false,
  1198. },
  1199. Ser: f.drawChartSeries(formatSet),
  1200. DLbls: f.drawChartDLbls(formatSet),
  1201. AxID: []*attrValInt{
  1202. {Val: 754001152},
  1203. {Val: 753999904},
  1204. },
  1205. },
  1206. CatAx: f.drawPlotAreaCatAx(formatSet),
  1207. ValAx: f.drawPlotAreaValAx(formatSet),
  1208. }
  1209. }
  1210. // drawScatterChart provides a function to draw the c:plotArea element for
  1211. // scatter chart by given format sets.
  1212. func (f *File) drawScatterChart(formatSet *formatChart) *cPlotArea {
  1213. return &cPlotArea{
  1214. ScatterChart: &cCharts{
  1215. ScatterStyle: &attrValString{
  1216. Val: "smoothMarker", // line,lineMarker,marker,none,smooth,smoothMarker
  1217. },
  1218. VaryColors: &attrValBool{
  1219. Val: false,
  1220. },
  1221. Ser: f.drawChartSeries(formatSet),
  1222. DLbls: f.drawChartDLbls(formatSet),
  1223. AxID: []*attrValInt{
  1224. {Val: 754001152},
  1225. {Val: 753999904},
  1226. },
  1227. },
  1228. CatAx: f.drawPlotAreaCatAx(formatSet),
  1229. ValAx: f.drawPlotAreaValAx(formatSet),
  1230. }
  1231. }
  1232. func (f *File) drawChartShape(formatSet *formatChart) *attrValString {
  1233. shapes := map[string]string{
  1234. Bar3DConeClustered: "cone",
  1235. Bar3DConeStacked: "cone",
  1236. Bar3DConePercentStacked: "cone",
  1237. Bar3DPyramidClustered: "pyramid",
  1238. Bar3DPyramidStacked: "pyramid",
  1239. Bar3DPyramidPercentStacked: "pyramid",
  1240. Bar3DCylinderClustered: "cylinder",
  1241. Bar3DCylinderStacked: "cylinder",
  1242. Bar3DCylinderPercentStacked: "cylinder",
  1243. Col3DCone: "cone",
  1244. Col3DConeClustered: "cone",
  1245. Col3DConeStacked: "cone",
  1246. Col3DConePercentStacked: "cone",
  1247. Col3DPyramid: "pyramid",
  1248. Col3DPyramidClustered: "pyramid",
  1249. Col3DPyramidStacked: "pyramid",
  1250. Col3DPyramidPercentStacked: "pyramid",
  1251. Col3DCylinder: "cylinder",
  1252. Col3DCylinderClustered: "cylinder",
  1253. Col3DCylinderStacked: "cylinder",
  1254. Col3DCylinderPercentStacked: "cylinder",
  1255. }
  1256. if shape, ok := shapes[formatSet.Type]; ok {
  1257. return &attrValString{
  1258. Val: shape,
  1259. }
  1260. }
  1261. return nil
  1262. }
  1263. // drawChartSeries provides a function to draw the c:ser element by given
  1264. // format sets.
  1265. func (f *File) drawChartSeries(formatSet *formatChart) *[]cSer {
  1266. ser := []cSer{}
  1267. for k := range formatSet.Series {
  1268. ser = append(ser, cSer{
  1269. IDx: &attrValInt{Val: k},
  1270. Order: &attrValInt{Val: k},
  1271. Tx: &cTx{
  1272. StrRef: &cStrRef{
  1273. F: formatSet.Series[k].Name,
  1274. },
  1275. },
  1276. SpPr: f.drawChartSeriesSpPr(k, formatSet),
  1277. Marker: f.drawChartSeriesMarker(k, formatSet),
  1278. DPt: f.drawChartSeriesDPt(k, formatSet),
  1279. DLbls: f.drawChartSeriesDLbls(formatSet),
  1280. Cat: f.drawChartSeriesCat(formatSet.Series[k], formatSet),
  1281. Val: f.drawChartSeriesVal(formatSet.Series[k], formatSet),
  1282. XVal: f.drawChartSeriesXVal(formatSet.Series[k], formatSet),
  1283. YVal: f.drawChartSeriesYVal(formatSet.Series[k], formatSet),
  1284. })
  1285. }
  1286. return &ser
  1287. }
  1288. // drawChartSeriesSpPr provides a function to draw the c:spPr element by given
  1289. // format sets.
  1290. func (f *File) drawChartSeriesSpPr(i int, formatSet *formatChart) *cSpPr {
  1291. spPrScatter := &cSpPr{
  1292. Ln: &aLn{
  1293. W: 25400,
  1294. NoFill: " ",
  1295. },
  1296. }
  1297. spPrLine := &cSpPr{
  1298. Ln: &aLn{
  1299. W: 25400,
  1300. Cap: "rnd", // rnd, sq, flat
  1301. },
  1302. }
  1303. if i < 6 {
  1304. spPrLine.Ln.SolidFill = &aSolidFill{
  1305. SchemeClr: &aSchemeClr{Val: "accent" + strconv.Itoa(i+1)},
  1306. }
  1307. }
  1308. chartSeriesSpPr := map[string]*cSpPr{Line: spPrLine, Scatter: spPrScatter}
  1309. return chartSeriesSpPr[formatSet.Type]
  1310. }
  1311. // drawChartSeriesDPt provides a function to draw the c:dPt element by given
  1312. // data index and format sets.
  1313. func (f *File) drawChartSeriesDPt(i int, formatSet *formatChart) []*cDPt {
  1314. dpt := []*cDPt{{
  1315. IDx: &attrValInt{Val: i},
  1316. Bubble3D: &attrValBool{Val: false},
  1317. SpPr: &cSpPr{
  1318. SolidFill: &aSolidFill{
  1319. SchemeClr: &aSchemeClr{Val: "accent" + strconv.Itoa(i+1)},
  1320. },
  1321. Ln: &aLn{
  1322. W: 25400,
  1323. Cap: "rnd",
  1324. SolidFill: &aSolidFill{
  1325. SchemeClr: &aSchemeClr{Val: "lt" + strconv.Itoa(i+1)},
  1326. },
  1327. },
  1328. Sp3D: &aSp3D{
  1329. ContourW: 25400,
  1330. ContourClr: &aContourClr{
  1331. SchemeClr: &aSchemeClr{Val: "lt" + strconv.Itoa(i+1)},
  1332. },
  1333. },
  1334. },
  1335. }}
  1336. chartSeriesDPt := map[string][]*cDPt{Pie: dpt, Pie3D: dpt}
  1337. return chartSeriesDPt[formatSet.Type]
  1338. }
  1339. // drawChartSeriesCat provides a function to draw the c:cat element by given
  1340. // chart series and format sets.
  1341. func (f *File) drawChartSeriesCat(v formatChartSeries, formatSet *formatChart) *cCat {
  1342. cat := &cCat{
  1343. StrRef: &cStrRef{
  1344. F: v.Categories,
  1345. },
  1346. }
  1347. chartSeriesCat := map[string]*cCat{Scatter: nil}
  1348. if _, ok := chartSeriesCat[formatSet.Type]; ok {
  1349. return nil
  1350. }
  1351. return cat
  1352. }
  1353. // drawChartSeriesVal provides a function to draw the c:val element by given
  1354. // chart series and format sets.
  1355. func (f *File) drawChartSeriesVal(v formatChartSeries, formatSet *formatChart) *cVal {
  1356. val := &cVal{
  1357. NumRef: &cNumRef{
  1358. F: v.Values,
  1359. },
  1360. }
  1361. chartSeriesVal := map[string]*cVal{Scatter: nil}
  1362. if _, ok := chartSeriesVal[formatSet.Type]; ok {
  1363. return nil
  1364. }
  1365. return val
  1366. }
  1367. // drawChartSeriesMarker provides a function to draw the c:marker element by
  1368. // given data index and format sets.
  1369. func (f *File) drawChartSeriesMarker(i int, formatSet *formatChart) *cMarker {
  1370. marker := &cMarker{
  1371. Symbol: &attrValString{Val: "circle"},
  1372. Size: &attrValInt{Val: 5},
  1373. }
  1374. if i < 6 {
  1375. marker.SpPr = &cSpPr{
  1376. SolidFill: &aSolidFill{
  1377. SchemeClr: &aSchemeClr{
  1378. Val: "accent" + strconv.Itoa(i+1),
  1379. },
  1380. },
  1381. Ln: &aLn{
  1382. W: 9252,
  1383. SolidFill: &aSolidFill{
  1384. SchemeClr: &aSchemeClr{
  1385. Val: "accent" + strconv.Itoa(i+1),
  1386. },
  1387. },
  1388. },
  1389. }
  1390. }
  1391. chartSeriesMarker := map[string]*cMarker{Scatter: marker}
  1392. return chartSeriesMarker[formatSet.Type]
  1393. }
  1394. // drawChartSeriesXVal provides a function to draw the c:xVal element by given
  1395. // chart series and format sets.
  1396. func (f *File) drawChartSeriesXVal(v formatChartSeries, formatSet *formatChart) *cCat {
  1397. cat := &cCat{
  1398. StrRef: &cStrRef{
  1399. F: v.Categories,
  1400. },
  1401. }
  1402. chartSeriesXVal := map[string]*cCat{Scatter: cat}
  1403. return chartSeriesXVal[formatSet.Type]
  1404. }
  1405. // drawChartSeriesYVal provides a function to draw the c:yVal element by given
  1406. // chart series and format sets.
  1407. func (f *File) drawChartSeriesYVal(v formatChartSeries, formatSet *formatChart) *cVal {
  1408. val := &cVal{
  1409. NumRef: &cNumRef{
  1410. F: v.Values,
  1411. },
  1412. }
  1413. chartSeriesYVal := map[string]*cVal{Scatter: val}
  1414. return chartSeriesYVal[formatSet.Type]
  1415. }
  1416. // drawChartDLbls provides a function to draw the c:dLbls element by given
  1417. // format sets.
  1418. func (f *File) drawChartDLbls(formatSet *formatChart) *cDLbls {
  1419. return &cDLbls{
  1420. ShowLegendKey: &attrValBool{Val: formatSet.Legend.ShowLegendKey},
  1421. ShowVal: &attrValBool{Val: formatSet.Plotarea.ShowVal},
  1422. ShowCatName: &attrValBool{Val: formatSet.Plotarea.ShowCatName},
  1423. ShowSerName: &attrValBool{Val: formatSet.Plotarea.ShowSerName},
  1424. ShowBubbleSize: &attrValBool{Val: formatSet.Plotarea.ShowBubbleSize},
  1425. ShowPercent: &attrValBool{Val: formatSet.Plotarea.ShowPercent},
  1426. ShowLeaderLines: &attrValBool{Val: formatSet.Plotarea.ShowLeaderLines},
  1427. }
  1428. }
  1429. // drawChartSeriesDLbls provides a function to draw the c:dLbls element by
  1430. // given format sets.
  1431. func (f *File) drawChartSeriesDLbls(formatSet *formatChart) *cDLbls {
  1432. dLbls := f.drawChartDLbls(formatSet)
  1433. chartSeriesDLbls := map[string]*cDLbls{Scatter: nil}
  1434. if _, ok := chartSeriesDLbls[formatSet.Type]; ok {
  1435. return nil
  1436. }
  1437. return dLbls
  1438. }
  1439. // drawPlotAreaCatAx provides a function to draw the c:catAx element.
  1440. func (f *File) drawPlotAreaCatAx(formatSet *formatChart) []*cAxs {
  1441. min := &attrValFloat{Val: formatSet.XAxis.Minimum}
  1442. max := &attrValFloat{Val: formatSet.XAxis.Maximum}
  1443. if formatSet.XAxis.Minimum == 0 {
  1444. min = nil
  1445. }
  1446. if formatSet.XAxis.Maximum == 0 {
  1447. max = nil
  1448. }
  1449. return []*cAxs{
  1450. {
  1451. AxID: &attrValInt{Val: 754001152},
  1452. Scaling: &cScaling{
  1453. Orientation: &attrValString{Val: orientation[formatSet.XAxis.ReverseOrder]},
  1454. Max: max,
  1455. Min: min,
  1456. },
  1457. Delete: &attrValBool{Val: false},
  1458. AxPos: &attrValString{Val: catAxPos[formatSet.XAxis.ReverseOrder]},
  1459. NumFmt: &cNumFmt{
  1460. FormatCode: "General",
  1461. SourceLinked: true,
  1462. },
  1463. MajorTickMark: &attrValString{Val: "none"},
  1464. MinorTickMark: &attrValString{Val: "none"},
  1465. TickLblPos: &attrValString{Val: "nextTo"},
  1466. SpPr: f.drawPlotAreaSpPr(),
  1467. TxPr: f.drawPlotAreaTxPr(),
  1468. CrossAx: &attrValInt{Val: 753999904},
  1469. Crosses: &attrValString{Val: "autoZero"},
  1470. Auto: &attrValBool{Val: true},
  1471. LblAlgn: &attrValString{Val: "ctr"},
  1472. LblOffset: &attrValInt{Val: 100},
  1473. NoMultiLvlLbl: &attrValBool{Val: false},
  1474. },
  1475. }
  1476. }
  1477. // drawPlotAreaValAx provides a function to draw the c:valAx element.
  1478. func (f *File) drawPlotAreaValAx(formatSet *formatChart) []*cAxs {
  1479. min := &attrValFloat{Val: formatSet.YAxis.Minimum}
  1480. max := &attrValFloat{Val: formatSet.YAxis.Maximum}
  1481. if formatSet.YAxis.Minimum == 0 {
  1482. min = nil
  1483. }
  1484. if formatSet.YAxis.Maximum == 0 {
  1485. max = nil
  1486. }
  1487. return []*cAxs{
  1488. {
  1489. AxID: &attrValInt{Val: 753999904},
  1490. Scaling: &cScaling{
  1491. Orientation: &attrValString{Val: orientation[formatSet.YAxis.ReverseOrder]},
  1492. Max: max,
  1493. Min: min,
  1494. },
  1495. Delete: &attrValBool{Val: false},
  1496. AxPos: &attrValString{Val: valAxPos[formatSet.YAxis.ReverseOrder]},
  1497. NumFmt: &cNumFmt{
  1498. FormatCode: chartValAxNumFmtFormatCode[formatSet.Type],
  1499. SourceLinked: true,
  1500. },
  1501. MajorTickMark: &attrValString{Val: "none"},
  1502. MinorTickMark: &attrValString{Val: "none"},
  1503. TickLblPos: &attrValString{Val: "nextTo"},
  1504. SpPr: f.drawPlotAreaSpPr(),
  1505. TxPr: f.drawPlotAreaTxPr(),
  1506. CrossAx: &attrValInt{Val: 754001152},
  1507. Crosses: &attrValString{Val: "autoZero"},
  1508. CrossBetween: &attrValString{Val: chartValAxCrossBetween[formatSet.Type]},
  1509. },
  1510. }
  1511. }
  1512. // drawPlotAreaSpPr provides a function to draw the c:spPr element.
  1513. func (f *File) drawPlotAreaSpPr() *cSpPr {
  1514. return &cSpPr{
  1515. Ln: &aLn{
  1516. W: 9525,
  1517. Cap: "flat",
  1518. Cmpd: "sng",
  1519. Algn: "ctr",
  1520. SolidFill: &aSolidFill{
  1521. SchemeClr: &aSchemeClr{
  1522. Val: "tx1",
  1523. LumMod: &attrValInt{Val: 15000},
  1524. LumOff: &attrValInt{Val: 85000},
  1525. },
  1526. },
  1527. },
  1528. }
  1529. }
  1530. // drawPlotAreaTxPr provides a function to draw the c:txPr element.
  1531. func (f *File) drawPlotAreaTxPr() *cTxPr {
  1532. return &cTxPr{
  1533. BodyPr: aBodyPr{
  1534. Rot: -60000000,
  1535. SpcFirstLastPara: true,
  1536. VertOverflow: "ellipsis",
  1537. Vert: "horz",
  1538. Wrap: "square",
  1539. Anchor: "ctr",
  1540. AnchorCtr: true,
  1541. },
  1542. P: aP{
  1543. PPr: &aPPr{
  1544. DefRPr: aRPr{
  1545. Sz: 900,
  1546. B: false,
  1547. I: false,
  1548. U: "none",
  1549. Strike: "noStrike",
  1550. Kern: 1200,
  1551. Baseline: 0,
  1552. SolidFill: &aSolidFill{
  1553. SchemeClr: &aSchemeClr{
  1554. Val: "tx1",
  1555. LumMod: &attrValInt{Val: 15000},
  1556. LumOff: &attrValInt{Val: 85000},
  1557. },
  1558. },
  1559. Latin: &aLatin{Typeface: "+mn-lt"},
  1560. Ea: &aEa{Typeface: "+mn-ea"},
  1561. Cs: &aCs{Typeface: "+mn-cs"},
  1562. },
  1563. },
  1564. EndParaRPr: &aEndParaRPr{Lang: "en-US"},
  1565. },
  1566. }
  1567. }
  1568. // drawingParser provides a function to parse drawingXML. In order to solve
  1569. // the problem that the label structure is changed after serialization and
  1570. // deserialization, two different structures: decodeWsDr and encodeWsDr are
  1571. // defined.
  1572. func (f *File) drawingParser(path string) (*xlsxWsDr, int) {
  1573. cNvPrID := 1
  1574. if f.Drawings[path] == nil {
  1575. content := xlsxWsDr{}
  1576. content.A = NameSpaceDrawingML
  1577. content.Xdr = NameSpaceDrawingMLSpreadSheet
  1578. _, ok := f.XLSX[path]
  1579. if ok { // Append Model
  1580. decodeWsDr := decodeWsDr{}
  1581. _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(path)), &decodeWsDr)
  1582. content.R = decodeWsDr.R
  1583. cNvPrID = len(decodeWsDr.OneCellAnchor) + len(decodeWsDr.TwoCellAnchor) + 1
  1584. for _, v := range decodeWsDr.OneCellAnchor {
  1585. content.OneCellAnchor = append(content.OneCellAnchor, &xdrCellAnchor{
  1586. EditAs: v.EditAs,
  1587. GraphicFrame: v.Content,
  1588. })
  1589. }
  1590. for _, v := range decodeWsDr.TwoCellAnchor {
  1591. content.TwoCellAnchor = append(content.TwoCellAnchor, &xdrCellAnchor{
  1592. EditAs: v.EditAs,
  1593. GraphicFrame: v.Content,
  1594. })
  1595. }
  1596. }
  1597. f.Drawings[path] = &content
  1598. }
  1599. return f.Drawings[path], cNvPrID
  1600. }
  1601. // addDrawingChart provides a function to add chart graphic frame by given
  1602. // sheet, drawingXML, cell, width, height, relationship index and format sets.
  1603. func (f *File) addDrawingChart(sheet, drawingXML, cell string, width, height, rID int, formatSet *formatPicture) error {
  1604. col, row, err := CellNameToCoordinates(cell)
  1605. if err != nil {
  1606. return err
  1607. }
  1608. colIdx := col - 1
  1609. rowIdx := row - 1
  1610. width = int(float64(width) * formatSet.XScale)
  1611. height = int(float64(height) * formatSet.YScale)
  1612. colStart, rowStart, _, _, colEnd, rowEnd, x2, y2 :=
  1613. f.positionObjectPixels(sheet, colIdx, rowIdx, formatSet.OffsetX, formatSet.OffsetY, width, height)
  1614. content, cNvPrID := f.drawingParser(drawingXML)
  1615. twoCellAnchor := xdrCellAnchor{}
  1616. twoCellAnchor.EditAs = formatSet.Positioning
  1617. from := xlsxFrom{}
  1618. from.Col = colStart
  1619. from.ColOff = formatSet.OffsetX * EMU
  1620. from.Row = rowStart
  1621. from.RowOff = formatSet.OffsetY * EMU
  1622. to := xlsxTo{}
  1623. to.Col = colEnd
  1624. to.ColOff = x2 * EMU
  1625. to.Row = rowEnd
  1626. to.RowOff = y2 * EMU
  1627. twoCellAnchor.From = &from
  1628. twoCellAnchor.To = &to
  1629. graphicFrame := xlsxGraphicFrame{
  1630. NvGraphicFramePr: xlsxNvGraphicFramePr{
  1631. CNvPr: &xlsxCNvPr{
  1632. ID: f.countCharts() + f.countMedia() + 1,
  1633. Name: "Chart " + strconv.Itoa(cNvPrID),
  1634. },
  1635. },
  1636. Graphic: &xlsxGraphic{
  1637. GraphicData: &xlsxGraphicData{
  1638. URI: NameSpaceDrawingMLChart,
  1639. Chart: &xlsxChart{
  1640. C: NameSpaceDrawingMLChart,
  1641. R: SourceRelationship,
  1642. RID: "rId" + strconv.Itoa(rID),
  1643. },
  1644. },
  1645. },
  1646. }
  1647. graphic, _ := xml.Marshal(graphicFrame)
  1648. twoCellAnchor.GraphicFrame = string(graphic)
  1649. twoCellAnchor.ClientData = &xdrClientData{
  1650. FLocksWithSheet: formatSet.FLocksWithSheet,
  1651. FPrintsWithSheet: formatSet.FPrintsWithSheet,
  1652. }
  1653. content.TwoCellAnchor = append(content.TwoCellAnchor, &twoCellAnchor)
  1654. f.Drawings[drawingXML] = content
  1655. return err
  1656. }