AddChart provides the method to add chart in a sheet by given chart format set (such as offset, scale, aspect ratio setting and print settings) and properties set. For example, create 3D clustered column chart with data Sheet1!$E$1:$L$15: package main import ( "fmt" "github.com/xuri/e
(sheet, cell string, chart *Chart, combo ...*Chart)
| 1188 | // } |
| 1189 | // } |
| 1190 | func (f *File) AddChart(sheet, cell string, chart *Chart, combo ...*Chart) error { |
| 1191 | // Read worksheet data |
| 1192 | ws, err := f.workSheetReader(sheet) |
| 1193 | if err != nil { |
| 1194 | return err |
| 1195 | } |
| 1196 | opts, comboCharts, err := f.getChartOptions(chart, combo) |
| 1197 | if err != nil { |
| 1198 | return err |
| 1199 | } |
| 1200 | // Add first picture for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder. |
| 1201 | drawingID := f.countDrawings() + 1 |
| 1202 | chartID := f.countCharts() + 1 |
| 1203 | drawingXML := "xl/drawings/drawing" + strconv.Itoa(drawingID) + ".xml" |
| 1204 | drawingID, drawingXML = f.prepareDrawing(ws, drawingID, sheet, drawingXML) |
| 1205 | drawingRels := "xl/drawings/_rels/drawing" + strconv.Itoa(drawingID) + ".xml.rels" |
| 1206 | drawingRID := f.addRels(drawingRels, SourceRelationshipChart, "../charts/chart"+strconv.Itoa(chartID)+".xml", "") |
| 1207 | err = f.addDrawingChart(sheet, drawingXML, cell, int(opts.Dimension.Width), int(opts.Dimension.Height), drawingRID, &opts.Format) |
| 1208 | if err != nil { |
| 1209 | return err |
| 1210 | } |
| 1211 | f.addChart(opts, comboCharts) |
| 1212 | if err = f.addContentTypePart(chartID, "chart"); err != nil { |
| 1213 | return err |
| 1214 | } |
| 1215 | _ = f.addContentTypePart(drawingID, "drawings") |
| 1216 | f.addSheetNameSpace(sheet, SourceRelationship) |
| 1217 | return err |
| 1218 | } |
| 1219 | |
| 1220 | // AddChartSheet provides the method to create a chartsheet by given chart |
| 1221 | // format set (such as offset, scale, aspect ratio setting and print settings) |