chart.go 36 KB

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