chart.go 60 KB

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