chart.go 58 KB

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