chart.go 58 KB

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