chart.go 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869
  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. drawingRID := f.addDrawingRelationships(drawingID, SourceRelationshipChart, "../charts/chart"+strconv.Itoa(chartID)+".xml", "")
  725. err = f.addDrawingChart(sheet, drawingXML, cell, formatSet.Dimension.Width, formatSet.Dimension.Height, drawingRID, &formatSet.Format)
  726. if err != nil {
  727. return err
  728. }
  729. f.addChart(formatSet)
  730. f.addContentTypePart(chartID, "chart")
  731. f.addContentTypePart(drawingID, "drawings")
  732. return err
  733. }
  734. // countCharts provides a function to get chart files count storage in the
  735. // folder xl/charts.
  736. func (f *File) countCharts() int {
  737. count := 0
  738. for k := range f.XLSX {
  739. if strings.Contains(k, "xl/charts/chart") {
  740. count++
  741. }
  742. }
  743. return count
  744. }
  745. // prepareDrawing provides a function to prepare drawing ID and XML by given
  746. // drawingID, worksheet name and default drawingXML.
  747. func (f *File) prepareDrawing(xlsx *xlsxWorksheet, drawingID int, sheet, drawingXML string) (int, string) {
  748. sheetRelationshipsDrawingXML := "../drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
  749. if xlsx.Drawing != nil {
  750. // The worksheet already has a picture or chart relationships, use the relationships drawing ../drawings/drawing%d.xml.
  751. sheetRelationshipsDrawingXML = f.getSheetRelationshipsTargetByID(sheet, xlsx.Drawing.RID)
  752. drawingID, _ = strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(sheetRelationshipsDrawingXML, "../drawings/drawing"), ".xml"))
  753. drawingXML = strings.Replace(sheetRelationshipsDrawingXML, "..", "xl", -1)
  754. } else {
  755. // Add first picture for given sheet.
  756. rID := f.addSheetRelationships(sheet, SourceRelationshipDrawingML, sheetRelationshipsDrawingXML, "")
  757. f.addSheetDrawing(sheet, rID)
  758. }
  759. return drawingID, drawingXML
  760. }
  761. // addChart provides a function to create chart as xl/charts/chart%d.xml by
  762. // given format sets.
  763. func (f *File) addChart(formatSet *formatChart) {
  764. count := f.countCharts()
  765. xlsxChartSpace := xlsxChartSpace{
  766. XMLNSc: NameSpaceDrawingMLChart,
  767. XMLNSa: NameSpaceDrawingML,
  768. XMLNSr: SourceRelationship,
  769. XMLNSc16r2: SourceRelationshipChart201506,
  770. Date1904: &attrValBool{Val: false},
  771. Lang: &attrValString{Val: "en-US"},
  772. RoundedCorners: &attrValBool{Val: false},
  773. Chart: cChart{
  774. Title: &cTitle{
  775. Tx: cTx{
  776. Rich: &cRich{
  777. P: aP{
  778. PPr: &aPPr{
  779. DefRPr: aRPr{
  780. Kern: 1200,
  781. Strike: "noStrike",
  782. U: "none",
  783. Sz: 1400,
  784. SolidFill: &aSolidFill{
  785. SchemeClr: &aSchemeClr{
  786. Val: "tx1",
  787. LumMod: &attrValInt{
  788. Val: 65000,
  789. },
  790. LumOff: &attrValInt{
  791. Val: 35000,
  792. },
  793. },
  794. },
  795. Ea: &aEa{
  796. Typeface: "+mn-ea",
  797. },
  798. Cs: &aCs{
  799. Typeface: "+mn-cs",
  800. },
  801. Latin: &aLatin{
  802. Typeface: "+mn-lt",
  803. },
  804. },
  805. },
  806. R: &aR{
  807. RPr: aRPr{
  808. Lang: "en-US",
  809. AltLang: "en-US",
  810. },
  811. T: formatSet.Title.Name,
  812. },
  813. },
  814. },
  815. },
  816. TxPr: cTxPr{
  817. P: aP{
  818. PPr: &aPPr{
  819. DefRPr: aRPr{
  820. Kern: 1200,
  821. U: "none",
  822. Sz: 14000,
  823. Strike: "noStrike",
  824. },
  825. },
  826. EndParaRPr: &aEndParaRPr{
  827. Lang: "en-US",
  828. },
  829. },
  830. },
  831. },
  832. View3D: &cView3D{
  833. RotX: &attrValInt{Val: chartView3DRotX[formatSet.Type]},
  834. RotY: &attrValInt{Val: chartView3DRotY[formatSet.Type]},
  835. DepthPercent: &attrValInt{Val: chartView3DDepthPercent[formatSet.Type]},
  836. Perspective: &attrValInt{Val: chartView3DPerspective[formatSet.Type]},
  837. RAngAx: &attrValInt{Val: chartView3DRAngAx[formatSet.Type]},
  838. },
  839. Floor: &cThicknessSpPr{
  840. Thickness: &attrValInt{Val: 0},
  841. },
  842. SideWall: &cThicknessSpPr{
  843. Thickness: &attrValInt{Val: 0},
  844. },
  845. BackWall: &cThicknessSpPr{
  846. Thickness: &attrValInt{Val: 0},
  847. },
  848. PlotArea: &cPlotArea{},
  849. Legend: &cLegend{
  850. LegendPos: &attrValString{Val: chartLegendPosition[formatSet.Legend.Position]},
  851. Overlay: &attrValBool{Val: false},
  852. },
  853. PlotVisOnly: &attrValBool{Val: false},
  854. DispBlanksAs: &attrValString{Val: formatSet.ShowBlanksAs},
  855. ShowDLblsOverMax: &attrValBool{Val: false},
  856. },
  857. SpPr: &cSpPr{
  858. SolidFill: &aSolidFill{
  859. SchemeClr: &aSchemeClr{Val: "bg1"},
  860. },
  861. Ln: &aLn{
  862. W: 9525,
  863. Cap: "flat",
  864. Cmpd: "sng",
  865. Algn: "ctr",
  866. SolidFill: &aSolidFill{
  867. SchemeClr: &aSchemeClr{Val: "tx1",
  868. LumMod: &attrValInt{
  869. Val: 15000,
  870. },
  871. LumOff: &attrValInt{
  872. Val: 85000,
  873. },
  874. },
  875. },
  876. },
  877. },
  878. PrintSettings: &cPrintSettings{
  879. PageMargins: &cPageMargins{
  880. B: 0.75,
  881. L: 0.7,
  882. R: 0.7,
  883. T: 0.7,
  884. Header: 0.3,
  885. Footer: 0.3,
  886. },
  887. },
  888. }
  889. plotAreaFunc := map[string]func(*formatChart) *cPlotArea{
  890. Area: f.drawBaseChart,
  891. AreaStacked: f.drawBaseChart,
  892. AreaPercentStacked: f.drawBaseChart,
  893. Area3D: f.drawBaseChart,
  894. Area3DStacked: f.drawBaseChart,
  895. Area3DPercentStacked: f.drawBaseChart,
  896. Bar: f.drawBaseChart,
  897. BarStacked: f.drawBaseChart,
  898. BarPercentStacked: f.drawBaseChart,
  899. Bar3DClustered: f.drawBaseChart,
  900. Bar3DStacked: f.drawBaseChart,
  901. Bar3DPercentStacked: f.drawBaseChart,
  902. Bar3DConeClustered: f.drawBaseChart,
  903. Bar3DConeStacked: f.drawBaseChart,
  904. Bar3DConePercentStacked: f.drawBaseChart,
  905. Bar3DPyramidClustered: f.drawBaseChart,
  906. Bar3DPyramidStacked: f.drawBaseChart,
  907. Bar3DPyramidPercentStacked: f.drawBaseChart,
  908. Bar3DCylinderClustered: f.drawBaseChart,
  909. Bar3DCylinderStacked: f.drawBaseChart,
  910. Bar3DCylinderPercentStacked: f.drawBaseChart,
  911. Col: f.drawBaseChart,
  912. ColStacked: f.drawBaseChart,
  913. ColPercentStacked: f.drawBaseChart,
  914. Col3D: f.drawBaseChart,
  915. Col3DClustered: f.drawBaseChart,
  916. Col3DStacked: f.drawBaseChart,
  917. Col3DPercentStacked: f.drawBaseChart,
  918. Col3DCone: f.drawBaseChart,
  919. Col3DConeClustered: f.drawBaseChart,
  920. Col3DConeStacked: f.drawBaseChart,
  921. Col3DConePercentStacked: f.drawBaseChart,
  922. Col3DPyramid: f.drawBaseChart,
  923. Col3DPyramidClustered: f.drawBaseChart,
  924. Col3DPyramidStacked: f.drawBaseChart,
  925. Col3DPyramidPercentStacked: f.drawBaseChart,
  926. Col3DCylinder: f.drawBaseChart,
  927. Col3DCylinderClustered: f.drawBaseChart,
  928. Col3DCylinderStacked: f.drawBaseChart,
  929. Col3DCylinderPercentStacked: f.drawBaseChart,
  930. Doughnut: f.drawDoughnutChart,
  931. Line: f.drawLineChart,
  932. Pie3D: f.drawPie3DChart,
  933. Pie: f.drawPieChart,
  934. Radar: f.drawRadarChart,
  935. Scatter: f.drawScatterChart,
  936. Surface3D: f.drawSurface3DChart,
  937. WireframeSurface3D: f.drawSurface3DChart,
  938. Contour: f.drawSurfaceChart,
  939. WireframeContour: f.drawSurfaceChart,
  940. Bubble: f.drawBaseChart,
  941. Bubble3D: f.drawBaseChart,
  942. }
  943. xlsxChartSpace.Chart.PlotArea = plotAreaFunc[formatSet.Type](formatSet)
  944. chart, _ := xml.Marshal(xlsxChartSpace)
  945. media := "xl/charts/chart" + strconv.Itoa(count+1) + ".xml"
  946. f.saveFileList(media, chart)
  947. }
  948. // drawBaseChart provides a function to draw the c:plotArea element for bar,
  949. // and column series charts by given format sets.
  950. func (f *File) drawBaseChart(formatSet *formatChart) *cPlotArea {
  951. c := cCharts{
  952. BarDir: &attrValString{
  953. Val: "col",
  954. },
  955. Grouping: &attrValString{
  956. Val: "clustered",
  957. },
  958. VaryColors: &attrValBool{
  959. Val: true,
  960. },
  961. Ser: f.drawChartSeries(formatSet),
  962. Shape: f.drawChartShape(formatSet),
  963. DLbls: f.drawChartDLbls(formatSet),
  964. AxID: []*attrValInt{
  965. {Val: 754001152},
  966. {Val: 753999904},
  967. },
  968. }
  969. var ok bool
  970. if c.BarDir.Val, ok = plotAreaChartBarDir[formatSet.Type]; !ok {
  971. c.BarDir = nil
  972. }
  973. if c.Grouping.Val, ok = plotAreaChartGrouping[formatSet.Type]; !ok {
  974. c.Grouping = nil
  975. }
  976. if strings.HasSuffix(formatSet.Type, "Stacked") {
  977. c.Overlap = &attrValInt{Val: 100}
  978. }
  979. catAx := f.drawPlotAreaCatAx(formatSet)
  980. valAx := f.drawPlotAreaValAx(formatSet)
  981. charts := map[string]*cPlotArea{
  982. "area": {
  983. AreaChart: &c,
  984. CatAx: catAx,
  985. ValAx: valAx,
  986. },
  987. "areaStacked": {
  988. AreaChart: &c,
  989. CatAx: catAx,
  990. ValAx: valAx,
  991. },
  992. "areaPercentStacked": {
  993. AreaChart: &c,
  994. CatAx: catAx,
  995. ValAx: valAx,
  996. },
  997. "area3D": {
  998. Area3DChart: &c,
  999. CatAx: catAx,
  1000. ValAx: valAx,
  1001. },
  1002. "area3DStacked": {
  1003. Area3DChart: &c,
  1004. CatAx: catAx,
  1005. ValAx: valAx,
  1006. },
  1007. "area3DPercentStacked": {
  1008. Area3DChart: &c,
  1009. CatAx: catAx,
  1010. ValAx: valAx,
  1011. },
  1012. "bar": {
  1013. BarChart: &c,
  1014. CatAx: catAx,
  1015. ValAx: valAx,
  1016. },
  1017. "barStacked": {
  1018. BarChart: &c,
  1019. CatAx: catAx,
  1020. ValAx: valAx,
  1021. },
  1022. "barPercentStacked": {
  1023. BarChart: &c,
  1024. CatAx: catAx,
  1025. ValAx: valAx,
  1026. },
  1027. "bar3DClustered": {
  1028. Bar3DChart: &c,
  1029. CatAx: catAx,
  1030. ValAx: valAx,
  1031. },
  1032. "bar3DStacked": {
  1033. Bar3DChart: &c,
  1034. CatAx: catAx,
  1035. ValAx: valAx,
  1036. },
  1037. "bar3DPercentStacked": {
  1038. Bar3DChart: &c,
  1039. CatAx: catAx,
  1040. ValAx: valAx,
  1041. },
  1042. "bar3DConeClustered": {
  1043. Bar3DChart: &c,
  1044. CatAx: catAx,
  1045. ValAx: valAx,
  1046. },
  1047. "bar3DConeStacked": {
  1048. Bar3DChart: &c,
  1049. CatAx: catAx,
  1050. ValAx: valAx,
  1051. },
  1052. "bar3DConePercentStacked": {
  1053. Bar3DChart: &c,
  1054. CatAx: catAx,
  1055. ValAx: valAx,
  1056. },
  1057. "bar3DPyramidClustered": {
  1058. Bar3DChart: &c,
  1059. CatAx: catAx,
  1060. ValAx: valAx,
  1061. },
  1062. "bar3DPyramidStacked": {
  1063. Bar3DChart: &c,
  1064. CatAx: catAx,
  1065. ValAx: valAx,
  1066. },
  1067. "bar3DPyramidPercentStacked": {
  1068. Bar3DChart: &c,
  1069. CatAx: catAx,
  1070. ValAx: valAx,
  1071. },
  1072. "bar3DCylinderClustered": {
  1073. Bar3DChart: &c,
  1074. CatAx: catAx,
  1075. ValAx: valAx,
  1076. },
  1077. "bar3DCylinderStacked": {
  1078. Bar3DChart: &c,
  1079. CatAx: catAx,
  1080. ValAx: valAx,
  1081. },
  1082. "bar3DCylinderPercentStacked": {
  1083. Bar3DChart: &c,
  1084. CatAx: catAx,
  1085. ValAx: valAx,
  1086. },
  1087. "col": {
  1088. BarChart: &c,
  1089. CatAx: catAx,
  1090. ValAx: valAx,
  1091. },
  1092. "colStacked": {
  1093. BarChart: &c,
  1094. CatAx: catAx,
  1095. ValAx: valAx,
  1096. },
  1097. "colPercentStacked": {
  1098. BarChart: &c,
  1099. CatAx: catAx,
  1100. ValAx: valAx,
  1101. },
  1102. "col3D": {
  1103. Bar3DChart: &c,
  1104. CatAx: catAx,
  1105. ValAx: valAx,
  1106. },
  1107. "col3DClustered": {
  1108. Bar3DChart: &c,
  1109. CatAx: catAx,
  1110. ValAx: valAx,
  1111. },
  1112. "col3DStacked": {
  1113. Bar3DChart: &c,
  1114. CatAx: catAx,
  1115. ValAx: valAx,
  1116. },
  1117. "col3DPercentStacked": {
  1118. Bar3DChart: &c,
  1119. CatAx: catAx,
  1120. ValAx: valAx,
  1121. },
  1122. "col3DCone": {
  1123. Bar3DChart: &c,
  1124. CatAx: catAx,
  1125. ValAx: valAx,
  1126. },
  1127. "col3DConeClustered": {
  1128. Bar3DChart: &c,
  1129. CatAx: catAx,
  1130. ValAx: valAx,
  1131. },
  1132. "col3DConeStacked": {
  1133. Bar3DChart: &c,
  1134. CatAx: catAx,
  1135. ValAx: valAx,
  1136. },
  1137. "col3DConePercentStacked": {
  1138. Bar3DChart: &c,
  1139. CatAx: catAx,
  1140. ValAx: valAx,
  1141. },
  1142. "col3DPyramid": {
  1143. Bar3DChart: &c,
  1144. CatAx: catAx,
  1145. ValAx: valAx,
  1146. },
  1147. "col3DPyramidClustered": {
  1148. Bar3DChart: &c,
  1149. CatAx: catAx,
  1150. ValAx: valAx,
  1151. },
  1152. "col3DPyramidStacked": {
  1153. Bar3DChart: &c,
  1154. CatAx: catAx,
  1155. ValAx: valAx,
  1156. },
  1157. "col3DPyramidPercentStacked": {
  1158. Bar3DChart: &c,
  1159. CatAx: catAx,
  1160. ValAx: valAx,
  1161. },
  1162. "col3DCylinder": {
  1163. Bar3DChart: &c,
  1164. CatAx: catAx,
  1165. ValAx: valAx,
  1166. },
  1167. "col3DCylinderClustered": {
  1168. Bar3DChart: &c,
  1169. CatAx: catAx,
  1170. ValAx: valAx,
  1171. },
  1172. "col3DCylinderStacked": {
  1173. Bar3DChart: &c,
  1174. CatAx: catAx,
  1175. ValAx: valAx,
  1176. },
  1177. "col3DCylinderPercentStacked": {
  1178. Bar3DChart: &c,
  1179. CatAx: catAx,
  1180. ValAx: valAx,
  1181. },
  1182. "bubble": {
  1183. BubbleChart: &c,
  1184. CatAx: catAx,
  1185. ValAx: valAx,
  1186. },
  1187. "bubble3D": {
  1188. BubbleChart: &c,
  1189. CatAx: catAx,
  1190. ValAx: valAx,
  1191. },
  1192. }
  1193. return charts[formatSet.Type]
  1194. }
  1195. // drawDoughnutChart provides a function to draw the c:plotArea element for
  1196. // doughnut chart by given format sets.
  1197. func (f *File) drawDoughnutChart(formatSet *formatChart) *cPlotArea {
  1198. return &cPlotArea{
  1199. DoughnutChart: &cCharts{
  1200. VaryColors: &attrValBool{
  1201. Val: true,
  1202. },
  1203. Ser: f.drawChartSeries(formatSet),
  1204. HoleSize: &attrValInt{Val: 75},
  1205. },
  1206. }
  1207. }
  1208. // drawLineChart provides a function to draw the c:plotArea element for line
  1209. // chart by given format sets.
  1210. func (f *File) drawLineChart(formatSet *formatChart) *cPlotArea {
  1211. return &cPlotArea{
  1212. LineChart: &cCharts{
  1213. Grouping: &attrValString{
  1214. Val: plotAreaChartGrouping[formatSet.Type],
  1215. },
  1216. VaryColors: &attrValBool{
  1217. Val: false,
  1218. },
  1219. Ser: f.drawChartSeries(formatSet),
  1220. DLbls: f.drawChartDLbls(formatSet),
  1221. Smooth: &attrValBool{
  1222. Val: false,
  1223. },
  1224. AxID: []*attrValInt{
  1225. {Val: 754001152},
  1226. {Val: 753999904},
  1227. },
  1228. },
  1229. CatAx: f.drawPlotAreaCatAx(formatSet),
  1230. ValAx: f.drawPlotAreaValAx(formatSet),
  1231. }
  1232. }
  1233. // drawPieChart provides a function to draw the c:plotArea element for pie
  1234. // chart by given format sets.
  1235. func (f *File) drawPieChart(formatSet *formatChart) *cPlotArea {
  1236. return &cPlotArea{
  1237. PieChart: &cCharts{
  1238. VaryColors: &attrValBool{
  1239. Val: true,
  1240. },
  1241. Ser: f.drawChartSeries(formatSet),
  1242. },
  1243. }
  1244. }
  1245. // drawPie3DChart provides a function to draw the c:plotArea element for 3D
  1246. // pie chart by given format sets.
  1247. func (f *File) drawPie3DChart(formatSet *formatChart) *cPlotArea {
  1248. return &cPlotArea{
  1249. Pie3DChart: &cCharts{
  1250. VaryColors: &attrValBool{
  1251. Val: true,
  1252. },
  1253. Ser: f.drawChartSeries(formatSet),
  1254. },
  1255. }
  1256. }
  1257. // drawRadarChart provides a function to draw the c:plotArea element for radar
  1258. // chart by given format sets.
  1259. func (f *File) drawRadarChart(formatSet *formatChart) *cPlotArea {
  1260. return &cPlotArea{
  1261. RadarChart: &cCharts{
  1262. RadarStyle: &attrValString{
  1263. Val: "marker",
  1264. },
  1265. VaryColors: &attrValBool{
  1266. Val: false,
  1267. },
  1268. Ser: f.drawChartSeries(formatSet),
  1269. DLbls: f.drawChartDLbls(formatSet),
  1270. AxID: []*attrValInt{
  1271. {Val: 754001152},
  1272. {Val: 753999904},
  1273. },
  1274. },
  1275. CatAx: f.drawPlotAreaCatAx(formatSet),
  1276. ValAx: f.drawPlotAreaValAx(formatSet),
  1277. }
  1278. }
  1279. // drawScatterChart provides a function to draw the c:plotArea element for
  1280. // scatter chart by given format sets.
  1281. func (f *File) drawScatterChart(formatSet *formatChart) *cPlotArea {
  1282. return &cPlotArea{
  1283. ScatterChart: &cCharts{
  1284. ScatterStyle: &attrValString{
  1285. Val: "smoothMarker", // line,lineMarker,marker,none,smooth,smoothMarker
  1286. },
  1287. VaryColors: &attrValBool{
  1288. Val: false,
  1289. },
  1290. Ser: f.drawChartSeries(formatSet),
  1291. DLbls: f.drawChartDLbls(formatSet),
  1292. AxID: []*attrValInt{
  1293. {Val: 754001152},
  1294. {Val: 753999904},
  1295. },
  1296. },
  1297. CatAx: f.drawPlotAreaCatAx(formatSet),
  1298. ValAx: f.drawPlotAreaValAx(formatSet),
  1299. }
  1300. }
  1301. // drawSurface3DChart provides a function to draw the c:surface3DChart element by
  1302. // given format sets.
  1303. func (f *File) drawSurface3DChart(formatSet *formatChart) *cPlotArea {
  1304. plotArea := &cPlotArea{
  1305. Surface3DChart: &cCharts{
  1306. Ser: f.drawChartSeries(formatSet),
  1307. AxID: []*attrValInt{
  1308. {Val: 754001152},
  1309. {Val: 753999904},
  1310. {Val: 832256642},
  1311. },
  1312. },
  1313. CatAx: f.drawPlotAreaCatAx(formatSet),
  1314. ValAx: f.drawPlotAreaValAx(formatSet),
  1315. SerAx: f.drawPlotAreaSerAx(formatSet),
  1316. }
  1317. if formatSet.Type == WireframeSurface3D {
  1318. plotArea.Surface3DChart.Wireframe = &attrValBool{Val: true}
  1319. }
  1320. return plotArea
  1321. }
  1322. // drawSurfaceChart provides a function to draw the c:surfaceChart element by
  1323. // given format sets.
  1324. func (f *File) drawSurfaceChart(formatSet *formatChart) *cPlotArea {
  1325. plotArea := &cPlotArea{
  1326. SurfaceChart: &cCharts{
  1327. Ser: f.drawChartSeries(formatSet),
  1328. AxID: []*attrValInt{
  1329. {Val: 754001152},
  1330. {Val: 753999904},
  1331. {Val: 832256642},
  1332. },
  1333. },
  1334. CatAx: f.drawPlotAreaCatAx(formatSet),
  1335. ValAx: f.drawPlotAreaValAx(formatSet),
  1336. SerAx: f.drawPlotAreaSerAx(formatSet),
  1337. }
  1338. if formatSet.Type == WireframeContour {
  1339. plotArea.SurfaceChart.Wireframe = &attrValBool{Val: true}
  1340. }
  1341. return plotArea
  1342. }
  1343. // drawChartShape provides a function to draw the c:shape element by given
  1344. // format sets.
  1345. func (f *File) drawChartShape(formatSet *formatChart) *attrValString {
  1346. shapes := map[string]string{
  1347. Bar3DConeClustered: "cone",
  1348. Bar3DConeStacked: "cone",
  1349. Bar3DConePercentStacked: "cone",
  1350. Bar3DPyramidClustered: "pyramid",
  1351. Bar3DPyramidStacked: "pyramid",
  1352. Bar3DPyramidPercentStacked: "pyramid",
  1353. Bar3DCylinderClustered: "cylinder",
  1354. Bar3DCylinderStacked: "cylinder",
  1355. Bar3DCylinderPercentStacked: "cylinder",
  1356. Col3DCone: "cone",
  1357. Col3DConeClustered: "cone",
  1358. Col3DConeStacked: "cone",
  1359. Col3DConePercentStacked: "cone",
  1360. Col3DPyramid: "pyramid",
  1361. Col3DPyramidClustered: "pyramid",
  1362. Col3DPyramidStacked: "pyramid",
  1363. Col3DPyramidPercentStacked: "pyramid",
  1364. Col3DCylinder: "cylinder",
  1365. Col3DCylinderClustered: "cylinder",
  1366. Col3DCylinderStacked: "cylinder",
  1367. Col3DCylinderPercentStacked: "cylinder",
  1368. }
  1369. if shape, ok := shapes[formatSet.Type]; ok {
  1370. return &attrValString{Val: shape}
  1371. }
  1372. return nil
  1373. }
  1374. // drawChartSeries provides a function to draw the c:ser element by given
  1375. // format sets.
  1376. func (f *File) drawChartSeries(formatSet *formatChart) *[]cSer {
  1377. ser := []cSer{}
  1378. for k := range formatSet.Series {
  1379. ser = append(ser, cSer{
  1380. IDx: &attrValInt{Val: k},
  1381. Order: &attrValInt{Val: k},
  1382. Tx: &cTx{
  1383. StrRef: &cStrRef{
  1384. F: formatSet.Series[k].Name,
  1385. },
  1386. },
  1387. SpPr: f.drawChartSeriesSpPr(k, formatSet),
  1388. Marker: f.drawChartSeriesMarker(k, formatSet),
  1389. DPt: f.drawChartSeriesDPt(k, formatSet),
  1390. DLbls: f.drawChartSeriesDLbls(formatSet),
  1391. Cat: f.drawChartSeriesCat(formatSet.Series[k], formatSet),
  1392. Val: f.drawChartSeriesVal(formatSet.Series[k], formatSet),
  1393. XVal: f.drawChartSeriesXVal(formatSet.Series[k], formatSet),
  1394. YVal: f.drawChartSeriesYVal(formatSet.Series[k], formatSet),
  1395. BubbleSize: f.drawCharSeriesBubbleSize(formatSet.Series[k], formatSet),
  1396. Bubble3D: f.drawCharSeriesBubble3D(formatSet),
  1397. })
  1398. }
  1399. return &ser
  1400. }
  1401. // drawChartSeriesSpPr provides a function to draw the c:spPr element by given
  1402. // format sets.
  1403. func (f *File) drawChartSeriesSpPr(i int, formatSet *formatChart) *cSpPr {
  1404. spPrScatter := &cSpPr{
  1405. Ln: &aLn{
  1406. W: 25400,
  1407. NoFill: " ",
  1408. },
  1409. }
  1410. spPrLine := &cSpPr{
  1411. Ln: &aLn{
  1412. W: 25400,
  1413. Cap: "rnd", // rnd, sq, flat
  1414. },
  1415. }
  1416. if i < 6 {
  1417. spPrLine.Ln.SolidFill = &aSolidFill{
  1418. SchemeClr: &aSchemeClr{Val: "accent" + strconv.Itoa(i+1)},
  1419. }
  1420. }
  1421. chartSeriesSpPr := map[string]*cSpPr{Line: spPrLine, Scatter: spPrScatter}
  1422. return chartSeriesSpPr[formatSet.Type]
  1423. }
  1424. // drawChartSeriesDPt provides a function to draw the c:dPt element by given
  1425. // data index and format sets.
  1426. func (f *File) drawChartSeriesDPt(i int, formatSet *formatChart) []*cDPt {
  1427. dpt := []*cDPt{{
  1428. IDx: &attrValInt{Val: i},
  1429. Bubble3D: &attrValBool{Val: false},
  1430. SpPr: &cSpPr{
  1431. SolidFill: &aSolidFill{
  1432. SchemeClr: &aSchemeClr{Val: "accent" + strconv.Itoa(i+1)},
  1433. },
  1434. Ln: &aLn{
  1435. W: 25400,
  1436. Cap: "rnd",
  1437. SolidFill: &aSolidFill{
  1438. SchemeClr: &aSchemeClr{Val: "lt" + strconv.Itoa(i+1)},
  1439. },
  1440. },
  1441. Sp3D: &aSp3D{
  1442. ContourW: 25400,
  1443. ContourClr: &aContourClr{
  1444. SchemeClr: &aSchemeClr{Val: "lt" + strconv.Itoa(i+1)},
  1445. },
  1446. },
  1447. },
  1448. }}
  1449. chartSeriesDPt := map[string][]*cDPt{Pie: dpt, Pie3D: dpt}
  1450. return chartSeriesDPt[formatSet.Type]
  1451. }
  1452. // drawChartSeriesCat provides a function to draw the c:cat element by given
  1453. // chart series and format sets.
  1454. func (f *File) drawChartSeriesCat(v formatChartSeries, formatSet *formatChart) *cCat {
  1455. cat := &cCat{
  1456. StrRef: &cStrRef{
  1457. F: v.Categories,
  1458. },
  1459. }
  1460. chartSeriesCat := map[string]*cCat{Scatter: nil}
  1461. if _, ok := chartSeriesCat[formatSet.Type]; ok {
  1462. return nil
  1463. }
  1464. return cat
  1465. }
  1466. // drawChartSeriesVal provides a function to draw the c:val element by given
  1467. // chart series and format sets.
  1468. func (f *File) drawChartSeriesVal(v formatChartSeries, formatSet *formatChart) *cVal {
  1469. val := &cVal{
  1470. NumRef: &cNumRef{
  1471. F: v.Values,
  1472. },
  1473. }
  1474. chartSeriesVal := map[string]*cVal{Scatter: nil}
  1475. if _, ok := chartSeriesVal[formatSet.Type]; ok {
  1476. return nil
  1477. }
  1478. return val
  1479. }
  1480. // drawChartSeriesMarker provides a function to draw the c:marker element by
  1481. // given data index and format sets.
  1482. func (f *File) drawChartSeriesMarker(i int, formatSet *formatChart) *cMarker {
  1483. marker := &cMarker{
  1484. Symbol: &attrValString{Val: "circle"},
  1485. Size: &attrValInt{Val: 5},
  1486. }
  1487. if i < 6 {
  1488. marker.SpPr = &cSpPr{
  1489. SolidFill: &aSolidFill{
  1490. SchemeClr: &aSchemeClr{
  1491. Val: "accent" + strconv.Itoa(i+1),
  1492. },
  1493. },
  1494. Ln: &aLn{
  1495. W: 9252,
  1496. SolidFill: &aSolidFill{
  1497. SchemeClr: &aSchemeClr{
  1498. Val: "accent" + strconv.Itoa(i+1),
  1499. },
  1500. },
  1501. },
  1502. }
  1503. }
  1504. chartSeriesMarker := map[string]*cMarker{Scatter: marker}
  1505. return chartSeriesMarker[formatSet.Type]
  1506. }
  1507. // drawChartSeriesXVal provides a function to draw the c:xVal element by given
  1508. // chart series and format sets.
  1509. func (f *File) drawChartSeriesXVal(v formatChartSeries, formatSet *formatChart) *cCat {
  1510. cat := &cCat{
  1511. StrRef: &cStrRef{
  1512. F: v.Categories,
  1513. },
  1514. }
  1515. chartSeriesXVal := map[string]*cCat{Scatter: cat}
  1516. return chartSeriesXVal[formatSet.Type]
  1517. }
  1518. // drawChartSeriesYVal provides a function to draw the c:yVal element by given
  1519. // chart series and format sets.
  1520. func (f *File) drawChartSeriesYVal(v formatChartSeries, formatSet *formatChart) *cVal {
  1521. val := &cVal{
  1522. NumRef: &cNumRef{
  1523. F: v.Values,
  1524. },
  1525. }
  1526. chartSeriesYVal := map[string]*cVal{Scatter: val, Bubble: val, Bubble3D: val}
  1527. return chartSeriesYVal[formatSet.Type]
  1528. }
  1529. // drawCharSeriesBubbleSize provides a function to draw the c:bubbleSize
  1530. // element by given chart series and format sets.
  1531. func (f *File) drawCharSeriesBubbleSize(v formatChartSeries, formatSet *formatChart) *cVal {
  1532. if _, ok := map[string]bool{Bubble: true, Bubble3D: true}[formatSet.Type]; !ok {
  1533. return nil
  1534. }
  1535. return &cVal{
  1536. NumRef: &cNumRef{
  1537. F: v.Values,
  1538. },
  1539. }
  1540. }
  1541. // drawCharSeriesBubble3D provides a function to draw the c:bubble3D element
  1542. // by given format sets.
  1543. func (f *File) drawCharSeriesBubble3D(formatSet *formatChart) *attrValBool {
  1544. if _, ok := map[string]bool{Bubble3D: true}[formatSet.Type]; !ok {
  1545. return nil
  1546. }
  1547. return &attrValBool{Val: true}
  1548. }
  1549. // drawChartDLbls provides a function to draw the c:dLbls element by given
  1550. // format sets.
  1551. func (f *File) drawChartDLbls(formatSet *formatChart) *cDLbls {
  1552. return &cDLbls{
  1553. ShowLegendKey: &attrValBool{Val: formatSet.Legend.ShowLegendKey},
  1554. ShowVal: &attrValBool{Val: formatSet.Plotarea.ShowVal},
  1555. ShowCatName: &attrValBool{Val: formatSet.Plotarea.ShowCatName},
  1556. ShowSerName: &attrValBool{Val: formatSet.Plotarea.ShowSerName},
  1557. ShowBubbleSize: &attrValBool{Val: formatSet.Plotarea.ShowBubbleSize},
  1558. ShowPercent: &attrValBool{Val: formatSet.Plotarea.ShowPercent},
  1559. ShowLeaderLines: &attrValBool{Val: formatSet.Plotarea.ShowLeaderLines},
  1560. }
  1561. }
  1562. // drawChartSeriesDLbls provides a function to draw the c:dLbls element by
  1563. // given format sets.
  1564. func (f *File) drawChartSeriesDLbls(formatSet *formatChart) *cDLbls {
  1565. dLbls := f.drawChartDLbls(formatSet)
  1566. chartSeriesDLbls := map[string]*cDLbls{Scatter: nil, Surface3D: nil, WireframeSurface3D: nil, Contour: nil, WireframeContour: nil, Bubble: nil, Bubble3D: nil}
  1567. if _, ok := chartSeriesDLbls[formatSet.Type]; ok {
  1568. return nil
  1569. }
  1570. return dLbls
  1571. }
  1572. // drawPlotAreaCatAx provides a function to draw the c:catAx element.
  1573. func (f *File) drawPlotAreaCatAx(formatSet *formatChart) []*cAxs {
  1574. min := &attrValFloat{Val: formatSet.XAxis.Minimum}
  1575. max := &attrValFloat{Val: formatSet.XAxis.Maximum}
  1576. if formatSet.XAxis.Minimum == 0 {
  1577. min = nil
  1578. }
  1579. if formatSet.XAxis.Maximum == 0 {
  1580. max = nil
  1581. }
  1582. axs := []*cAxs{
  1583. {
  1584. AxID: &attrValInt{Val: 754001152},
  1585. Scaling: &cScaling{
  1586. Orientation: &attrValString{Val: orientation[formatSet.XAxis.ReverseOrder]},
  1587. Max: max,
  1588. Min: min,
  1589. },
  1590. Delete: &attrValBool{Val: false},
  1591. AxPos: &attrValString{Val: catAxPos[formatSet.XAxis.ReverseOrder]},
  1592. NumFmt: &cNumFmt{
  1593. FormatCode: "General",
  1594. SourceLinked: true,
  1595. },
  1596. MajorTickMark: &attrValString{Val: "none"},
  1597. MinorTickMark: &attrValString{Val: "none"},
  1598. TickLblPos: &attrValString{Val: "nextTo"},
  1599. SpPr: f.drawPlotAreaSpPr(),
  1600. TxPr: f.drawPlotAreaTxPr(),
  1601. CrossAx: &attrValInt{Val: 753999904},
  1602. Crosses: &attrValString{Val: "autoZero"},
  1603. Auto: &attrValBool{Val: true},
  1604. LblAlgn: &attrValString{Val: "ctr"},
  1605. LblOffset: &attrValInt{Val: 100},
  1606. NoMultiLvlLbl: &attrValBool{Val: false},
  1607. },
  1608. }
  1609. if formatSet.XAxis.MajorGridlines {
  1610. axs[0].MajorGridlines = &cChartLines{SpPr: f.drawPlotAreaSpPr()}
  1611. }
  1612. return axs
  1613. }
  1614. // drawPlotAreaValAx provides a function to draw the c:valAx element.
  1615. func (f *File) drawPlotAreaValAx(formatSet *formatChart) []*cAxs {
  1616. min := &attrValFloat{Val: formatSet.YAxis.Minimum}
  1617. max := &attrValFloat{Val: formatSet.YAxis.Maximum}
  1618. if formatSet.YAxis.Minimum == 0 {
  1619. min = nil
  1620. }
  1621. if formatSet.YAxis.Maximum == 0 {
  1622. max = nil
  1623. }
  1624. axs := []*cAxs{
  1625. {
  1626. AxID: &attrValInt{Val: 753999904},
  1627. Scaling: &cScaling{
  1628. Orientation: &attrValString{Val: orientation[formatSet.YAxis.ReverseOrder]},
  1629. Max: max,
  1630. Min: min,
  1631. },
  1632. Delete: &attrValBool{Val: false},
  1633. AxPos: &attrValString{Val: valAxPos[formatSet.YAxis.ReverseOrder]},
  1634. NumFmt: &cNumFmt{
  1635. FormatCode: chartValAxNumFmtFormatCode[formatSet.Type],
  1636. SourceLinked: true,
  1637. },
  1638. MajorTickMark: &attrValString{Val: "none"},
  1639. MinorTickMark: &attrValString{Val: "none"},
  1640. TickLblPos: &attrValString{Val: "nextTo"},
  1641. SpPr: f.drawPlotAreaSpPr(),
  1642. TxPr: f.drawPlotAreaTxPr(),
  1643. CrossAx: &attrValInt{Val: 754001152},
  1644. Crosses: &attrValString{Val: "autoZero"},
  1645. CrossBetween: &attrValString{Val: chartValAxCrossBetween[formatSet.Type]},
  1646. },
  1647. }
  1648. if formatSet.YAxis.MajorGridlines {
  1649. axs[0].MajorGridlines = &cChartLines{SpPr: f.drawPlotAreaSpPr()}
  1650. }
  1651. if pos, ok := valTickLblPos[formatSet.Type]; ok {
  1652. axs[0].TickLblPos.Val = pos
  1653. }
  1654. return axs
  1655. }
  1656. // drawPlotAreaSerAx provides a function to draw the c:serAx element.
  1657. func (f *File) drawPlotAreaSerAx(formatSet *formatChart) []*cAxs {
  1658. min := &attrValFloat{Val: formatSet.YAxis.Minimum}
  1659. max := &attrValFloat{Val: formatSet.YAxis.Maximum}
  1660. if formatSet.YAxis.Minimum == 0 {
  1661. min = nil
  1662. }
  1663. if formatSet.YAxis.Maximum == 0 {
  1664. max = nil
  1665. }
  1666. return []*cAxs{
  1667. {
  1668. AxID: &attrValInt{Val: 832256642},
  1669. Scaling: &cScaling{
  1670. Orientation: &attrValString{Val: orientation[formatSet.YAxis.ReverseOrder]},
  1671. Max: max,
  1672. Min: min,
  1673. },
  1674. Delete: &attrValBool{Val: false},
  1675. AxPos: &attrValString{Val: catAxPos[formatSet.XAxis.ReverseOrder]},
  1676. TickLblPos: &attrValString{Val: "nextTo"},
  1677. SpPr: f.drawPlotAreaSpPr(),
  1678. TxPr: f.drawPlotAreaTxPr(),
  1679. CrossAx: &attrValInt{Val: 753999904},
  1680. },
  1681. }
  1682. }
  1683. // drawPlotAreaSpPr provides a function to draw the c:spPr element.
  1684. func (f *File) drawPlotAreaSpPr() *cSpPr {
  1685. return &cSpPr{
  1686. Ln: &aLn{
  1687. W: 9525,
  1688. Cap: "flat",
  1689. Cmpd: "sng",
  1690. Algn: "ctr",
  1691. SolidFill: &aSolidFill{
  1692. SchemeClr: &aSchemeClr{
  1693. Val: "tx1",
  1694. LumMod: &attrValInt{Val: 15000},
  1695. LumOff: &attrValInt{Val: 85000},
  1696. },
  1697. },
  1698. },
  1699. }
  1700. }
  1701. // drawPlotAreaTxPr provides a function to draw the c:txPr element.
  1702. func (f *File) drawPlotAreaTxPr() *cTxPr {
  1703. return &cTxPr{
  1704. BodyPr: aBodyPr{
  1705. Rot: -60000000,
  1706. SpcFirstLastPara: true,
  1707. VertOverflow: "ellipsis",
  1708. Vert: "horz",
  1709. Wrap: "square",
  1710. Anchor: "ctr",
  1711. AnchorCtr: true,
  1712. },
  1713. P: aP{
  1714. PPr: &aPPr{
  1715. DefRPr: aRPr{
  1716. Sz: 900,
  1717. B: false,
  1718. I: false,
  1719. U: "none",
  1720. Strike: "noStrike",
  1721. Kern: 1200,
  1722. Baseline: 0,
  1723. SolidFill: &aSolidFill{
  1724. SchemeClr: &aSchemeClr{
  1725. Val: "tx1",
  1726. LumMod: &attrValInt{Val: 15000},
  1727. LumOff: &attrValInt{Val: 85000},
  1728. },
  1729. },
  1730. Latin: &aLatin{Typeface: "+mn-lt"},
  1731. Ea: &aEa{Typeface: "+mn-ea"},
  1732. Cs: &aCs{Typeface: "+mn-cs"},
  1733. },
  1734. },
  1735. EndParaRPr: &aEndParaRPr{Lang: "en-US"},
  1736. },
  1737. }
  1738. }
  1739. // drawingParser provides a function to parse drawingXML. In order to solve
  1740. // the problem that the label structure is changed after serialization and
  1741. // deserialization, two different structures: decodeWsDr and encodeWsDr are
  1742. // defined.
  1743. func (f *File) drawingParser(path string) (*xlsxWsDr, int) {
  1744. cNvPrID := 1
  1745. if f.Drawings[path] == nil {
  1746. content := xlsxWsDr{}
  1747. content.A = NameSpaceDrawingML
  1748. content.Xdr = NameSpaceDrawingMLSpreadSheet
  1749. _, ok := f.XLSX[path]
  1750. if ok { // Append Model
  1751. decodeWsDr := decodeWsDr{}
  1752. _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(path)), &decodeWsDr)
  1753. content.R = decodeWsDr.R
  1754. cNvPrID = len(decodeWsDr.OneCellAnchor) + len(decodeWsDr.TwoCellAnchor) + 1
  1755. for _, v := range decodeWsDr.OneCellAnchor {
  1756. content.OneCellAnchor = append(content.OneCellAnchor, &xdrCellAnchor{
  1757. EditAs: v.EditAs,
  1758. GraphicFrame: v.Content,
  1759. })
  1760. }
  1761. for _, v := range decodeWsDr.TwoCellAnchor {
  1762. content.TwoCellAnchor = append(content.TwoCellAnchor, &xdrCellAnchor{
  1763. EditAs: v.EditAs,
  1764. GraphicFrame: v.Content,
  1765. })
  1766. }
  1767. }
  1768. f.Drawings[path] = &content
  1769. }
  1770. return f.Drawings[path], cNvPrID
  1771. }
  1772. // addDrawingChart provides a function to add chart graphic frame by given
  1773. // sheet, drawingXML, cell, width, height, relationship index and format sets.
  1774. func (f *File) addDrawingChart(sheet, drawingXML, cell string, width, height, rID int, formatSet *formatPicture) error {
  1775. col, row, err := CellNameToCoordinates(cell)
  1776. if err != nil {
  1777. return err
  1778. }
  1779. colIdx := col - 1
  1780. rowIdx := row - 1
  1781. width = int(float64(width) * formatSet.XScale)
  1782. height = int(float64(height) * formatSet.YScale)
  1783. colStart, rowStart, _, _, colEnd, rowEnd, x2, y2 :=
  1784. f.positionObjectPixels(sheet, colIdx, rowIdx, formatSet.OffsetX, formatSet.OffsetY, width, height)
  1785. content, cNvPrID := f.drawingParser(drawingXML)
  1786. twoCellAnchor := xdrCellAnchor{}
  1787. twoCellAnchor.EditAs = formatSet.Positioning
  1788. from := xlsxFrom{}
  1789. from.Col = colStart
  1790. from.ColOff = formatSet.OffsetX * EMU
  1791. from.Row = rowStart
  1792. from.RowOff = formatSet.OffsetY * EMU
  1793. to := xlsxTo{}
  1794. to.Col = colEnd
  1795. to.ColOff = x2 * EMU
  1796. to.Row = rowEnd
  1797. to.RowOff = y2 * EMU
  1798. twoCellAnchor.From = &from
  1799. twoCellAnchor.To = &to
  1800. graphicFrame := xlsxGraphicFrame{
  1801. NvGraphicFramePr: xlsxNvGraphicFramePr{
  1802. CNvPr: &xlsxCNvPr{
  1803. ID: f.countCharts() + f.countMedia() + 1,
  1804. Name: "Chart " + strconv.Itoa(cNvPrID),
  1805. },
  1806. },
  1807. Graphic: &xlsxGraphic{
  1808. GraphicData: &xlsxGraphicData{
  1809. URI: NameSpaceDrawingMLChart,
  1810. Chart: &xlsxChart{
  1811. C: NameSpaceDrawingMLChart,
  1812. R: SourceRelationship,
  1813. RID: "rId" + strconv.Itoa(rID),
  1814. },
  1815. },
  1816. },
  1817. }
  1818. graphic, _ := xml.Marshal(graphicFrame)
  1819. twoCellAnchor.GraphicFrame = string(graphic)
  1820. twoCellAnchor.ClientData = &xdrClientData{
  1821. FLocksWithSheet: formatSet.FLocksWithSheet,
  1822. FPrintsWithSheet: formatSet.FPrintsWithSheet,
  1823. }
  1824. content.TwoCellAnchor = append(content.TwoCellAnchor, &twoCellAnchor)
  1825. f.Drawings[drawingXML] = content
  1826. return err
  1827. }