chart.go 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  1. // Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of
  2. // this source code is governed by a BSD-style license that can be found in
  3. // the LICENSE file.
  4. //
  5. // Package excelize providing a set of functions that allow you to write to
  6. // and read from XLSX files. Support reads and writes XLSX file generated by
  7. // Microsoft Excel™ 2007 and later. Support save file without losing original
  8. // charts of XLSX. This library needs Go version 1.8 or later.
  9. package excelize
  10. import (
  11. "encoding/json"
  12. "encoding/xml"
  13. "strconv"
  14. "strings"
  15. )
  16. // This section defines the currently supported chart types.
  17. const (
  18. Area = "area"
  19. AreaStacked = "areaStacked"
  20. AreaPercentStacked = "areaPercentStacked"
  21. Area3D = "area3D"
  22. Area3DStacked = "area3DStacked"
  23. Area3DPercentStacked = "area3DPercentStacked"
  24. Bar = "bar"
  25. BarStacked = "barStacked"
  26. BarPercentStacked = "barPercentStacked"
  27. Bar3DClustered = "bar3DClustered"
  28. Bar3DStacked = "bar3DStacked"
  29. Bar3DPercentStacked = "bar3DPercentStacked"
  30. Col = "col"
  31. ColStacked = "colStacked"
  32. ColPercentStacked = "colPercentStacked"
  33. Col3DClustered = "col3DClustered"
  34. Col3D = "col3D"
  35. Col3DStacked = "col3DStacked"
  36. Col3DPercentStacked = "col3DPercentStacked"
  37. Doughnut = "doughnut"
  38. Line = "line"
  39. Pie = "pie"
  40. Pie3D = "pie3D"
  41. Radar = "radar"
  42. Scatter = "scatter"
  43. )
  44. // This section defines the default value of chart properties.
  45. var (
  46. chartView3DRotX = map[string]int{
  47. Area: 0,
  48. AreaStacked: 0,
  49. AreaPercentStacked: 0,
  50. Area3D: 15,
  51. Area3DStacked: 15,
  52. Area3DPercentStacked: 15,
  53. Bar: 0,
  54. BarStacked: 0,
  55. BarPercentStacked: 0,
  56. Bar3DClustered: 15,
  57. Bar3DStacked: 15,
  58. Bar3DPercentStacked: 15,
  59. Col: 0,
  60. ColStacked: 0,
  61. ColPercentStacked: 0,
  62. Col3DClustered: 15,
  63. Col3D: 15,
  64. Col3DStacked: 15,
  65. Col3DPercentStacked: 15,
  66. Doughnut: 0,
  67. Line: 0,
  68. Pie: 0,
  69. Pie3D: 30,
  70. Radar: 0,
  71. Scatter: 0,
  72. }
  73. chartView3DRotY = map[string]int{
  74. Area: 0,
  75. AreaStacked: 0,
  76. AreaPercentStacked: 0,
  77. Area3D: 20,
  78. Area3DStacked: 20,
  79. Area3DPercentStacked: 20,
  80. Bar: 0,
  81. BarStacked: 0,
  82. BarPercentStacked: 0,
  83. Bar3DClustered: 20,
  84. Bar3DStacked: 20,
  85. Bar3DPercentStacked: 20,
  86. Col: 0,
  87. ColStacked: 0,
  88. ColPercentStacked: 0,
  89. Col3DClustered: 20,
  90. Col3D: 20,
  91. Col3DStacked: 20,
  92. Col3DPercentStacked: 20,
  93. Doughnut: 0,
  94. Line: 0,
  95. Pie: 0,
  96. Pie3D: 0,
  97. Radar: 0,
  98. Scatter: 0,
  99. }
  100. chartView3DDepthPercent = map[string]int{
  101. Area: 100,
  102. AreaStacked: 100,
  103. AreaPercentStacked: 100,
  104. Area3D: 100,
  105. Area3DStacked: 100,
  106. Area3DPercentStacked: 100,
  107. Bar: 100,
  108. BarStacked: 100,
  109. BarPercentStacked: 100,
  110. Bar3DClustered: 100,
  111. Bar3DStacked: 100,
  112. Bar3DPercentStacked: 100,
  113. Col: 100,
  114. ColStacked: 100,
  115. ColPercentStacked: 100,
  116. Col3DClustered: 100,
  117. Col3D: 100,
  118. Col3DStacked: 100,
  119. Col3DPercentStacked: 100,
  120. Doughnut: 100,
  121. Line: 100,
  122. Pie: 100,
  123. Pie3D: 100,
  124. Radar: 100,
  125. Scatter: 100,
  126. }
  127. chartView3DRAngAx = map[string]int{
  128. Area: 0,
  129. AreaStacked: 0,
  130. AreaPercentStacked: 0,
  131. Area3D: 1,
  132. Area3DStacked: 1,
  133. Area3DPercentStacked: 1,
  134. Bar: 0,
  135. BarStacked: 0,
  136. BarPercentStacked: 0,
  137. Bar3DClustered: 1,
  138. Bar3DStacked: 1,
  139. Bar3DPercentStacked: 1,
  140. Col: 0,
  141. ColStacked: 0,
  142. ColPercentStacked: 0,
  143. Col3DClustered: 1,
  144. Col3D: 1,
  145. Col3DStacked: 1,
  146. Col3DPercentStacked: 1,
  147. Doughnut: 0,
  148. Line: 0,
  149. Pie: 0,
  150. Pie3D: 0,
  151. Radar: 0,
  152. Scatter: 0,
  153. }
  154. chartLegendPosition = map[string]string{
  155. "bottom": "b",
  156. "left": "l",
  157. "right": "r",
  158. "top": "t",
  159. "top_right": "tr",
  160. }
  161. chartValAxNumFmtFormatCode = map[string]string{
  162. Area: "General",
  163. AreaStacked: "General",
  164. AreaPercentStacked: "0%",
  165. Area3D: "General",
  166. Area3DStacked: "General",
  167. Area3DPercentStacked: "0%",
  168. Bar: "General",
  169. BarStacked: "General",
  170. BarPercentStacked: "0%",
  171. Bar3DClustered: "General",
  172. Bar3DStacked: "General",
  173. Bar3DPercentStacked: "0%",
  174. Col: "General",
  175. ColStacked: "General",
  176. ColPercentStacked: "0%",
  177. Col3DClustered: "General",
  178. Col3D: "General",
  179. Col3DStacked: "General",
  180. Col3DPercentStacked: "0%",
  181. Doughnut: "General",
  182. Line: "General",
  183. Pie: "General",
  184. Pie3D: "General",
  185. Radar: "General",
  186. Scatter: "General",
  187. }
  188. chartValAxCrossBetween = map[string]string{
  189. Area: "midCat",
  190. AreaStacked: "midCat",
  191. AreaPercentStacked: "midCat",
  192. Area3D: "midCat",
  193. Area3DStacked: "midCat",
  194. Area3DPercentStacked: "midCat",
  195. Bar: "between",
  196. BarStacked: "between",
  197. BarPercentStacked: "between",
  198. Bar3DClustered: "between",
  199. Bar3DStacked: "between",
  200. Bar3DPercentStacked: "between",
  201. Col: "between",
  202. ColStacked: "between",
  203. ColPercentStacked: "between",
  204. Col3DClustered: "between",
  205. Col3D: "between",
  206. Col3DStacked: "between",
  207. Col3DPercentStacked: "between",
  208. Doughnut: "between",
  209. Line: "between",
  210. Pie: "between",
  211. Pie3D: "between",
  212. Radar: "between",
  213. Scatter: "between",
  214. }
  215. plotAreaChartGrouping = map[string]string{
  216. Area: "standard",
  217. AreaStacked: "stacked",
  218. AreaPercentStacked: "percentStacked",
  219. Area3D: "standard",
  220. Area3DStacked: "stacked",
  221. Area3DPercentStacked: "percentStacked",
  222. Bar: "clustered",
  223. BarStacked: "stacked",
  224. BarPercentStacked: "percentStacked",
  225. Bar3DClustered: "clustered",
  226. Bar3DStacked: "stacked",
  227. Bar3DPercentStacked: "percentStacked",
  228. Col: "clustered",
  229. ColStacked: "stacked",
  230. ColPercentStacked: "percentStacked",
  231. Col3DClustered: "clustered",
  232. Col3D: "standard",
  233. Col3DStacked: "stacked",
  234. Col3DPercentStacked: "percentStacked",
  235. Line: "standard",
  236. }
  237. plotAreaChartBarDir = map[string]string{
  238. Bar: "bar",
  239. BarStacked: "bar",
  240. BarPercentStacked: "bar",
  241. Bar3DClustered: "bar",
  242. Bar3DStacked: "bar",
  243. Bar3DPercentStacked: "bar",
  244. Col: "col",
  245. ColStacked: "col",
  246. ColPercentStacked: "col",
  247. Col3DClustered: "col",
  248. Col3D: "col",
  249. Col3DStacked: "col",
  250. Col3DPercentStacked: "col",
  251. Line: "standard",
  252. }
  253. orientation = map[bool]string{
  254. true: "maxMin",
  255. false: "minMax",
  256. }
  257. catAxPos = map[bool]string{
  258. true: "t",
  259. false: "b",
  260. }
  261. valAxPos = map[bool]string{
  262. true: "r",
  263. false: "l",
  264. }
  265. )
  266. // parseFormatChartSet provides a function to parse the format settings of the
  267. // chart with default value.
  268. func parseFormatChartSet(formatSet string) (*formatChart, error) {
  269. format := formatChart{
  270. Dimension: formatChartDimension{
  271. Width: 480,
  272. Height: 290,
  273. },
  274. Format: formatPicture{
  275. FPrintsWithSheet: true,
  276. FLocksWithSheet: false,
  277. NoChangeAspect: false,
  278. OffsetX: 0,
  279. OffsetY: 0,
  280. XScale: 1.0,
  281. YScale: 1.0,
  282. },
  283. Legend: formatChartLegend{
  284. Position: "bottom",
  285. ShowLegendKey: false,
  286. },
  287. Title: formatChartTitle{
  288. Name: " ",
  289. },
  290. ShowBlanksAs: "gap",
  291. }
  292. err := json.Unmarshal([]byte(formatSet), &format)
  293. return &format, err
  294. }
  295. // AddChart provides the method to add chart in a sheet by given chart format
  296. // set (such as offset, scale, aspect ratio setting and print settings) and
  297. // properties set. For example, create 3D clustered column chart with data
  298. // Sheet1!$A$29:$D$32:
  299. //
  300. // package main
  301. //
  302. // import (
  303. // "fmt"
  304. //
  305. // "github.com/360EntSecGroup-Skylar/excelize"
  306. // )
  307. //
  308. // func main() {
  309. // categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
  310. // values := map[string]int{"B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8}
  311. // xlsx := excelize.NewFile()
  312. // for k, v := range categories {
  313. // xlsx.SetCellValue("Sheet1", k, v)
  314. // }
  315. // for k, v := range values {
  316. // xlsx.SetCellValue("Sheet1", k, v)
  317. // }
  318. // xlsx.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}}`)
  319. // // Save xlsx file by the given path.
  320. // err := xlsx.SaveAs("./Book1.xlsx")
  321. // if err != nil {
  322. // fmt.Println(err)
  323. // }
  324. // }
  325. //
  326. // The following shows the type of chart supported by excelize:
  327. //
  328. // Type | Chart
  329. // ----------------------+------------------------------
  330. // area | 2D area chart
  331. // areaStacked | 2D stacked area chart
  332. // areaPercentStacked | 2D 100% stacked area chart
  333. // area3D | 3D area chart
  334. // area3DStacked | 3D stacked area chart
  335. // area3DPercentStacked | 3D 100% stacked area chart
  336. // bar | 2D clustered bar chart
  337. // barStacked | 2D stacked bar chart
  338. // barPercentStacked | 2D 100% stacked bar chart
  339. // bar3DClustered | 3D clustered bar chart
  340. // bar3DStacked | 3D stacked bar chart
  341. // bar3DPercentStacked | 3D 100% stacked bar chart
  342. // col | 2D clustered column chart
  343. // colStacked | 2D stacked column chart
  344. // colPercentStacked | 2D 100% stacked column chart
  345. // col3DClustered | 3D clustered column chart
  346. // col3D | 3D column chart
  347. // col3DStacked | 3D stacked column chart
  348. // col3DPercentStacked | 3D 100% stacked column chart
  349. // doughnut | doughnut chart
  350. // line | line chart
  351. // pie | pie chart
  352. // pie3D | 3D pie chart
  353. // radar | radar chart
  354. // scatter | scatter chart
  355. //
  356. // In Excel a chart series is a collection of information that defines which data is plotted such as values, axis labels and formatting.
  357. //
  358. // The series options that can be set are:
  359. //
  360. // name
  361. // categories
  362. // values
  363. //
  364. // 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
  365. //
  366. // 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.
  367. //
  368. // 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.
  369. //
  370. // Set properties of the chart legend. The options that can be set are:
  371. //
  372. // position
  373. // show_legend_key
  374. //
  375. // position: Set the position of the chart legend. The default legend position is right. The available positions are:
  376. //
  377. // top
  378. // bottom
  379. // left
  380. // right
  381. // top_right
  382. //
  383. // show_legend_key: Set the legend keys shall be shown in data labels. The default value is false.
  384. //
  385. // Set properties of the chart title. The properties that can be set are:
  386. //
  387. // title
  388. //
  389. // 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.
  390. //
  391. // 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:
  392. //
  393. // gap
  394. // span
  395. // zero
  396. //
  397. // gap: Specifies that blank values shall be left as a gap.
  398. //
  399. // sapn: Specifies that blank values shall be spanned with a line.
  400. //
  401. // zero: Specifies that blank values shall be treated as zero.
  402. //
  403. // Set chart offset, scale, aspect ratio setting and print settings by format, same as function AddPicture.
  404. //
  405. // Set the position of the chart plot area by plotarea. The properties that can be set are:
  406. //
  407. // show_bubble_size
  408. // show_cat_name
  409. // show_leader_lines
  410. // show_percent
  411. // show_series_name
  412. // show_val
  413. //
  414. // 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.
  415. //
  416. // 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.
  417. //
  418. // show_leader_lines: Specifies leader lines shall be shown for data labels. The show_leader_lines property is optional. The default value is false.
  419. //
  420. // show_percent: Specifies that the percentage shall be shown in a data label. The show_percent property is optional. The default value is false.
  421. //
  422. // 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.
  423. //
  424. // show_val: Specifies that the value shall be shown in a data label. The show_val property is optional. The default value is false.
  425. //
  426. // Set the primary horizontal and vertical axis options by x_axis and y_axis. The properties that can be set are:
  427. //
  428. // reverse_order
  429. // maximum
  430. // minimum
  431. //
  432. // 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.
  433. //
  434. // maximum: Specifies that the fixed maximum, 0 is auto. The maximum property is optional. The default value is auto.
  435. //
  436. // minimum: Specifies that the fixed minimum, 0 is auto. The minimum property is optional. The default value is auto.
  437. //
  438. // Set chart size by dimension property. The dimension property is optional. The default width is 480, and height is 290.
  439. //
  440. func (f *File) AddChart(sheet, cell, format string) error {
  441. formatSet, err := parseFormatChartSet(format)
  442. if err != nil {
  443. return err
  444. }
  445. // Read sheet data.
  446. xlsx := f.workSheetReader(sheet)
  447. // Add first picture for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder.
  448. drawingID := f.countDrawings() + 1
  449. chartID := f.countCharts() + 1
  450. drawingXML := "xl/drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
  451. drawingID, drawingXML = f.prepareDrawing(xlsx, drawingID, sheet, drawingXML)
  452. drawingRID := f.addDrawingRelationships(drawingID, SourceRelationshipChart, "../charts/chart"+strconv.Itoa(chartID)+".xml", "")
  453. f.addDrawingChart(sheet, drawingXML, cell, formatSet.Dimension.Width, formatSet.Dimension.Height, drawingRID, &formatSet.Format)
  454. f.addChart(formatSet)
  455. f.addContentTypePart(chartID, "chart")
  456. f.addContentTypePart(drawingID, "drawings")
  457. return err
  458. }
  459. // countCharts provides a function to get chart files count storage in the
  460. // folder xl/charts.
  461. func (f *File) countCharts() int {
  462. count := 0
  463. for k := range f.XLSX {
  464. if strings.Contains(k, "xl/charts/chart") {
  465. count++
  466. }
  467. }
  468. return count
  469. }
  470. // prepareDrawing provides a function to prepare drawing ID and XML by given
  471. // drawingID, worksheet name and default drawingXML.
  472. func (f *File) prepareDrawing(xlsx *xlsxWorksheet, drawingID int, sheet, drawingXML string) (int, string) {
  473. sheetRelationshipsDrawingXML := "../drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
  474. if xlsx.Drawing != nil {
  475. // The worksheet already has a picture or chart relationships, use the relationships drawing ../drawings/drawing%d.xml.
  476. sheetRelationshipsDrawingXML = f.getSheetRelationshipsTargetByID(sheet, xlsx.Drawing.RID)
  477. drawingID, _ = strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(sheetRelationshipsDrawingXML, "../drawings/drawing"), ".xml"))
  478. drawingXML = strings.Replace(sheetRelationshipsDrawingXML, "..", "xl", -1)
  479. } else {
  480. // Add first picture for given sheet.
  481. rID := f.addSheetRelationships(sheet, SourceRelationshipDrawingML, sheetRelationshipsDrawingXML, "")
  482. f.addSheetDrawing(sheet, rID)
  483. }
  484. return drawingID, drawingXML
  485. }
  486. // addChart provides a function to create chart as xl/charts/chart%d.xml by
  487. // given format sets.
  488. func (f *File) addChart(formatSet *formatChart) {
  489. count := f.countCharts()
  490. xlsxChartSpace := xlsxChartSpace{
  491. XMLNSc: NameSpaceDrawingMLChart,
  492. XMLNSa: NameSpaceDrawingML,
  493. XMLNSr: SourceRelationship,
  494. XMLNSc16r2: SourceRelationshipChart201506,
  495. Date1904: &attrValBool{Val: false},
  496. Lang: &attrValString{Val: "en-US"},
  497. RoundedCorners: &attrValBool{Val: false},
  498. Chart: cChart{
  499. Title: &cTitle{
  500. Tx: cTx{
  501. Rich: &cRich{
  502. P: aP{
  503. PPr: &aPPr{
  504. DefRPr: aRPr{
  505. Kern: 1200,
  506. Strike: "noStrike",
  507. U: "none",
  508. Sz: 1400,
  509. SolidFill: &aSolidFill{
  510. SchemeClr: &aSchemeClr{
  511. Val: "tx1",
  512. LumMod: &attrValInt{
  513. Val: 65000,
  514. },
  515. LumOff: &attrValInt{
  516. Val: 35000,
  517. },
  518. },
  519. },
  520. Ea: &aEa{
  521. Typeface: "+mn-ea",
  522. },
  523. Cs: &aCs{
  524. Typeface: "+mn-cs",
  525. },
  526. Latin: &aLatin{
  527. Typeface: "+mn-lt",
  528. },
  529. },
  530. },
  531. R: &aR{
  532. RPr: aRPr{
  533. Lang: "en-US",
  534. AltLang: "en-US",
  535. },
  536. T: formatSet.Title.Name,
  537. },
  538. },
  539. },
  540. },
  541. TxPr: cTxPr{
  542. P: aP{
  543. PPr: &aPPr{
  544. DefRPr: aRPr{
  545. Kern: 1200,
  546. U: "none",
  547. Sz: 14000,
  548. Strike: "noStrike",
  549. },
  550. },
  551. EndParaRPr: &aEndParaRPr{
  552. Lang: "en-US",
  553. },
  554. },
  555. },
  556. },
  557. View3D: &cView3D{
  558. RotX: &attrValInt{Val: chartView3DRotX[formatSet.Type]},
  559. RotY: &attrValInt{Val: chartView3DRotY[formatSet.Type]},
  560. DepthPercent: &attrValInt{Val: chartView3DDepthPercent[formatSet.Type]},
  561. RAngAx: &attrValInt{Val: chartView3DRAngAx[formatSet.Type]},
  562. },
  563. Floor: &cThicknessSpPr{
  564. Thickness: &attrValInt{Val: 0},
  565. },
  566. SideWall: &cThicknessSpPr{
  567. Thickness: &attrValInt{Val: 0},
  568. },
  569. BackWall: &cThicknessSpPr{
  570. Thickness: &attrValInt{Val: 0},
  571. },
  572. PlotArea: &cPlotArea{},
  573. Legend: &cLegend{
  574. LegendPos: &attrValString{Val: chartLegendPosition[formatSet.Legend.Position]},
  575. Overlay: &attrValBool{Val: false},
  576. },
  577. PlotVisOnly: &attrValBool{Val: false},
  578. DispBlanksAs: &attrValString{Val: formatSet.ShowBlanksAs},
  579. ShowDLblsOverMax: &attrValBool{Val: false},
  580. },
  581. SpPr: &cSpPr{
  582. SolidFill: &aSolidFill{
  583. SchemeClr: &aSchemeClr{Val: "bg1"},
  584. },
  585. Ln: &aLn{
  586. W: 9525,
  587. Cap: "flat",
  588. Cmpd: "sng",
  589. Algn: "ctr",
  590. SolidFill: &aSolidFill{
  591. SchemeClr: &aSchemeClr{Val: "tx1",
  592. LumMod: &attrValInt{
  593. Val: 15000,
  594. },
  595. LumOff: &attrValInt{
  596. Val: 85000,
  597. },
  598. },
  599. },
  600. },
  601. },
  602. PrintSettings: &cPrintSettings{
  603. PageMargins: &cPageMargins{
  604. B: 0.75,
  605. L: 0.7,
  606. R: 0.7,
  607. T: 0.7,
  608. Header: 0.3,
  609. Footer: 0.3,
  610. },
  611. },
  612. }
  613. plotAreaFunc := map[string]func(*formatChart) *cPlotArea{
  614. Area: f.drawBaseChart,
  615. AreaStacked: f.drawBaseChart,
  616. AreaPercentStacked: f.drawBaseChart,
  617. Area3D: f.drawBaseChart,
  618. Area3DStacked: f.drawBaseChart,
  619. Area3DPercentStacked: f.drawBaseChart,
  620. Bar: f.drawBaseChart,
  621. BarStacked: f.drawBaseChart,
  622. BarPercentStacked: f.drawBaseChart,
  623. Bar3DClustered: f.drawBaseChart,
  624. Bar3DStacked: f.drawBaseChart,
  625. Bar3DPercentStacked: f.drawBaseChart,
  626. Col: f.drawBaseChart,
  627. ColStacked: f.drawBaseChart,
  628. ColPercentStacked: f.drawBaseChart,
  629. Col3DClustered: f.drawBaseChart,
  630. Col3D: f.drawBaseChart,
  631. Col3DStacked: f.drawBaseChart,
  632. Col3DPercentStacked: f.drawBaseChart,
  633. Doughnut: f.drawDoughnutChart,
  634. Line: f.drawLineChart,
  635. Pie3D: f.drawPie3DChart,
  636. Pie: f.drawPieChart,
  637. Radar: f.drawRadarChart,
  638. Scatter: f.drawScatterChart,
  639. }
  640. xlsxChartSpace.Chart.PlotArea = plotAreaFunc[formatSet.Type](formatSet)
  641. chart, _ := xml.Marshal(xlsxChartSpace)
  642. media := "xl/charts/chart" + strconv.Itoa(count+1) + ".xml"
  643. f.saveFileList(media, chart)
  644. }
  645. // drawBaseChart provides a function to draw the c:plotArea element for bar,
  646. // and column series charts by given format sets.
  647. func (f *File) drawBaseChart(formatSet *formatChart) *cPlotArea {
  648. c := cCharts{
  649. BarDir: &attrValString{
  650. Val: "col",
  651. },
  652. Grouping: &attrValString{
  653. Val: "clustered",
  654. },
  655. VaryColors: &attrValBool{
  656. Val: true,
  657. },
  658. Ser: f.drawChartSeries(formatSet),
  659. DLbls: f.drawChartDLbls(formatSet),
  660. AxID: []*attrValInt{
  661. {Val: 754001152},
  662. {Val: 753999904},
  663. },
  664. }
  665. var ok bool
  666. c.BarDir.Val, ok = plotAreaChartBarDir[formatSet.Type]
  667. if !ok {
  668. c.BarDir = nil
  669. }
  670. c.Grouping.Val = plotAreaChartGrouping[formatSet.Type]
  671. if formatSet.Type == "colStacked" || formatSet.Type == "barStacked" || formatSet.Type == "barPercentStacked" || formatSet.Type == "colPercentStacked" || formatSet.Type == "areaPercentStacked" {
  672. c.Overlap = &attrValInt{Val: 100}
  673. }
  674. catAx := f.drawPlotAreaCatAx(formatSet)
  675. valAx := f.drawPlotAreaValAx(formatSet)
  676. charts := map[string]*cPlotArea{
  677. "area": {
  678. AreaChart: &c,
  679. CatAx: catAx,
  680. ValAx: valAx,
  681. },
  682. "areaStacked": {
  683. AreaChart: &c,
  684. CatAx: catAx,
  685. ValAx: valAx,
  686. },
  687. "areaPercentStacked": {
  688. AreaChart: &c,
  689. CatAx: catAx,
  690. ValAx: valAx,
  691. },
  692. "area3D": {
  693. Area3DChart: &c,
  694. CatAx: catAx,
  695. ValAx: valAx,
  696. },
  697. "area3DStacked": {
  698. Area3DChart: &c,
  699. CatAx: catAx,
  700. ValAx: valAx,
  701. },
  702. "area3DPercentStacked": {
  703. Area3DChart: &c,
  704. CatAx: catAx,
  705. ValAx: valAx,
  706. },
  707. "bar": {
  708. BarChart: &c,
  709. CatAx: catAx,
  710. ValAx: valAx,
  711. },
  712. "barStacked": {
  713. BarChart: &c,
  714. CatAx: catAx,
  715. ValAx: valAx,
  716. },
  717. "barPercentStacked": {
  718. BarChart: &c,
  719. CatAx: catAx,
  720. ValAx: valAx,
  721. },
  722. "bar3DClustered": {
  723. Bar3DChart: &c,
  724. CatAx: catAx,
  725. ValAx: valAx,
  726. },
  727. "bar3DStacked": {
  728. Bar3DChart: &c,
  729. CatAx: catAx,
  730. ValAx: valAx,
  731. },
  732. "bar3DPercentStacked": {
  733. Bar3DChart: &c,
  734. CatAx: catAx,
  735. ValAx: valAx,
  736. },
  737. "col": {
  738. BarChart: &c,
  739. CatAx: catAx,
  740. ValAx: valAx,
  741. },
  742. "colStacked": {
  743. BarChart: &c,
  744. CatAx: catAx,
  745. ValAx: valAx,
  746. },
  747. "colPercentStacked": {
  748. BarChart: &c,
  749. CatAx: catAx,
  750. ValAx: valAx,
  751. },
  752. "col3DClustered": {
  753. Bar3DChart: &c,
  754. CatAx: catAx,
  755. ValAx: valAx,
  756. },
  757. "col3D": {
  758. Bar3DChart: &c,
  759. CatAx: catAx,
  760. ValAx: valAx,
  761. },
  762. "col3DStacked": {
  763. Bar3DChart: &c,
  764. CatAx: catAx,
  765. ValAx: valAx,
  766. },
  767. "col3DPercentStacked": {
  768. Bar3DChart: &c,
  769. CatAx: catAx,
  770. ValAx: valAx,
  771. },
  772. }
  773. return charts[formatSet.Type]
  774. }
  775. // drawDoughnutChart provides a function to draw the c:plotArea element for
  776. // doughnut chart by given format sets.
  777. func (f *File) drawDoughnutChart(formatSet *formatChart) *cPlotArea {
  778. return &cPlotArea{
  779. DoughnutChart: &cCharts{
  780. VaryColors: &attrValBool{
  781. Val: true,
  782. },
  783. Ser: f.drawChartSeries(formatSet),
  784. HoleSize: &attrValInt{Val: 75},
  785. },
  786. }
  787. }
  788. // drawLineChart provides a function to draw the c:plotArea element for line
  789. // chart by given format sets.
  790. func (f *File) drawLineChart(formatSet *formatChart) *cPlotArea {
  791. return &cPlotArea{
  792. LineChart: &cCharts{
  793. Grouping: &attrValString{
  794. Val: plotAreaChartGrouping[formatSet.Type],
  795. },
  796. VaryColors: &attrValBool{
  797. Val: false,
  798. },
  799. Ser: f.drawChartSeries(formatSet),
  800. DLbls: f.drawChartDLbls(formatSet),
  801. Smooth: &attrValBool{
  802. Val: false,
  803. },
  804. AxID: []*attrValInt{
  805. {Val: 754001152},
  806. {Val: 753999904},
  807. },
  808. },
  809. CatAx: f.drawPlotAreaCatAx(formatSet),
  810. ValAx: f.drawPlotAreaValAx(formatSet),
  811. }
  812. }
  813. // drawPieChart provides a function to draw the c:plotArea element for pie
  814. // chart by given format sets.
  815. func (f *File) drawPieChart(formatSet *formatChart) *cPlotArea {
  816. return &cPlotArea{
  817. PieChart: &cCharts{
  818. VaryColors: &attrValBool{
  819. Val: true,
  820. },
  821. Ser: f.drawChartSeries(formatSet),
  822. },
  823. }
  824. }
  825. // drawPie3DChart provides a function to draw the c:plotArea element for 3D
  826. // pie chart by given format sets.
  827. func (f *File) drawPie3DChart(formatSet *formatChart) *cPlotArea {
  828. return &cPlotArea{
  829. Pie3DChart: &cCharts{
  830. VaryColors: &attrValBool{
  831. Val: true,
  832. },
  833. Ser: f.drawChartSeries(formatSet),
  834. },
  835. }
  836. }
  837. // drawRadarChart provides a function to draw the c:plotArea element for radar
  838. // chart by given format sets.
  839. func (f *File) drawRadarChart(formatSet *formatChart) *cPlotArea {
  840. return &cPlotArea{
  841. RadarChart: &cCharts{
  842. RadarStyle: &attrValString{
  843. Val: "marker",
  844. },
  845. VaryColors: &attrValBool{
  846. Val: false,
  847. },
  848. Ser: f.drawChartSeries(formatSet),
  849. DLbls: f.drawChartDLbls(formatSet),
  850. AxID: []*attrValInt{
  851. {Val: 754001152},
  852. {Val: 753999904},
  853. },
  854. },
  855. CatAx: f.drawPlotAreaCatAx(formatSet),
  856. ValAx: f.drawPlotAreaValAx(formatSet),
  857. }
  858. }
  859. // drawScatterChart provides a function to draw the c:plotArea element for
  860. // scatter chart by given format sets.
  861. func (f *File) drawScatterChart(formatSet *formatChart) *cPlotArea {
  862. return &cPlotArea{
  863. ScatterChart: &cCharts{
  864. ScatterStyle: &attrValString{
  865. Val: "smoothMarker", // line,lineMarker,marker,none,smooth,smoothMarker
  866. },
  867. VaryColors: &attrValBool{
  868. Val: false,
  869. },
  870. Ser: f.drawChartSeries(formatSet),
  871. DLbls: f.drawChartDLbls(formatSet),
  872. AxID: []*attrValInt{
  873. {Val: 754001152},
  874. {Val: 753999904},
  875. },
  876. },
  877. CatAx: f.drawPlotAreaCatAx(formatSet),
  878. ValAx: f.drawPlotAreaValAx(formatSet),
  879. }
  880. }
  881. // drawChartSeries provides a function to draw the c:ser element by given
  882. // format sets.
  883. func (f *File) drawChartSeries(formatSet *formatChart) *[]cSer {
  884. ser := []cSer{}
  885. for k := range formatSet.Series {
  886. ser = append(ser, cSer{
  887. IDx: &attrValInt{Val: k},
  888. Order: &attrValInt{Val: k},
  889. Tx: &cTx{
  890. StrRef: &cStrRef{
  891. F: formatSet.Series[k].Name,
  892. },
  893. },
  894. SpPr: f.drawChartSeriesSpPr(k, formatSet),
  895. Marker: f.drawChartSeriesMarker(k, formatSet),
  896. DPt: f.drawChartSeriesDPt(k, formatSet),
  897. DLbls: f.drawChartSeriesDLbls(formatSet),
  898. Cat: f.drawChartSeriesCat(formatSet.Series[k], formatSet),
  899. Val: f.drawChartSeriesVal(formatSet.Series[k], formatSet),
  900. XVal: f.drawChartSeriesXVal(formatSet.Series[k], formatSet),
  901. YVal: f.drawChartSeriesYVal(formatSet.Series[k], formatSet),
  902. })
  903. }
  904. return &ser
  905. }
  906. // drawChartSeriesSpPr provides a function to draw the c:spPr element by given
  907. // format sets.
  908. func (f *File) drawChartSeriesSpPr(i int, formatSet *formatChart) *cSpPr {
  909. spPrScatter := &cSpPr{
  910. Ln: &aLn{
  911. W: 25400,
  912. NoFill: " ",
  913. },
  914. }
  915. spPrLine := &cSpPr{
  916. Ln: &aLn{
  917. W: 25400,
  918. Cap: "rnd", // rnd, sq, flat
  919. SolidFill: &aSolidFill{
  920. SchemeClr: &aSchemeClr{Val: "accent" + strconv.Itoa(i+1)},
  921. },
  922. },
  923. }
  924. chartSeriesSpPr := map[string]*cSpPr{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: spPrLine, Pie: nil, Pie3D: nil, Radar: nil, Scatter: spPrScatter}
  925. return chartSeriesSpPr[formatSet.Type]
  926. }
  927. // drawChartSeriesDPt provides a function to draw the c:dPt element by given
  928. // data index and format sets.
  929. func (f *File) drawChartSeriesDPt(i int, formatSet *formatChart) []*cDPt {
  930. dpt := []*cDPt{{
  931. IDx: &attrValInt{Val: i},
  932. Bubble3D: &attrValBool{Val: false},
  933. SpPr: &cSpPr{
  934. SolidFill: &aSolidFill{
  935. SchemeClr: &aSchemeClr{Val: "accent" + strconv.Itoa(i+1)},
  936. },
  937. Ln: &aLn{
  938. W: 25400,
  939. Cap: "rnd",
  940. SolidFill: &aSolidFill{
  941. SchemeClr: &aSchemeClr{Val: "lt" + strconv.Itoa(i+1)},
  942. },
  943. },
  944. Sp3D: &aSp3D{
  945. ContourW: 25400,
  946. ContourClr: &aContourClr{
  947. SchemeClr: &aSchemeClr{Val: "lt" + strconv.Itoa(i+1)},
  948. },
  949. },
  950. },
  951. }}
  952. chartSeriesDPt := map[string][]*cDPt{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: nil, Pie: dpt, Pie3D: dpt, Radar: nil, Scatter: nil}
  953. return chartSeriesDPt[formatSet.Type]
  954. }
  955. // drawChartSeriesCat provides a function to draw the c:cat element by given
  956. // chart series and format sets.
  957. func (f *File) drawChartSeriesCat(v formatChartSeries, formatSet *formatChart) *cCat {
  958. cat := &cCat{
  959. StrRef: &cStrRef{
  960. F: v.Categories,
  961. },
  962. }
  963. chartSeriesCat := map[string]*cCat{Area: cat, AreaStacked: cat, AreaPercentStacked: cat, Area3D: cat, Area3DStacked: cat, Area3DPercentStacked: cat, Bar: cat, BarStacked: cat, BarPercentStacked: cat, Bar3DClustered: cat, Bar3DStacked: cat, Bar3DPercentStacked: cat, Col: cat, ColStacked: cat, ColPercentStacked: cat, Col3DClustered: cat, Col3D: cat, Col3DStacked: cat, Col3DPercentStacked: cat, Doughnut: cat, Line: cat, Pie: cat, Pie3D: cat, Radar: cat, Scatter: nil}
  964. return chartSeriesCat[formatSet.Type]
  965. }
  966. // drawChartSeriesVal provides a function to draw the c:val element by given
  967. // chart series and format sets.
  968. func (f *File) drawChartSeriesVal(v formatChartSeries, formatSet *formatChart) *cVal {
  969. val := &cVal{
  970. NumRef: &cNumRef{
  971. F: v.Values,
  972. },
  973. }
  974. chartSeriesVal := map[string]*cVal{Area: val, AreaStacked: val, AreaPercentStacked: val, Area3D: val, Area3DStacked: val, Area3DPercentStacked: val, Bar: val, BarStacked: val, BarPercentStacked: val, Bar3DClustered: val, Bar3DStacked: val, Bar3DPercentStacked: val, Col: val, ColStacked: val, ColPercentStacked: val, Col3DClustered: val, Col3D: val, Col3DStacked: val, Col3DPercentStacked: val, Doughnut: val, Line: val, Pie: val, Pie3D: val, Radar: val, Scatter: nil}
  975. return chartSeriesVal[formatSet.Type]
  976. }
  977. // drawChartSeriesMarker provides a function to draw the c:marker element by
  978. // given data index and format sets.
  979. func (f *File) drawChartSeriesMarker(i int, formatSet *formatChart) *cMarker {
  980. marker := &cMarker{
  981. Symbol: &attrValString{Val: "circle"},
  982. Size: &attrValInt{Val: 5},
  983. SpPr: &cSpPr{
  984. SolidFill: &aSolidFill{
  985. SchemeClr: &aSchemeClr{
  986. Val: "accent" + strconv.Itoa(i+1),
  987. },
  988. },
  989. Ln: &aLn{
  990. W: 9252,
  991. SolidFill: &aSolidFill{
  992. SchemeClr: &aSchemeClr{
  993. Val: "accent" + strconv.Itoa(i+1),
  994. },
  995. },
  996. },
  997. },
  998. }
  999. chartSeriesMarker := map[string]*cMarker{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: nil, Pie: nil, Pie3D: nil, Radar: nil, Scatter: marker}
  1000. return chartSeriesMarker[formatSet.Type]
  1001. }
  1002. // drawChartSeriesXVal provides a function to draw the c:xVal element by given
  1003. // chart series and format sets.
  1004. func (f *File) drawChartSeriesXVal(v formatChartSeries, formatSet *formatChart) *cCat {
  1005. cat := &cCat{
  1006. StrRef: &cStrRef{
  1007. F: v.Categories,
  1008. },
  1009. }
  1010. chartSeriesXVal := map[string]*cCat{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: nil, Pie: nil, Pie3D: nil, Radar: nil, Scatter: cat}
  1011. return chartSeriesXVal[formatSet.Type]
  1012. }
  1013. // drawChartSeriesYVal provides a function to draw the c:yVal element by given
  1014. // chart series and format sets.
  1015. func (f *File) drawChartSeriesYVal(v formatChartSeries, formatSet *formatChart) *cVal {
  1016. val := &cVal{
  1017. NumRef: &cNumRef{
  1018. F: v.Values,
  1019. },
  1020. }
  1021. chartSeriesYVal := map[string]*cVal{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: nil, Pie: nil, Pie3D: nil, Radar: nil, Scatter: val}
  1022. return chartSeriesYVal[formatSet.Type]
  1023. }
  1024. // drawChartDLbls provides a function to draw the c:dLbls element by given
  1025. // format sets.
  1026. func (f *File) drawChartDLbls(formatSet *formatChart) *cDLbls {
  1027. return &cDLbls{
  1028. ShowLegendKey: &attrValBool{Val: formatSet.Legend.ShowLegendKey},
  1029. ShowVal: &attrValBool{Val: formatSet.Plotarea.ShowVal},
  1030. ShowCatName: &attrValBool{Val: formatSet.Plotarea.ShowCatName},
  1031. ShowSerName: &attrValBool{Val: formatSet.Plotarea.ShowSerName},
  1032. ShowBubbleSize: &attrValBool{Val: formatSet.Plotarea.ShowBubbleSize},
  1033. ShowPercent: &attrValBool{Val: formatSet.Plotarea.ShowPercent},
  1034. ShowLeaderLines: &attrValBool{Val: formatSet.Plotarea.ShowLeaderLines},
  1035. }
  1036. }
  1037. // drawChartSeriesDLbls provides a function to draw the c:dLbls element by
  1038. // given format sets.
  1039. func (f *File) drawChartSeriesDLbls(formatSet *formatChart) *cDLbls {
  1040. dLbls := f.drawChartDLbls(formatSet)
  1041. chartSeriesDLbls := map[string]*cDLbls{Area: dLbls, AreaStacked: dLbls, AreaPercentStacked: dLbls, Area3D: dLbls, Area3DStacked: dLbls, Area3DPercentStacked: dLbls, Bar: dLbls, BarStacked: dLbls, BarPercentStacked: dLbls, Bar3DClustered: dLbls, Bar3DStacked: dLbls, Bar3DPercentStacked: dLbls, Col: dLbls, ColStacked: dLbls, ColPercentStacked: dLbls, Col3DClustered: dLbls, Col3D: dLbls, Col3DStacked: dLbls, Col3DPercentStacked: dLbls, Doughnut: dLbls, Line: dLbls, Pie: dLbls, Pie3D: dLbls, Radar: dLbls, Scatter: nil}
  1042. return chartSeriesDLbls[formatSet.Type]
  1043. }
  1044. // drawPlotAreaCatAx provides a function to draw the c:catAx element.
  1045. func (f *File) drawPlotAreaCatAx(formatSet *formatChart) []*cAxs {
  1046. min := &attrValFloat{Val: formatSet.XAxis.Minimum}
  1047. max := &attrValFloat{Val: formatSet.XAxis.Maximum}
  1048. if formatSet.XAxis.Minimum == 0 {
  1049. min = nil
  1050. }
  1051. if formatSet.XAxis.Maximum == 0 {
  1052. max = nil
  1053. }
  1054. return []*cAxs{
  1055. {
  1056. AxID: &attrValInt{Val: 754001152},
  1057. Scaling: &cScaling{
  1058. Orientation: &attrValString{Val: orientation[formatSet.XAxis.ReverseOrder]},
  1059. Max: max,
  1060. Min: min,
  1061. },
  1062. Delete: &attrValBool{Val: false},
  1063. AxPos: &attrValString{Val: catAxPos[formatSet.XAxis.ReverseOrder]},
  1064. NumFmt: &cNumFmt{
  1065. FormatCode: "General",
  1066. SourceLinked: true,
  1067. },
  1068. MajorTickMark: &attrValString{Val: "none"},
  1069. MinorTickMark: &attrValString{Val: "none"},
  1070. TickLblPos: &attrValString{Val: "nextTo"},
  1071. SpPr: f.drawPlotAreaSpPr(),
  1072. TxPr: f.drawPlotAreaTxPr(),
  1073. CrossAx: &attrValInt{Val: 753999904},
  1074. Crosses: &attrValString{Val: "autoZero"},
  1075. Auto: &attrValBool{Val: true},
  1076. LblAlgn: &attrValString{Val: "ctr"},
  1077. LblOffset: &attrValInt{Val: 100},
  1078. NoMultiLvlLbl: &attrValBool{Val: false},
  1079. },
  1080. }
  1081. }
  1082. // drawPlotAreaValAx provides a function to draw the c:valAx element.
  1083. func (f *File) drawPlotAreaValAx(formatSet *formatChart) []*cAxs {
  1084. min := &attrValFloat{Val: formatSet.YAxis.Minimum}
  1085. max := &attrValFloat{Val: formatSet.YAxis.Maximum}
  1086. if formatSet.YAxis.Minimum == 0 {
  1087. min = nil
  1088. }
  1089. if formatSet.YAxis.Maximum == 0 {
  1090. max = nil
  1091. }
  1092. return []*cAxs{
  1093. {
  1094. AxID: &attrValInt{Val: 753999904},
  1095. Scaling: &cScaling{
  1096. Orientation: &attrValString{Val: orientation[formatSet.YAxis.ReverseOrder]},
  1097. Max: max,
  1098. Min: min,
  1099. },
  1100. Delete: &attrValBool{Val: false},
  1101. AxPos: &attrValString{Val: valAxPos[formatSet.YAxis.ReverseOrder]},
  1102. NumFmt: &cNumFmt{
  1103. FormatCode: chartValAxNumFmtFormatCode[formatSet.Type],
  1104. SourceLinked: true,
  1105. },
  1106. MajorTickMark: &attrValString{Val: "none"},
  1107. MinorTickMark: &attrValString{Val: "none"},
  1108. TickLblPos: &attrValString{Val: "nextTo"},
  1109. SpPr: f.drawPlotAreaSpPr(),
  1110. TxPr: f.drawPlotAreaTxPr(),
  1111. CrossAx: &attrValInt{Val: 754001152},
  1112. Crosses: &attrValString{Val: "autoZero"},
  1113. CrossBetween: &attrValString{Val: chartValAxCrossBetween[formatSet.Type]},
  1114. },
  1115. }
  1116. }
  1117. // drawPlotAreaSpPr provides a function to draw the c:spPr element.
  1118. func (f *File) drawPlotAreaSpPr() *cSpPr {
  1119. return &cSpPr{
  1120. Ln: &aLn{
  1121. W: 9525,
  1122. Cap: "flat",
  1123. Cmpd: "sng",
  1124. Algn: "ctr",
  1125. SolidFill: &aSolidFill{
  1126. SchemeClr: &aSchemeClr{
  1127. Val: "tx1",
  1128. LumMod: &attrValInt{Val: 15000},
  1129. LumOff: &attrValInt{Val: 85000},
  1130. },
  1131. },
  1132. },
  1133. }
  1134. }
  1135. // drawPlotAreaTxPr provides a function to draw the c:txPr element.
  1136. func (f *File) drawPlotAreaTxPr() *cTxPr {
  1137. return &cTxPr{
  1138. BodyPr: aBodyPr{
  1139. Rot: -60000000,
  1140. SpcFirstLastPara: true,
  1141. VertOverflow: "ellipsis",
  1142. Vert: "horz",
  1143. Wrap: "square",
  1144. Anchor: "ctr",
  1145. AnchorCtr: true,
  1146. },
  1147. P: aP{
  1148. PPr: &aPPr{
  1149. DefRPr: aRPr{
  1150. Sz: 900,
  1151. B: false,
  1152. I: false,
  1153. U: "none",
  1154. Strike: "noStrike",
  1155. Kern: 1200,
  1156. Baseline: 0,
  1157. SolidFill: &aSolidFill{
  1158. SchemeClr: &aSchemeClr{
  1159. Val: "tx1",
  1160. LumMod: &attrValInt{Val: 15000},
  1161. LumOff: &attrValInt{Val: 85000},
  1162. },
  1163. },
  1164. Latin: &aLatin{Typeface: "+mn-lt"},
  1165. Ea: &aEa{Typeface: "+mn-ea"},
  1166. Cs: &aCs{Typeface: "+mn-cs"},
  1167. },
  1168. },
  1169. EndParaRPr: &aEndParaRPr{Lang: "en-US"},
  1170. },
  1171. }
  1172. }
  1173. // drawingParser provides a function to parse drawingXML. In order to solve
  1174. // the problem that the label structure is changed after serialization and
  1175. // deserialization, two different structures: decodeWsDr and encodeWsDr are
  1176. // defined.
  1177. func (f *File) drawingParser(path string) (*xlsxWsDr, int) {
  1178. cNvPrID := 1
  1179. if f.Drawings[path] == nil {
  1180. content := xlsxWsDr{}
  1181. content.A = NameSpaceDrawingML
  1182. content.Xdr = NameSpaceDrawingMLSpreadSheet
  1183. _, ok := f.XLSX[path]
  1184. if ok { // Append Model
  1185. decodeWsDr := decodeWsDr{}
  1186. _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(path)), &decodeWsDr)
  1187. content.R = decodeWsDr.R
  1188. cNvPrID = len(decodeWsDr.OneCellAnchor) + len(decodeWsDr.TwoCellAnchor) + 1
  1189. for _, v := range decodeWsDr.OneCellAnchor {
  1190. content.OneCellAnchor = append(content.OneCellAnchor, &xdrCellAnchor{
  1191. EditAs: v.EditAs,
  1192. GraphicFrame: v.Content,
  1193. })
  1194. }
  1195. for _, v := range decodeWsDr.TwoCellAnchor {
  1196. content.TwoCellAnchor = append(content.TwoCellAnchor, &xdrCellAnchor{
  1197. EditAs: v.EditAs,
  1198. GraphicFrame: v.Content,
  1199. })
  1200. }
  1201. }
  1202. f.Drawings[path] = &content
  1203. }
  1204. return f.Drawings[path], cNvPrID
  1205. }
  1206. // addDrawingChart provides a function to add chart graphic frame by given
  1207. // sheet, drawingXML, cell, width, height, relationship index and format sets.
  1208. func (f *File) addDrawingChart(sheet, drawingXML, cell string, width, height, rID int, formatSet *formatPicture) {
  1209. col, row := MustCellNameToCoordinates(cell)
  1210. colIdx := col - 1
  1211. rowIdx := row - 1
  1212. width = int(float64(width) * formatSet.XScale)
  1213. height = int(float64(height) * formatSet.YScale)
  1214. colStart, rowStart, _, _, colEnd, rowEnd, x2, y2 :=
  1215. f.positionObjectPixels(sheet, colIdx, rowIdx, formatSet.OffsetX, formatSet.OffsetY, width, height)
  1216. content, cNvPrID := f.drawingParser(drawingXML)
  1217. twoCellAnchor := xdrCellAnchor{}
  1218. twoCellAnchor.EditAs = formatSet.Positioning
  1219. from := xlsxFrom{}
  1220. from.Col = colStart
  1221. from.ColOff = formatSet.OffsetX * EMU
  1222. from.Row = rowStart
  1223. from.RowOff = formatSet.OffsetY * EMU
  1224. to := xlsxTo{}
  1225. to.Col = colEnd
  1226. to.ColOff = x2 * EMU
  1227. to.Row = rowEnd
  1228. to.RowOff = y2 * EMU
  1229. twoCellAnchor.From = &from
  1230. twoCellAnchor.To = &to
  1231. graphicFrame := xlsxGraphicFrame{
  1232. NvGraphicFramePr: xlsxNvGraphicFramePr{
  1233. CNvPr: &xlsxCNvPr{
  1234. ID: f.countCharts() + f.countMedia() + 1,
  1235. Name: "Chart " + strconv.Itoa(cNvPrID),
  1236. },
  1237. },
  1238. Graphic: &xlsxGraphic{
  1239. GraphicData: &xlsxGraphicData{
  1240. URI: NameSpaceDrawingMLChart,
  1241. Chart: &xlsxChart{
  1242. C: NameSpaceDrawingMLChart,
  1243. R: SourceRelationship,
  1244. RID: "rId" + strconv.Itoa(rID),
  1245. },
  1246. },
  1247. },
  1248. }
  1249. graphic, _ := xml.Marshal(graphicFrame)
  1250. twoCellAnchor.GraphicFrame = string(graphic)
  1251. twoCellAnchor.ClientData = &xdrClientData{
  1252. FLocksWithSheet: formatSet.FLocksWithSheet,
  1253. FPrintsWithSheet: formatSet.FPrintsWithSheet,
  1254. }
  1255. content.TwoCellAnchor = append(content.TwoCellAnchor, &twoCellAnchor)
  1256. f.Drawings[drawingXML] = content
  1257. }