2019-01-01 13:20:14 +08:00
// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of
2018-09-14 00:44:23 +08:00
// this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
//
// Package excelize providing a set of functions that allow you to write to
// and read from XLSX files. Support reads and writes XLSX file generated by
// Microsoft Excel™ 2007 and later. Support save file without losing original
2019-08-11 00:36:14 +08:00
// charts of XLSX. This library needs Go version 1.10 or later.
2018-09-14 00:58:48 +08:00
2017-04-23 00:10:23 +08:00
package excelize
import (
"encoding/json"
"encoding/xml"
2019-06-14 00:05:10 +08:00
"errors"
2017-04-23 00:10:23 +08:00
"strconv"
"strings"
)
// This section defines the currently supported chart types.
const (
2019-06-14 00:05:10 +08:00
Area = "area"
AreaStacked = "areaStacked"
AreaPercentStacked = "areaPercentStacked"
Area3D = "area3D"
Area3DStacked = "area3DStacked"
Area3DPercentStacked = "area3DPercentStacked"
Bar = "bar"
BarStacked = "barStacked"
BarPercentStacked = "barPercentStacked"
Bar3DClustered = "bar3DClustered"
Bar3DStacked = "bar3DStacked"
Bar3DPercentStacked = "bar3DPercentStacked"
Bar3DConeClustered = "bar3DConeClustered"
Bar3DConeStacked = "bar3DConeStacked"
Bar3DConePercentStacked = "bar3DConePercentStacked"
Bar3DPyramidClustered = "bar3DPyramidClustered"
Bar3DPyramidStacked = "bar3DPyramidStacked"
Bar3DPyramidPercentStacked = "bar3DPyramidPercentStacked"
Bar3DCylinderClustered = "bar3DCylinderClustered"
Bar3DCylinderStacked = "bar3DCylinderStacked"
Bar3DCylinderPercentStacked = "bar3DCylinderPercentStacked"
Col = "col"
ColStacked = "colStacked"
ColPercentStacked = "colPercentStacked"
Col3D = "col3D"
Col3DClustered = "col3DClustered"
Col3DStacked = "col3DStacked"
Col3DPercentStacked = "col3DPercentStacked"
Col3DCone = "col3DCone"
Col3DConeClustered = "col3DConeClustered"
Col3DConeStacked = "col3DConeStacked"
Col3DConePercentStacked = "col3DConePercentStacked"
Col3DPyramid = "col3DPyramid"
Col3DPyramidClustered = "col3DPyramidClustered"
Col3DPyramidStacked = "col3DPyramidStacked"
Col3DPyramidPercentStacked = "col3DPyramidPercentStacked"
Col3DCylinder = "col3DCylinder"
Col3DCylinderClustered = "col3DCylinderClustered"
Col3DCylinderStacked = "col3DCylinderStacked"
Col3DCylinderPercentStacked = "col3DCylinderPercentStacked"
Doughnut = "doughnut"
Line = "line"
Pie = "pie"
Pie3D = "pie3D"
Radar = "radar"
Scatter = "scatter"
2019-06-15 20:55:56 +08:00
Surface3D = "surface3D"
WireframeSurface3D = "wireframeSurface3D"
Contour = "contour"
WireframeContour = "wireframeContour"
2019-06-19 00:01:18 +08:00
Bubble = "bubble"
Bubble3D = "bubble3D"
2017-04-23 00:10:23 +08:00
)
// This section defines the default value of chart properties.
var (
2017-09-30 17:07:59 +08:00
chartView3DRotX = map [ string ] int {
2019-06-14 00:05:10 +08:00
Area : 0 ,
AreaStacked : 0 ,
AreaPercentStacked : 0 ,
Area3D : 15 ,
Area3DStacked : 15 ,
Area3DPercentStacked : 15 ,
Bar : 0 ,
BarStacked : 0 ,
BarPercentStacked : 0 ,
Bar3DClustered : 15 ,
Bar3DStacked : 15 ,
Bar3DPercentStacked : 15 ,
Bar3DConeClustered : 15 ,
Bar3DConeStacked : 15 ,
Bar3DConePercentStacked : 15 ,
Bar3DPyramidClustered : 15 ,
Bar3DPyramidStacked : 15 ,
Bar3DPyramidPercentStacked : 15 ,
Bar3DCylinderClustered : 15 ,
Bar3DCylinderStacked : 15 ,
Bar3DCylinderPercentStacked : 15 ,
Col : 0 ,
ColStacked : 0 ,
ColPercentStacked : 0 ,
Col3D : 15 ,
Col3DClustered : 15 ,
Col3DStacked : 15 ,
Col3DPercentStacked : 15 ,
Col3DCone : 15 ,
Col3DConeClustered : 15 ,
Col3DConeStacked : 15 ,
Col3DConePercentStacked : 15 ,
Col3DPyramid : 15 ,
Col3DPyramidClustered : 15 ,
Col3DPyramidStacked : 15 ,
Col3DPyramidPercentStacked : 15 ,
Col3DCylinder : 15 ,
Col3DCylinderClustered : 15 ,
Col3DCylinderStacked : 15 ,
Col3DCylinderPercentStacked : 15 ,
Doughnut : 0 ,
Line : 0 ,
Pie : 0 ,
Pie3D : 30 ,
Radar : 0 ,
Scatter : 0 ,
2019-06-15 20:55:56 +08:00
Surface3D : 15 ,
WireframeSurface3D : 15 ,
Contour : 90 ,
WireframeContour : 90 ,
2017-09-30 17:07:59 +08:00
}
chartView3DRotY = map [ string ] int {
2019-06-14 00:05:10 +08:00
Area : 0 ,
AreaStacked : 0 ,
AreaPercentStacked : 0 ,
Area3D : 20 ,
Area3DStacked : 20 ,
Area3DPercentStacked : 20 ,
Bar : 0 ,
BarStacked : 0 ,
BarPercentStacked : 0 ,
Bar3DClustered : 20 ,
Bar3DStacked : 20 ,
Bar3DPercentStacked : 20 ,
Bar3DConeClustered : 20 ,
Bar3DConeStacked : 20 ,
Bar3DConePercentStacked : 20 ,
Bar3DPyramidClustered : 20 ,
Bar3DPyramidStacked : 20 ,
Bar3DPyramidPercentStacked : 20 ,
Bar3DCylinderClustered : 20 ,
Bar3DCylinderStacked : 20 ,
Bar3DCylinderPercentStacked : 20 ,
Col : 0 ,
ColStacked : 0 ,
ColPercentStacked : 0 ,
Col3D : 20 ,
Col3DClustered : 20 ,
Col3DStacked : 20 ,
Col3DPercentStacked : 20 ,
Col3DCone : 20 ,
Col3DConeClustered : 20 ,
Col3DConeStacked : 20 ,
Col3DConePercentStacked : 20 ,
Col3DPyramid : 20 ,
Col3DPyramidClustered : 20 ,
Col3DPyramidStacked : 20 ,
Col3DPyramidPercentStacked : 20 ,
Col3DCylinder : 20 ,
Col3DCylinderClustered : 20 ,
Col3DCylinderStacked : 20 ,
Col3DCylinderPercentStacked : 20 ,
Doughnut : 0 ,
Line : 0 ,
Pie : 0 ,
Pie3D : 0 ,
Radar : 0 ,
Scatter : 0 ,
2019-06-15 20:55:56 +08:00
Surface3D : 20 ,
WireframeSurface3D : 20 ,
Contour : 0 ,
WireframeContour : 0 ,
2017-09-30 17:07:59 +08:00
}
chartView3DDepthPercent = map [ string ] int {
2019-06-14 00:05:10 +08:00
Area : 100 ,
AreaStacked : 100 ,
AreaPercentStacked : 100 ,
Area3D : 100 ,
Area3DStacked : 100 ,
Area3DPercentStacked : 100 ,
Bar : 100 ,
BarStacked : 100 ,
BarPercentStacked : 100 ,
Bar3DClustered : 100 ,
Bar3DStacked : 100 ,
Bar3DPercentStacked : 100 ,
Bar3DConeClustered : 100 ,
Bar3DConeStacked : 100 ,
Bar3DConePercentStacked : 100 ,
Bar3DPyramidClustered : 100 ,
Bar3DPyramidStacked : 100 ,
Bar3DPyramidPercentStacked : 100 ,
Bar3DCylinderClustered : 100 ,
Bar3DCylinderStacked : 100 ,
Bar3DCylinderPercentStacked : 100 ,
Col : 100 ,
ColStacked : 100 ,
ColPercentStacked : 100 ,
Col3D : 100 ,
Col3DClustered : 100 ,
Col3DStacked : 100 ,
Col3DPercentStacked : 100 ,
Col3DCone : 100 ,
Col3DConeClustered : 100 ,
Col3DConeStacked : 100 ,
Col3DConePercentStacked : 100 ,
Col3DPyramid : 100 ,
Col3DPyramidClustered : 100 ,
Col3DPyramidStacked : 100 ,
Col3DPyramidPercentStacked : 100 ,
Col3DCylinder : 100 ,
Col3DCylinderClustered : 100 ,
Col3DCylinderStacked : 100 ,
Col3DCylinderPercentStacked : 100 ,
Doughnut : 100 ,
Line : 100 ,
Pie : 100 ,
Pie3D : 100 ,
Radar : 100 ,
Scatter : 100 ,
2019-06-15 20:55:56 +08:00
Surface3D : 100 ,
WireframeSurface3D : 100 ,
Contour : 100 ,
WireframeContour : 100 ,
2019-06-19 00:01:18 +08:00
Bubble : 100 ,
Bubble3D : 100 ,
2019-06-15 20:55:56 +08:00
}
chartView3DPerspective = map [ string ] int {
Contour : 0 ,
WireframeContour : 0 ,
2017-09-30 17:07:59 +08:00
}
chartView3DRAngAx = map [ string ] int {
2019-06-14 00:05:10 +08:00
Area : 0 ,
AreaStacked : 0 ,
AreaPercentStacked : 0 ,
Area3D : 1 ,
Area3DStacked : 1 ,
Area3DPercentStacked : 1 ,
Bar : 0 ,
BarStacked : 0 ,
BarPercentStacked : 0 ,
Bar3DClustered : 1 ,
Bar3DStacked : 1 ,
Bar3DPercentStacked : 1 ,
Bar3DConeClustered : 1 ,
Bar3DConeStacked : 1 ,
Bar3DConePercentStacked : 1 ,
Bar3DPyramidClustered : 1 ,
Bar3DPyramidStacked : 1 ,
Bar3DPyramidPercentStacked : 1 ,
Bar3DCylinderClustered : 1 ,
Bar3DCylinderStacked : 1 ,
Bar3DCylinderPercentStacked : 1 ,
Col : 0 ,
ColStacked : 0 ,
ColPercentStacked : 0 ,
Col3D : 1 ,
Col3DClustered : 1 ,
Col3DStacked : 1 ,
Col3DPercentStacked : 1 ,
Col3DCone : 1 ,
Col3DConeClustered : 1 ,
Col3DConeStacked : 1 ,
Col3DConePercentStacked : 1 ,
Col3DPyramid : 1 ,
Col3DPyramidClustered : 1 ,
Col3DPyramidStacked : 1 ,
Col3DPyramidPercentStacked : 1 ,
Col3DCylinder : 1 ,
Col3DCylinderClustered : 1 ,
Col3DCylinderStacked : 1 ,
Col3DCylinderPercentStacked : 1 ,
Doughnut : 0 ,
Line : 0 ,
Pie : 0 ,
Pie3D : 0 ,
Radar : 0 ,
Scatter : 0 ,
2019-06-15 20:55:56 +08:00
Surface3D : 0 ,
WireframeSurface3D : 0 ,
Contour : 0 ,
2019-06-19 00:01:18 +08:00
Bubble : 0 ,
Bubble3D : 0 ,
2018-01-08 23:03:59 +08:00
}
2017-09-30 17:07:59 +08:00
chartLegendPosition = map [ string ] string {
"bottom" : "b" ,
"left" : "l" ,
"right" : "r" ,
"top" : "t" ,
"top_right" : "tr" ,
}
2018-01-08 23:03:59 +08:00
chartValAxNumFmtFormatCode = map [ string ] string {
2019-06-14 00:05:10 +08:00
Area : "General" ,
AreaStacked : "General" ,
AreaPercentStacked : "0%" ,
Area3D : "General" ,
Area3DStacked : "General" ,
Area3DPercentStacked : "0%" ,
Bar : "General" ,
BarStacked : "General" ,
BarPercentStacked : "0%" ,
Bar3DClustered : "General" ,
Bar3DStacked : "General" ,
Bar3DPercentStacked : "0%" ,
Bar3DConeClustered : "General" ,
Bar3DConeStacked : "General" ,
Bar3DConePercentStacked : "0%" ,
Bar3DPyramidClustered : "General" ,
Bar3DPyramidStacked : "General" ,
Bar3DPyramidPercentStacked : "0%" ,
Bar3DCylinderClustered : "General" ,
Bar3DCylinderStacked : "General" ,
Bar3DCylinderPercentStacked : "0%" ,
Col : "General" ,
ColStacked : "General" ,
ColPercentStacked : "0%" ,
Col3D : "General" ,
Col3DClustered : "General" ,
Col3DStacked : "General" ,
Col3DPercentStacked : "0%" ,
Col3DCone : "General" ,
Col3DConeClustered : "General" ,
Col3DConeStacked : "General" ,
Col3DConePercentStacked : "0%" ,
Col3DPyramid : "General" ,
Col3DPyramidClustered : "General" ,
Col3DPyramidStacked : "General" ,
Col3DPyramidPercentStacked : "0%" ,
Col3DCylinder : "General" ,
Col3DCylinderClustered : "General" ,
Col3DCylinderStacked : "General" ,
Col3DCylinderPercentStacked : "0%" ,
Doughnut : "General" ,
Line : "General" ,
Pie : "General" ,
Pie3D : "General" ,
Radar : "General" ,
Scatter : "General" ,
2019-06-15 20:55:56 +08:00
Surface3D : "General" ,
WireframeSurface3D : "General" ,
Contour : "General" ,
WireframeContour : "General" ,
2019-06-19 00:01:18 +08:00
Bubble : "General" ,
Bubble3D : "General" ,
2018-12-23 00:07:47 +08:00
}
chartValAxCrossBetween = map [ string ] string {
2019-06-14 00:05:10 +08:00
Area : "midCat" ,
AreaStacked : "midCat" ,
AreaPercentStacked : "midCat" ,
Area3D : "midCat" ,
Area3DStacked : "midCat" ,
Area3DPercentStacked : "midCat" ,
Bar : "between" ,
BarStacked : "between" ,
BarPercentStacked : "between" ,
Bar3DClustered : "between" ,
Bar3DStacked : "between" ,
Bar3DPercentStacked : "between" ,
Bar3DConeClustered : "between" ,
Bar3DConeStacked : "between" ,
Bar3DConePercentStacked : "between" ,
Bar3DPyramidClustered : "between" ,
Bar3DPyramidStacked : "between" ,
Bar3DPyramidPercentStacked : "between" ,
Bar3DCylinderClustered : "between" ,
Bar3DCylinderStacked : "between" ,
Bar3DCylinderPercentStacked : "between" ,
Col : "between" ,
ColStacked : "between" ,
ColPercentStacked : "between" ,
Col3D : "between" ,
Col3DClustered : "between" ,
Col3DStacked : "between" ,
Col3DPercentStacked : "between" ,
Col3DCone : "between" ,
Col3DConeClustered : "between" ,
Col3DConeStacked : "between" ,
Col3DConePercentStacked : "between" ,
Col3DPyramid : "between" ,
Col3DPyramidClustered : "between" ,
Col3DPyramidStacked : "between" ,
Col3DPyramidPercentStacked : "between" ,
Col3DCylinder : "between" ,
Col3DCylinderClustered : "between" ,
Col3DCylinderStacked : "between" ,
Col3DCylinderPercentStacked : "between" ,
Doughnut : "between" ,
Line : "between" ,
Pie : "between" ,
Pie3D : "between" ,
Radar : "between" ,
Scatter : "between" ,
2019-06-15 20:55:56 +08:00
Surface3D : "midCat" ,
WireframeSurface3D : "midCat" ,
Contour : "midCat" ,
WireframeContour : "midCat" ,
2019-06-19 00:01:18 +08:00
Bubble : "midCat" ,
Bubble3D : "midCat" ,
2018-01-08 23:03:59 +08:00
}
plotAreaChartGrouping = map [ string ] string {
2019-06-14 00:05:10 +08:00
Area : "standard" ,
AreaStacked : "stacked" ,
AreaPercentStacked : "percentStacked" ,
Area3D : "standard" ,
Area3DStacked : "stacked" ,
Area3DPercentStacked : "percentStacked" ,
Bar : "clustered" ,
BarStacked : "stacked" ,
BarPercentStacked : "percentStacked" ,
Bar3DClustered : "clustered" ,
Bar3DStacked : "stacked" ,
Bar3DPercentStacked : "percentStacked" ,
Bar3DConeClustered : "clustered" ,
Bar3DConeStacked : "stacked" ,
Bar3DConePercentStacked : "percentStacked" ,
Bar3DPyramidClustered : "clustered" ,
Bar3DPyramidStacked : "stacked" ,
Bar3DPyramidPercentStacked : "percentStacked" ,
Bar3DCylinderClustered : "clustered" ,
Bar3DCylinderStacked : "stacked" ,
Bar3DCylinderPercentStacked : "percentStacked" ,
Col : "clustered" ,
ColStacked : "stacked" ,
ColPercentStacked : "percentStacked" ,
Col3D : "standard" ,
Col3DClustered : "clustered" ,
Col3DStacked : "stacked" ,
Col3DPercentStacked : "percentStacked" ,
Col3DCone : "standard" ,
Col3DConeClustered : "clustered" ,
Col3DConeStacked : "stacked" ,
Col3DConePercentStacked : "percentStacked" ,
Col3DPyramid : "standard" ,
Col3DPyramidClustered : "clustered" ,
Col3DPyramidStacked : "stacked" ,
Col3DPyramidPercentStacked : "percentStacked" ,
Col3DCylinder : "standard" ,
Col3DCylinderClustered : "clustered" ,
Col3DCylinderStacked : "stacked" ,
Col3DCylinderPercentStacked : "percentStacked" ,
Line : "standard" ,
2018-03-05 21:23:52 +08:00
}
plotAreaChartBarDir = map [ string ] string {
2019-06-14 00:05:10 +08:00
Bar : "bar" ,
BarStacked : "bar" ,
BarPercentStacked : "bar" ,
Bar3DClustered : "bar" ,
Bar3DStacked : "bar" ,
Bar3DPercentStacked : "bar" ,
Bar3DConeClustered : "bar" ,
Bar3DConeStacked : "bar" ,
Bar3DConePercentStacked : "bar" ,
Bar3DPyramidClustered : "bar" ,
Bar3DPyramidStacked : "bar" ,
Bar3DPyramidPercentStacked : "bar" ,
Bar3DCylinderClustered : "bar" ,
Bar3DCylinderStacked : "bar" ,
Bar3DCylinderPercentStacked : "bar" ,
Col : "col" ,
ColStacked : "col" ,
ColPercentStacked : "col" ,
Col3D : "col" ,
Col3DClustered : "col" ,
Col3DStacked : "col" ,
Col3DPercentStacked : "col" ,
Col3DCone : "col" ,
Col3DConeStacked : "col" ,
Col3DConeClustered : "col" ,
Col3DConePercentStacked : "col" ,
Col3DPyramid : "col" ,
Col3DPyramidClustered : "col" ,
Col3DPyramidStacked : "col" ,
Col3DPyramidPercentStacked : "col" ,
Col3DCylinder : "col" ,
Col3DCylinderClustered : "col" ,
Col3DCylinderStacked : "col" ,
Col3DCylinderPercentStacked : "col" ,
Line : "standard" ,
2018-01-08 23:03:59 +08:00
}
2018-03-29 20:17:07 +08:00
orientation = map [ bool ] string {
true : "maxMin" ,
false : "minMax" ,
}
catAxPos = map [ bool ] string {
true : "t" ,
false : "b" ,
}
valAxPos = map [ bool ] string {
true : "r" ,
false : "l" ,
}
2019-06-15 20:55:56 +08:00
valTickLblPos = map [ string ] string {
Contour : "none" ,
WireframeContour : "none" ,
}
2017-04-23 00:10:23 +08:00
)
2018-08-06 10:21:24 +08:00
// parseFormatChartSet provides a function to parse the format settings of the
2017-04-23 00:10:23 +08:00
// chart with default value.
2018-05-27 11:25:55 +08:00
func parseFormatChartSet ( formatSet string ) ( * formatChart , error ) {
2017-04-23 00:10:23 +08:00
format := formatChart {
2018-05-09 19:44:04 +08:00
Dimension : formatChartDimension {
Width : 480 ,
Height : 290 ,
} ,
2017-04-23 00:10:23 +08:00
Format : formatPicture {
FPrintsWithSheet : true ,
FLocksWithSheet : false ,
NoChangeAspect : false ,
OffsetX : 0 ,
OffsetY : 0 ,
XScale : 1.0 ,
YScale : 1.0 ,
} ,
Legend : formatChartLegend {
Position : "bottom" ,
ShowLegendKey : false ,
} ,
Title : formatChartTitle {
Name : " " ,
} ,
ShowBlanksAs : "gap" ,
}
2018-05-27 11:25:55 +08:00
err := json . Unmarshal ( [ ] byte ( formatSet ) , & format )
return & format , err
2017-04-23 00:10:23 +08:00
}
// 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
2018-03-05 21:23:52 +08:00
// properties set. For example, create 3D clustered column chart with data
2017-04-30 20:03:43 +08:00
// Sheet1!$A$29:$D$32:
2017-04-23 00:10:23 +08:00
//
// package main
//
// import (
// "fmt"
//
2019-04-30 18:39:27 +08:00
// "github.com/360EntSecGroup-Skylar/excelize/v2"
2017-04-23 00:10:23 +08:00
// )
//
// func main() {
2017-04-23 00:39:14 +08:00
// categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
// values := map[string]int{"B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8}
2019-04-21 00:04:42 +08:00
// f := excelize.NewFile()
2017-04-23 00:39:14 +08:00
// for k, v := range categories {
2019-04-21 00:04:42 +08:00
// f.SetCellValue("Sheet1", k, v)
2017-04-23 00:39:14 +08:00
// }
// for k, v := range values {
2019-04-21 00:04:42 +08:00
// f.SetCellValue("Sheet1", k, v)
// }
// err := f.AddChart("Sheet1", "E1", `{"type":"col3DClustered","dimension":{"width":640,"height":480},"series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"bottom","show_legend_key":false},"title":{"name":"Fruit 3D Clustered Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero","x_axis":{"reverse_order":true},"y_axis":{"maximum":7.5,"minimum":0.5}}`)
// if err != nil {
// fmt.Println(err)
// return
2017-04-23 00:39:14 +08:00
// }
2017-04-23 00:10:23 +08:00
// // Save xlsx file by the given path.
2019-04-21 00:04:42 +08:00
// err = xlsx.SaveAs("./Book1.xlsx")
2017-04-23 00:10:23 +08:00
// if err != nil {
// fmt.Println(err)
// }
// }
//
// The following shows the type of chart supported by excelize:
//
2019-06-14 00:05:10 +08:00
// Type | Chart
// -----------------------------+------------------------------
// area | 2D area chart
// areaStacked | 2D stacked area chart
// areaPercentStacked | 2D 100% stacked area chart
// area3D | 3D area chart
// area3DStacked | 3D stacked area chart
// area3DPercentStacked | 3D 100% stacked area chart
// bar | 2D clustered bar chart
// barStacked | 2D stacked bar chart
// barPercentStacked | 2D 100% stacked bar chart
// bar3DClustered | 3D clustered bar chart
// bar3DStacked | 3D stacked bar chart
// bar3DPercentStacked | 3D 100% stacked bar chart
// bar3DConeClustered | 3D cone clustered bar chart
// bar3DConeStacked | 3D cone stacked bar chart
// bar3DConePercentStacked | 3D cone percent bar chart
// bar3DPyramidClustered | 3D pyramid clustered bar chart
// bar3DPyramidStacked | 3D pyramid stacked bar chart
// bar3DPyramidPercentStacked | 3D pyramid percent stacked bar chart
// bar3DCylinderClustered | 3D cylinder clustered bar chart
// bar3DCylinderStacked | 3D cylinder stacked bar chart
// bar3DCylinderPercentStacked | 3D cylinder percent stacked bar chart
// col | 2D clustered column chart
// colStacked | 2D stacked column chart
// colPercentStacked | 2D 100% stacked column chart
// col3DClustered | 3D clustered column chart
// col3D | 3D column chart
// col3DStacked | 3D stacked column chart
// col3DPercentStacked | 3D 100% stacked column chart
// col3DCone | 3D cone column chart
// col3DConeClustered | 3D cone clustered column chart
// col3DConeStacked | 3D cone stacked column chart
// col3DConePercentStacked | 3D cone percent stacked column chart
// col3DPyramid | 3D pyramid column chart
// col3DPyramidClustered | 3D pyramid clustered column chart
// col3DPyramidStacked | 3D pyramid stacked column chart
// col3DPyramidPercentStacked | 3D pyramid percent stacked column chart
// col3DCylinder | 3D cylinder column chart
// col3DCylinderClustered | 3D cylinder clustered column chart
// col3DCylinderStacked | 3D cylinder stacked column chart
// col3DCylinderPercentStacked | 3D cylinder percent stacked column chart
// doughnut | doughnut chart
// line | line chart
// pie | pie chart
// pie3D | 3D pie chart
// radar | radar chart
// scatter | scatter chart
2019-06-15 20:55:56 +08:00
// surface3D | 3D surface chart
// wireframeSurface3D | 3D wireframe surface chart
// contour | contour chart
2019-06-19 00:01:18 +08:00
// wireframeContour | wireframe contour chart
// bubble | bubble chart
// bubble3D | 3D bubble chart
2017-04-23 00:10:23 +08:00
//
// In Excel a chart series is a collection of information that defines which data is plotted such as values, axis labels and formatting.
//
// The series options that can be set are:
//
// name
// categories
// values
//
2018-02-12 11:45:42 +08:00
// 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
2017-04-23 00:10:23 +08:00
//
// 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.
//
// 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.
//
// Set properties of the chart legend. The options that can be set are:
//
// position
// show_legend_key
//
// position: Set the position of the chart legend. The default legend position is right. The available positions are:
//
// top
// bottom
// left
// right
// top_right
//
// show_legend_key: Set the legend keys shall be shown in data labels. The default value is false.
//
// Set properties of the chart title. The properties that can be set are:
//
// title
//
2018-02-12 11:45:42 +08:00
// 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.
2017-04-23 00:10:23 +08:00
//
// 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:
//
// gap
// span
// zero
//
// gap: Specifies that blank values shall be left as a gap.
//
// sapn: Specifies that blank values shall be spanned with a line.
//
// zero: Specifies that blank values shall be treated as zero.
//
// Set chart offset, scale, aspect ratio setting and print settings by format, same as function AddPicture.
//
// Set the position of the chart plot area by plotarea. The properties that can be set are:
//
// show_bubble_size
// show_cat_name
// show_leader_lines
// show_percent
// show_series_name
// show_val
//
// 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.
2017-05-13 14:12:43 +08:00
//
2017-04-23 00:10:23 +08:00
// 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.
2017-05-13 14:12:43 +08:00
//
2017-04-23 00:10:23 +08:00
// show_leader_lines: Specifies leader lines shall be shown for data labels. The show_leader_lines property is optional. The default value is false.
2017-05-13 14:12:43 +08:00
//
2017-04-23 00:10:23 +08:00
// show_percent: Specifies that the percentage shall be shown in a data label. The show_percent property is optional. The default value is false.
2017-05-13 14:12:43 +08:00
//
2017-04-23 00:10:23 +08:00
// 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.
2017-05-13 14:12:43 +08:00
//
2017-04-23 00:10:23 +08:00
// show_val: Specifies that the value shall be shown in a data label. The show_val property is optional. The default value is false.
//
2018-03-29 20:17:07 +08:00
// Set the primary horizontal and vertical axis options by x_axis and y_axis. The properties that can be set are:
//
// reverse_order
// maximum
// minimum
//
// 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.
2018-07-13 17:40:47 +08:00
//
2018-03-29 20:17:07 +08:00
// maximum: Specifies that the fixed maximum, 0 is auto. The maximum property is optional. The default value is auto.
2018-07-13 17:40:47 +08:00
//
2018-03-29 20:17:07 +08:00
// minimum: Specifies that the fixed minimum, 0 is auto. The minimum property is optional. The default value is auto.
//
2018-05-11 10:14:18 +08:00
// Set chart size by dimension property. The dimension property is optional. The default width is 480, and height is 290.
//
2018-05-27 11:25:55 +08:00
func ( f * File ) AddChart ( sheet , cell , format string ) error {
formatSet , err := parseFormatChartSet ( format )
if err != nil {
return err
}
2017-04-23 00:10:23 +08:00
// Read sheet data.
2019-04-15 11:22:57 +08:00
xlsx , err := f . workSheetReader ( sheet )
if err != nil {
return err
}
2019-06-14 00:05:10 +08:00
if _ , ok := chartValAxNumFmtFormatCode [ formatSet . Type ] ; ! ok {
return errors . New ( "unsupported chart type " + formatSet . Type )
}
2017-04-23 00:10:23 +08:00
// Add first picture for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder.
drawingID := f . countDrawings ( ) + 1
chartID := f . countCharts ( ) + 1
drawingXML := "xl/drawings/drawing" + strconv . Itoa ( drawingID ) + ".xml"
2017-05-24 14:17:35 +08:00
drawingID , drawingXML = f . prepareDrawing ( xlsx , drawingID , sheet , drawingXML )
2018-02-03 15:02:37 +08:00
drawingRID := f . addDrawingRelationships ( drawingID , SourceRelationshipChart , "../charts/chart" + strconv . Itoa ( chartID ) + ".xml" , "" )
2019-03-23 20:08:06 +08:00
err = f . addDrawingChart ( sheet , drawingXML , cell , formatSet . Dimension . Width , formatSet . Dimension . Height , drawingRID , & formatSet . Format )
if err != nil {
return err
}
2017-04-23 00:10:23 +08:00
f . addChart ( formatSet )
2017-05-24 14:17:35 +08:00
f . addContentTypePart ( chartID , "chart" )
f . addContentTypePart ( drawingID , "drawings" )
2018-05-27 11:25:55 +08:00
return err
2017-04-23 00:10:23 +08:00
}
2018-08-06 10:21:24 +08:00
// countCharts provides a function to get chart files count storage in the
2017-04-23 00:10:23 +08:00
// folder xl/charts.
func ( f * File ) countCharts ( ) int {
count := 0
for k := range f . XLSX {
if strings . Contains ( k , "xl/charts/chart" ) {
count ++
}
}
return count
}
2018-08-06 10:21:24 +08:00
// prepareDrawing provides a function to prepare drawing ID and XML by given
2017-10-31 16:33:36 +08:00
// drawingID, worksheet name and default drawingXML.
2017-05-24 14:17:35 +08:00
func ( f * File ) prepareDrawing ( xlsx * xlsxWorksheet , drawingID int , sheet , drawingXML string ) ( int , string ) {
sheetRelationshipsDrawingXML := "../drawings/drawing" + strconv . Itoa ( drawingID ) + ".xml"
if xlsx . Drawing != nil {
// The worksheet already has a picture or chart relationships, use the relationships drawing ../drawings/drawing%d.xml.
sheetRelationshipsDrawingXML = f . getSheetRelationshipsTargetByID ( sheet , xlsx . Drawing . RID )
drawingID , _ = strconv . Atoi ( strings . TrimSuffix ( strings . TrimPrefix ( sheetRelationshipsDrawingXML , "../drawings/drawing" ) , ".xml" ) )
drawingXML = strings . Replace ( sheetRelationshipsDrawingXML , ".." , "xl" , - 1 )
} else {
// Add first picture for given sheet.
rID := f . addSheetRelationships ( sheet , SourceRelationshipDrawingML , sheetRelationshipsDrawingXML , "" )
f . addSheetDrawing ( sheet , rID )
2017-04-23 00:10:23 +08:00
}
2017-05-24 14:17:35 +08:00
return drawingID , drawingXML
2017-04-23 00:10:23 +08:00
}
2018-08-06 10:21:24 +08:00
// addChart provides a function to create chart as xl/charts/chart%d.xml by
// given format sets.
2017-04-23 00:10:23 +08:00
func ( f * File ) addChart ( formatSet * formatChart ) {
count := f . countCharts ( )
xlsxChartSpace := xlsxChartSpace {
2017-04-30 20:03:43 +08:00
XMLNSc : NameSpaceDrawingMLChart ,
XMLNSa : NameSpaceDrawingML ,
XMLNSr : SourceRelationship ,
XMLNSc16r2 : SourceRelationshipChart201506 ,
Date1904 : & attrValBool { Val : false } ,
Lang : & attrValString { Val : "en-US" } ,
RoundedCorners : & attrValBool { Val : false } ,
Chart : cChart {
Title : & cTitle {
Tx : cTx {
Rich : & cRich {
P : aP {
PPr : & aPPr {
2017-05-16 20:42:01 +08:00
DefRPr : aRPr {
2017-04-30 20:03:43 +08:00
Kern : 1200 ,
Strike : "noStrike" ,
U : "none" ,
Sz : 1400 ,
SolidFill : & aSolidFill {
SchemeClr : & aSchemeClr {
Val : "tx1" ,
LumMod : & attrValInt {
Val : 65000 ,
} ,
LumOff : & attrValInt {
Val : 35000 ,
2017-04-23 00:10:23 +08:00
} ,
} ,
} ,
2017-04-30 20:03:43 +08:00
Ea : & aEa {
Typeface : "+mn-ea" ,
} ,
Cs : & aCs {
Typeface : "+mn-cs" ,
} ,
Latin : & aLatin {
Typeface : "+mn-lt" ,
2017-04-23 00:10:23 +08:00
} ,
} ,
} ,
2017-04-30 20:03:43 +08:00
R : & aR {
RPr : aRPr {
Lang : "en-US" ,
AltLang : "en-US" ,
2017-04-23 00:10:23 +08:00
} ,
2017-04-30 20:03:43 +08:00
T : formatSet . Title . Name ,
2017-04-23 00:10:23 +08:00
} ,
} ,
} ,
} ,
2017-04-30 20:03:43 +08:00
TxPr : cTxPr {
P : aP {
PPr : & aPPr {
2017-05-16 20:42:01 +08:00
DefRPr : aRPr {
2017-04-30 20:03:43 +08:00
Kern : 1200 ,
U : "none" ,
Sz : 14000 ,
Strike : "noStrike" ,
} ,
} ,
EndParaRPr : & aEndParaRPr {
Lang : "en-US" ,
} ,
} ,
2017-04-23 00:10:23 +08:00
} ,
2017-04-30 20:03:43 +08:00
} ,
View3D : & cView3D {
RotX : & attrValInt { Val : chartView3DRotX [ formatSet . Type ] } ,
RotY : & attrValInt { Val : chartView3DRotY [ formatSet . Type ] } ,
DepthPercent : & attrValInt { Val : chartView3DDepthPercent [ formatSet . Type ] } ,
2019-06-15 20:55:56 +08:00
Perspective : & attrValInt { Val : chartView3DPerspective [ formatSet . Type ] } ,
2017-04-30 20:03:43 +08:00
RAngAx : & attrValInt { Val : chartView3DRAngAx [ formatSet . Type ] } ,
} ,
Floor : & cThicknessSpPr {
Thickness : & attrValInt { Val : 0 } ,
} ,
SideWall : & cThicknessSpPr {
Thickness : & attrValInt { Val : 0 } ,
} ,
BackWall : & cThicknessSpPr {
Thickness : & attrValInt { Val : 0 } ,
} ,
PlotArea : & cPlotArea { } ,
Legend : & cLegend {
LegendPos : & attrValString { Val : chartLegendPosition [ formatSet . Legend . Position ] } ,
Overlay : & attrValBool { Val : false } ,
} ,
2017-04-23 00:10:23 +08:00
2017-04-30 20:03:43 +08:00
PlotVisOnly : & attrValBool { Val : false } ,
DispBlanksAs : & attrValString { Val : formatSet . ShowBlanksAs } ,
ShowDLblsOverMax : & attrValBool { Val : false } ,
} ,
SpPr : & cSpPr {
SolidFill : & aSolidFill {
SchemeClr : & aSchemeClr { Val : "bg1" } ,
2017-04-23 00:10:23 +08:00
} ,
2017-04-30 20:03:43 +08:00
Ln : & aLn {
W : 9525 ,
Cap : "flat" ,
Cmpd : "sng" ,
Algn : "ctr" ,
2017-04-23 00:10:23 +08:00
SolidFill : & aSolidFill {
2017-04-30 20:03:43 +08:00
SchemeClr : & aSchemeClr { Val : "tx1" ,
LumMod : & attrValInt {
Val : 15000 ,
} ,
LumOff : & attrValInt {
Val : 85000 ,
2017-04-23 00:10:23 +08:00
} ,
} ,
} ,
} ,
2017-04-30 20:03:43 +08:00
} ,
PrintSettings : & cPrintSettings {
PageMargins : & cPageMargins {
B : 0.75 ,
L : 0.7 ,
R : 0.7 ,
T : 0.7 ,
Header : 0.3 ,
Footer : 0.3 ,
2017-04-23 00:10:23 +08:00
} ,
} ,
}
plotAreaFunc := map [ string ] func ( * formatChart ) * cPlotArea {
2019-06-14 00:05:10 +08:00
Area : f . drawBaseChart ,
AreaStacked : f . drawBaseChart ,
AreaPercentStacked : f . drawBaseChart ,
Area3D : f . drawBaseChart ,
Area3DStacked : f . drawBaseChart ,
Area3DPercentStacked : f . drawBaseChart ,
Bar : f . drawBaseChart ,
BarStacked : f . drawBaseChart ,
BarPercentStacked : f . drawBaseChart ,
Bar3DClustered : f . drawBaseChart ,
Bar3DStacked : f . drawBaseChart ,
Bar3DPercentStacked : f . drawBaseChart ,
Bar3DConeClustered : f . drawBaseChart ,
Bar3DConeStacked : f . drawBaseChart ,
Bar3DConePercentStacked : f . drawBaseChart ,
Bar3DPyramidClustered : f . drawBaseChart ,
Bar3DPyramidStacked : f . drawBaseChart ,
Bar3DPyramidPercentStacked : f . drawBaseChart ,
Bar3DCylinderClustered : f . drawBaseChart ,
Bar3DCylinderStacked : f . drawBaseChart ,
Bar3DCylinderPercentStacked : f . drawBaseChart ,
Col : f . drawBaseChart ,
ColStacked : f . drawBaseChart ,
ColPercentStacked : f . drawBaseChart ,
Col3D : f . drawBaseChart ,
Col3DClustered : f . drawBaseChart ,
Col3DStacked : f . drawBaseChart ,
Col3DPercentStacked : f . drawBaseChart ,
Col3DCone : f . drawBaseChart ,
Col3DConeClustered : f . drawBaseChart ,
Col3DConeStacked : f . drawBaseChart ,
Col3DConePercentStacked : f . drawBaseChart ,
Col3DPyramid : f . drawBaseChart ,
Col3DPyramidClustered : f . drawBaseChart ,
Col3DPyramidStacked : f . drawBaseChart ,
Col3DPyramidPercentStacked : f . drawBaseChart ,
Col3DCylinder : f . drawBaseChart ,
Col3DCylinderClustered : f . drawBaseChart ,
Col3DCylinderStacked : f . drawBaseChart ,
Col3DCylinderPercentStacked : f . drawBaseChart ,
Doughnut : f . drawDoughnutChart ,
Line : f . drawLineChart ,
Pie3D : f . drawPie3DChart ,
Pie : f . drawPieChart ,
Radar : f . drawRadarChart ,
Scatter : f . drawScatterChart ,
2019-06-15 20:55:56 +08:00
Surface3D : f . drawSurface3DChart ,
WireframeSurface3D : f . drawSurface3DChart ,
Contour : f . drawSurfaceChart ,
WireframeContour : f . drawSurfaceChart ,
2019-06-19 00:01:18 +08:00
Bubble : f . drawBaseChart ,
Bubble3D : f . drawBaseChart ,
2017-04-23 00:10:23 +08:00
}
2017-04-30 20:03:43 +08:00
xlsxChartSpace . Chart . PlotArea = plotAreaFunc [ formatSet . Type ] ( formatSet )
2017-04-23 00:10:23 +08:00
chart , _ := xml . Marshal ( xlsxChartSpace )
media := "xl/charts/chart" + strconv . Itoa ( count + 1 ) + ".xml"
2018-05-07 16:12:51 +08:00
f . saveFileList ( media , chart )
2017-04-23 00:10:23 +08:00
}
2018-08-06 10:21:24 +08:00
// drawBaseChart provides a function to draw the c:plotArea element for bar,
2018-03-05 21:23:52 +08:00
// and column series charts by given format sets.
func ( f * File ) drawBaseChart ( formatSet * formatChart ) * cPlotArea {
2017-05-24 14:17:35 +08:00
c := cCharts {
BarDir : & attrValString {
Val : "col" ,
} ,
Grouping : & attrValString {
Val : "clustered" ,
} ,
VaryColors : & attrValBool {
Val : true ,
} ,
Ser : f . drawChartSeries ( formatSet ) ,
2019-06-14 00:05:10 +08:00
Shape : f . drawChartShape ( formatSet ) ,
2017-05-24 14:17:35 +08:00
DLbls : f . drawChartDLbls ( formatSet ) ,
AxID : [ ] * attrValInt {
{ Val : 754001152 } ,
{ Val : 753999904 } ,
2017-04-23 00:10:23 +08:00
} ,
}
2018-12-23 00:07:47 +08:00
var ok bool
2019-06-19 00:01:18 +08:00
if c . BarDir . Val , ok = plotAreaChartBarDir [ formatSet . Type ] ; ! ok {
2018-12-23 00:07:47 +08:00
c . BarDir = nil
}
2019-06-19 00:01:18 +08:00
if c . Grouping . Val , ok = plotAreaChartGrouping [ formatSet . Type ] ; ! ok {
c . Grouping = nil
}
if strings . HasSuffix ( formatSet . Type , "Stacked" ) {
2017-11-21 09:18:25 +08:00
c . Overlap = & attrValInt { Val : 100 }
}
2018-01-08 23:03:59 +08:00
catAx := f . drawPlotAreaCatAx ( formatSet )
valAx := f . drawPlotAreaValAx ( formatSet )
2017-05-24 14:17:35 +08:00
charts := map [ string ] * cPlotArea {
2018-12-23 00:07:47 +08:00
"area" : {
AreaChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"areaStacked" : {
AreaChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"areaPercentStacked" : {
AreaChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"area3D" : {
Area3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"area3DStacked" : {
Area3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"area3DPercentStacked" : {
Area3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
2017-05-25 10:57:45 +08:00
"bar" : {
2017-05-24 14:17:35 +08:00
BarChart : & c ,
2017-11-21 09:18:25 +08:00
CatAx : catAx ,
ValAx : valAx ,
} ,
"barStacked" : {
BarChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
2017-05-24 14:17:35 +08:00
} ,
2018-03-05 21:23:52 +08:00
"barPercentStacked" : {
BarChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"bar3DClustered" : {
2017-05-24 14:17:35 +08:00
Bar3DChart : & c ,
2017-11-21 09:18:25 +08:00
CatAx : catAx ,
ValAx : valAx ,
2017-04-23 00:10:23 +08:00
} ,
2018-03-05 21:23:52 +08:00
"bar3DStacked" : {
2018-01-08 23:03:59 +08:00
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"bar3DPercentStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
2019-06-14 00:05:10 +08:00
"bar3DConeClustered" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"bar3DConeStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"bar3DConePercentStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"bar3DPyramidClustered" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"bar3DPyramidStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"bar3DPyramidPercentStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"bar3DCylinderClustered" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"bar3DCylinderStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"bar3DCylinderPercentStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
2018-03-05 21:23:52 +08:00
"col" : {
BarChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"colStacked" : {
BarChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"colPercentStacked" : {
BarChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
2019-06-14 00:05:10 +08:00
"col3D" : {
2018-03-05 21:23:52 +08:00
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
2019-06-14 00:05:10 +08:00
"col3DClustered" : {
2018-03-05 21:23:52 +08:00
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"col3DStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"col3DPercentStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
2019-06-14 00:05:10 +08:00
"col3DCone" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"col3DConeClustered" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"col3DConeStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"col3DConePercentStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"col3DPyramid" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"col3DPyramidClustered" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"col3DPyramidStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"col3DPyramidPercentStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"col3DCylinder" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"col3DCylinderClustered" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"col3DCylinderStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"col3DCylinderPercentStacked" : {
Bar3DChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
2019-06-19 00:01:18 +08:00
"bubble" : {
BubbleChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
"bubble3D" : {
BubbleChart : & c ,
CatAx : catAx ,
ValAx : valAx ,
} ,
2017-04-23 00:10:23 +08:00
}
2017-05-24 14:17:35 +08:00
return charts [ formatSet . Type ]
2017-04-23 00:10:23 +08:00
}
2018-08-06 10:21:24 +08:00
// drawDoughnutChart provides a function to draw the c:plotArea element for
2017-04-23 00:10:23 +08:00
// doughnut chart by given format sets.
func ( f * File ) drawDoughnutChart ( formatSet * formatChart ) * cPlotArea {
return & cPlotArea {
DoughnutChart : & cCharts {
VaryColors : & attrValBool {
Val : true ,
} ,
Ser : f . drawChartSeries ( formatSet ) ,
HoleSize : & attrValInt { Val : 75 } ,
} ,
}
}
2018-08-06 10:21:24 +08:00
// drawLineChart provides a function to draw the c:plotArea element for line
// chart by given format sets.
2017-04-23 00:10:23 +08:00
func ( f * File ) drawLineChart ( formatSet * formatChart ) * cPlotArea {
return & cPlotArea {
LineChart : & cCharts {
Grouping : & attrValString {
2018-01-08 23:03:59 +08:00
Val : plotAreaChartGrouping [ formatSet . Type ] ,
2017-04-23 00:10:23 +08:00
} ,
VaryColors : & attrValBool {
Val : false ,
} ,
Ser : f . drawChartSeries ( formatSet ) ,
DLbls : f . drawChartDLbls ( formatSet ) ,
Smooth : & attrValBool {
Val : false ,
} ,
AxID : [ ] * attrValInt {
2017-04-23 00:39:14 +08:00
{ Val : 754001152 } ,
{ Val : 753999904 } ,
2017-04-23 00:10:23 +08:00
} ,
} ,
2018-01-08 23:03:59 +08:00
CatAx : f . drawPlotAreaCatAx ( formatSet ) ,
ValAx : f . drawPlotAreaValAx ( formatSet ) ,
2017-04-23 00:10:23 +08:00
}
}
2018-08-06 10:21:24 +08:00
// drawPieChart provides a function to draw the c:plotArea element for pie
// chart by given format sets.
2017-04-23 00:10:23 +08:00
func ( f * File ) drawPieChart ( formatSet * formatChart ) * cPlotArea {
return & cPlotArea {
PieChart : & cCharts {
VaryColors : & attrValBool {
Val : true ,
} ,
Ser : f . drawChartSeries ( formatSet ) ,
} ,
}
}
2018-08-06 10:21:24 +08:00
// drawPie3DChart provides a function to draw the c:plotArea element for 3D
// pie chart by given format sets.
2017-04-23 00:10:23 +08:00
func ( f * File ) drawPie3DChart ( formatSet * formatChart ) * cPlotArea {
return & cPlotArea {
Pie3DChart : & cCharts {
VaryColors : & attrValBool {
Val : true ,
} ,
Ser : f . drawChartSeries ( formatSet ) ,
} ,
}
}
2018-08-06 10:21:24 +08:00
// drawRadarChart provides a function to draw the c:plotArea element for radar
2017-04-23 00:10:23 +08:00
// chart by given format sets.
func ( f * File ) drawRadarChart ( formatSet * formatChart ) * cPlotArea {
return & cPlotArea {
RadarChart : & cCharts {
RadarStyle : & attrValString {
Val : "marker" ,
} ,
VaryColors : & attrValBool {
Val : false ,
} ,
Ser : f . drawChartSeries ( formatSet ) ,
DLbls : f . drawChartDLbls ( formatSet ) ,
AxID : [ ] * attrValInt {
2017-04-23 00:39:14 +08:00
{ Val : 754001152 } ,
{ Val : 753999904 } ,
2017-04-23 00:10:23 +08:00
} ,
} ,
2018-01-08 23:03:59 +08:00
CatAx : f . drawPlotAreaCatAx ( formatSet ) ,
ValAx : f . drawPlotAreaValAx ( formatSet ) ,
2017-04-23 00:10:23 +08:00
}
}
2018-08-06 10:21:24 +08:00
// drawScatterChart provides a function to draw the c:plotArea element for
// scatter chart by given format sets.
2017-04-23 00:10:23 +08:00
func ( f * File ) drawScatterChart ( formatSet * formatChart ) * cPlotArea {
return & cPlotArea {
ScatterChart : & cCharts {
ScatterStyle : & attrValString {
Val : "smoothMarker" , // line,lineMarker,marker,none,smooth,smoothMarker
} ,
VaryColors : & attrValBool {
Val : false ,
} ,
Ser : f . drawChartSeries ( formatSet ) ,
DLbls : f . drawChartDLbls ( formatSet ) ,
AxID : [ ] * attrValInt {
2017-04-23 00:39:14 +08:00
{ Val : 754001152 } ,
{ Val : 753999904 } ,
2017-04-23 00:10:23 +08:00
} ,
} ,
2018-01-08 23:03:59 +08:00
CatAx : f . drawPlotAreaCatAx ( formatSet ) ,
ValAx : f . drawPlotAreaValAx ( formatSet ) ,
2017-04-23 00:10:23 +08:00
}
}
2019-06-15 20:55:56 +08:00
// drawSurface3DChart provides a function to draw the c:surface3DChart element by
// given format sets.
func ( f * File ) drawSurface3DChart ( formatSet * formatChart ) * cPlotArea {
plotArea := & cPlotArea {
Surface3DChart : & cCharts {
Ser : f . drawChartSeries ( formatSet ) ,
AxID : [ ] * attrValInt {
{ Val : 754001152 } ,
{ Val : 753999904 } ,
{ Val : 832256642 } ,
} ,
} ,
CatAx : f . drawPlotAreaCatAx ( formatSet ) ,
ValAx : f . drawPlotAreaValAx ( formatSet ) ,
SerAx : f . drawPlotAreaSerAx ( formatSet ) ,
}
if formatSet . Type == WireframeSurface3D {
plotArea . Surface3DChart . Wireframe = & attrValBool { Val : true }
}
return plotArea
}
// drawSurfaceChart provides a function to draw the c:surfaceChart element by
// given format sets.
func ( f * File ) drawSurfaceChart ( formatSet * formatChart ) * cPlotArea {
plotArea := & cPlotArea {
SurfaceChart : & cCharts {
Ser : f . drawChartSeries ( formatSet ) ,
AxID : [ ] * attrValInt {
{ Val : 754001152 } ,
{ Val : 753999904 } ,
{ Val : 832256642 } ,
} ,
} ,
CatAx : f . drawPlotAreaCatAx ( formatSet ) ,
ValAx : f . drawPlotAreaValAx ( formatSet ) ,
SerAx : f . drawPlotAreaSerAx ( formatSet ) ,
}
if formatSet . Type == WireframeContour {
plotArea . SurfaceChart . Wireframe = & attrValBool { Val : true }
}
return plotArea
}
// drawChartShape provides a function to draw the c:shape element by given
// format sets.
2019-06-14 00:05:10 +08:00
func ( f * File ) drawChartShape ( formatSet * formatChart ) * attrValString {
shapes := map [ string ] string {
Bar3DConeClustered : "cone" ,
Bar3DConeStacked : "cone" ,
Bar3DConePercentStacked : "cone" ,
Bar3DPyramidClustered : "pyramid" ,
Bar3DPyramidStacked : "pyramid" ,
Bar3DPyramidPercentStacked : "pyramid" ,
Bar3DCylinderClustered : "cylinder" ,
Bar3DCylinderStacked : "cylinder" ,
Bar3DCylinderPercentStacked : "cylinder" ,
Col3DCone : "cone" ,
Col3DConeClustered : "cone" ,
Col3DConeStacked : "cone" ,
Col3DConePercentStacked : "cone" ,
Col3DPyramid : "pyramid" ,
Col3DPyramidClustered : "pyramid" ,
Col3DPyramidStacked : "pyramid" ,
Col3DPyramidPercentStacked : "pyramid" ,
Col3DCylinder : "cylinder" ,
Col3DCylinderClustered : "cylinder" ,
Col3DCylinderStacked : "cylinder" ,
Col3DCylinderPercentStacked : "cylinder" ,
}
if shape , ok := shapes [ formatSet . Type ] ; ok {
2019-06-15 20:55:56 +08:00
return & attrValString { Val : shape }
2019-06-14 00:05:10 +08:00
}
return nil
}
2018-08-06 10:21:24 +08:00
// drawChartSeries provides a function to draw the c:ser element by given
// format sets.
2017-04-23 00:10:23 +08:00
func ( f * File ) drawChartSeries ( formatSet * formatChart ) * [ ] cSer {
ser := [ ] cSer { }
2017-10-16 10:42:43 +08:00
for k := range formatSet . Series {
2017-04-23 00:10:23 +08:00
ser = append ( ser , cSer {
IDx : & attrValInt { Val : k } ,
Order : & attrValInt { Val : k } ,
Tx : & cTx {
StrRef : & cStrRef {
2017-10-16 10:42:43 +08:00
F : formatSet . Series [ k ] . Name ,
2017-04-23 00:10:23 +08:00
} ,
} ,
2019-06-19 00:01:18 +08:00
SpPr : f . drawChartSeriesSpPr ( k , formatSet ) ,
Marker : f . drawChartSeriesMarker ( k , formatSet ) ,
DPt : f . drawChartSeriesDPt ( k , formatSet ) ,
DLbls : f . drawChartSeriesDLbls ( formatSet ) ,
Cat : f . drawChartSeriesCat ( formatSet . Series [ k ] , formatSet ) ,
Val : f . drawChartSeriesVal ( formatSet . Series [ k ] , formatSet ) ,
XVal : f . drawChartSeriesXVal ( formatSet . Series [ k ] , formatSet ) ,
YVal : f . drawChartSeriesYVal ( formatSet . Series [ k ] , formatSet ) ,
BubbleSize : f . drawCharSeriesBubbleSize ( formatSet . Series [ k ] , formatSet ) ,
Bubble3D : f . drawCharSeriesBubble3D ( formatSet ) ,
2017-04-23 00:10:23 +08:00
} )
}
return & ser
}
2018-08-06 10:21:24 +08:00
// drawChartSeriesSpPr provides a function to draw the c:spPr element by given
2017-04-23 00:10:23 +08:00
// format sets.
func ( f * File ) drawChartSeriesSpPr ( i int , formatSet * formatChart ) * cSpPr {
spPrScatter := & cSpPr {
Ln : & aLn {
W : 25400 ,
NoFill : " " ,
} ,
}
spPrLine := & cSpPr {
Ln : & aLn {
W : 25400 ,
Cap : "rnd" , // rnd, sq, flat
} ,
}
2019-06-09 09:53:02 +08:00
if i < 6 {
spPrLine . Ln . SolidFill = & aSolidFill {
SchemeClr : & aSchemeClr { Val : "accent" + strconv . Itoa ( i + 1 ) } ,
}
}
2019-06-14 00:05:10 +08:00
chartSeriesSpPr := map [ string ] * cSpPr { Line : spPrLine , Scatter : spPrScatter }
2017-04-23 00:10:23 +08:00
return chartSeriesSpPr [ formatSet . Type ]
}
2018-08-06 10:21:24 +08:00
// drawChartSeriesDPt provides a function to draw the c:dPt element by given
// data index and format sets.
2017-04-23 00:10:23 +08:00
func ( f * File ) drawChartSeriesDPt ( i int , formatSet * formatChart ) [ ] * cDPt {
2017-04-23 00:39:14 +08:00
dpt := [ ] * cDPt { {
2017-04-23 00:10:23 +08:00
IDx : & attrValInt { Val : i } ,
Bubble3D : & attrValBool { Val : false } ,
SpPr : & cSpPr {
SolidFill : & aSolidFill {
SchemeClr : & aSchemeClr { Val : "accent" + strconv . Itoa ( i + 1 ) } ,
} ,
Ln : & aLn {
W : 25400 ,
Cap : "rnd" ,
SolidFill : & aSolidFill {
SchemeClr : & aSchemeClr { Val : "lt" + strconv . Itoa ( i + 1 ) } ,
} ,
} ,
Sp3D : & aSp3D {
ContourW : 25400 ,
ContourClr : & aContourClr {
SchemeClr : & aSchemeClr { Val : "lt" + strconv . Itoa ( i + 1 ) } ,
} ,
} ,
} ,
} }
2019-06-14 00:05:10 +08:00
chartSeriesDPt := map [ string ] [ ] * cDPt { Pie : dpt , Pie3D : dpt }
2017-04-23 00:10:23 +08:00
return chartSeriesDPt [ formatSet . Type ]
}
2018-08-06 10:21:24 +08:00
// drawChartSeriesCat provides a function to draw the c:cat element by given
// chart series and format sets.
2017-04-23 00:10:23 +08:00
func ( f * File ) drawChartSeriesCat ( v formatChartSeries , formatSet * formatChart ) * cCat {
cat := & cCat {
StrRef : & cStrRef {
F : v . Categories ,
} ,
}
2019-06-14 00:05:10 +08:00
chartSeriesCat := map [ string ] * cCat { Scatter : nil }
if _ , ok := chartSeriesCat [ formatSet . Type ] ; ok {
return nil
}
return cat
2017-04-23 00:10:23 +08:00
}
2018-08-06 10:21:24 +08:00
// drawChartSeriesVal provides a function to draw the c:val element by given
// chart series and format sets.
2017-04-23 00:10:23 +08:00
func ( f * File ) drawChartSeriesVal ( v formatChartSeries , formatSet * formatChart ) * cVal {
val := & cVal {
NumRef : & cNumRef {
F : v . Values ,
} ,
}
2019-06-14 00:05:10 +08:00
chartSeriesVal := map [ string ] * cVal { Scatter : nil }
if _ , ok := chartSeriesVal [ formatSet . Type ] ; ok {
return nil
}
return val
2017-04-23 00:10:23 +08:00
}
2018-08-06 10:21:24 +08:00
// drawChartSeriesMarker provides a function to draw the c:marker element by
// given data index and format sets.
2017-04-23 00:10:23 +08:00
func ( f * File ) drawChartSeriesMarker ( i int , formatSet * formatChart ) * cMarker {
marker := & cMarker {
Symbol : & attrValString { Val : "circle" } ,
Size : & attrValInt { Val : 5 } ,
2019-06-09 09:53:02 +08:00
}
if i < 6 {
marker . SpPr = & cSpPr {
2017-04-23 00:10:23 +08:00
SolidFill : & aSolidFill {
SchemeClr : & aSchemeClr {
Val : "accent" + strconv . Itoa ( i + 1 ) ,
} ,
} ,
Ln : & aLn {
W : 9252 ,
SolidFill : & aSolidFill {
SchemeClr : & aSchemeClr {
Val : "accent" + strconv . Itoa ( i + 1 ) ,
} ,
} ,
} ,
2019-06-09 09:53:02 +08:00
}
2017-04-23 00:10:23 +08:00
}
2019-06-14 00:05:10 +08:00
chartSeriesMarker := map [ string ] * cMarker { Scatter : marker }
2017-04-23 00:10:23 +08:00
return chartSeriesMarker [ formatSet . Type ]
}
2018-08-06 10:21:24 +08:00
// drawChartSeriesXVal provides a function to draw the c:xVal element by given
2017-04-23 00:10:23 +08:00
// chart series and format sets.
func ( f * File ) drawChartSeriesXVal ( v formatChartSeries , formatSet * formatChart ) * cCat {
cat := & cCat {
StrRef : & cStrRef {
F : v . Categories ,
} ,
}
2019-06-14 00:05:10 +08:00
chartSeriesXVal := map [ string ] * cCat { Scatter : cat }
2017-04-23 00:10:23 +08:00
return chartSeriesXVal [ formatSet . Type ]
}
2018-08-06 10:21:24 +08:00
// drawChartSeriesYVal provides a function to draw the c:yVal element by given
2017-04-23 00:10:23 +08:00
// chart series and format sets.
func ( f * File ) drawChartSeriesYVal ( v formatChartSeries , formatSet * formatChart ) * cVal {
val := & cVal {
NumRef : & cNumRef {
F : v . Values ,
} ,
}
2019-06-19 00:01:18 +08:00
chartSeriesYVal := map [ string ] * cVal { Scatter : val , Bubble : val , Bubble3D : val }
2017-04-23 00:10:23 +08:00
return chartSeriesYVal [ formatSet . Type ]
}
2019-06-19 00:01:18 +08:00
// drawCharSeriesBubbleSize provides a function to draw the c:bubbleSize
// element by given chart series and format sets.
func ( f * File ) drawCharSeriesBubbleSize ( v formatChartSeries , formatSet * formatChart ) * cVal {
if _ , ok := map [ string ] bool { Bubble : true , Bubble3D : true } [ formatSet . Type ] ; ! ok {
return nil
}
return & cVal {
NumRef : & cNumRef {
F : v . Values ,
} ,
}
}
// drawCharSeriesBubble3D provides a function to draw the c:bubble3D element
// by given format sets.
func ( f * File ) drawCharSeriesBubble3D ( formatSet * formatChart ) * attrValBool {
if _ , ok := map [ string ] bool { Bubble3D : true } [ formatSet . Type ] ; ! ok {
return nil
}
return & attrValBool { Val : true }
}
2018-08-06 10:21:24 +08:00
// drawChartDLbls provides a function to draw the c:dLbls element by given
// format sets.
2017-04-23 00:10:23 +08:00
func ( f * File ) drawChartDLbls ( formatSet * formatChart ) * cDLbls {
return & cDLbls {
ShowLegendKey : & attrValBool { Val : formatSet . Legend . ShowLegendKey } ,
ShowVal : & attrValBool { Val : formatSet . Plotarea . ShowVal } ,
ShowCatName : & attrValBool { Val : formatSet . Plotarea . ShowCatName } ,
ShowSerName : & attrValBool { Val : formatSet . Plotarea . ShowSerName } ,
ShowBubbleSize : & attrValBool { Val : formatSet . Plotarea . ShowBubbleSize } ,
ShowPercent : & attrValBool { Val : formatSet . Plotarea . ShowPercent } ,
ShowLeaderLines : & attrValBool { Val : formatSet . Plotarea . ShowLeaderLines } ,
}
}
2018-08-06 10:21:24 +08:00
// drawChartSeriesDLbls provides a function to draw the c:dLbls element by
// given format sets.
2017-04-23 00:10:23 +08:00
func ( f * File ) drawChartSeriesDLbls ( formatSet * formatChart ) * cDLbls {
2017-05-24 14:17:35 +08:00
dLbls := f . drawChartDLbls ( formatSet )
2019-06-19 00:01:18 +08:00
chartSeriesDLbls := map [ string ] * cDLbls { Scatter : nil , Surface3D : nil , WireframeSurface3D : nil , Contour : nil , WireframeContour : nil , Bubble : nil , Bubble3D : nil }
2019-06-14 00:05:10 +08:00
if _ , ok := chartSeriesDLbls [ formatSet . Type ] ; ok {
return nil
}
return dLbls
2017-04-23 00:10:23 +08:00
}
2018-08-06 10:21:24 +08:00
// drawPlotAreaCatAx provides a function to draw the c:catAx element.
2018-01-08 23:03:59 +08:00
func ( f * File ) drawPlotAreaCatAx ( formatSet * formatChart ) [ ] * cAxs {
2018-03-29 20:17:07 +08:00
min := & attrValFloat { Val : formatSet . XAxis . Minimum }
max := & attrValFloat { Val : formatSet . XAxis . Maximum }
if formatSet . XAxis . Minimum == 0 {
min = nil
}
if formatSet . XAxis . Maximum == 0 {
max = nil
}
2019-06-15 20:55:56 +08:00
axs := [ ] * cAxs {
2017-04-23 00:39:14 +08:00
{
2017-04-23 00:10:23 +08:00
AxID : & attrValInt { Val : 754001152 } ,
Scaling : & cScaling {
2018-03-29 20:17:07 +08:00
Orientation : & attrValString { Val : orientation [ formatSet . XAxis . ReverseOrder ] } ,
Max : max ,
Min : min ,
2017-04-23 00:10:23 +08:00
} ,
Delete : & attrValBool { Val : false } ,
2018-03-29 20:17:07 +08:00
AxPos : & attrValString { Val : catAxPos [ formatSet . XAxis . ReverseOrder ] } ,
2017-04-23 00:10:23 +08:00
NumFmt : & cNumFmt {
FormatCode : "General" ,
SourceLinked : true ,
} ,
MajorTickMark : & attrValString { Val : "none" } ,
MinorTickMark : & attrValString { Val : "none" } ,
TickLblPos : & attrValString { Val : "nextTo" } ,
SpPr : f . drawPlotAreaSpPr ( ) ,
TxPr : f . drawPlotAreaTxPr ( ) ,
CrossAx : & attrValInt { Val : 753999904 } ,
Crosses : & attrValString { Val : "autoZero" } ,
Auto : & attrValBool { Val : true } ,
LblAlgn : & attrValString { Val : "ctr" } ,
LblOffset : & attrValInt { Val : 100 } ,
NoMultiLvlLbl : & attrValBool { Val : false } ,
} ,
}
2019-06-15 20:55:56 +08:00
if formatSet . XAxis . MajorGridlines {
axs [ 0 ] . MajorGridlines = & cChartLines { SpPr : f . drawPlotAreaSpPr ( ) }
}
return axs
2017-04-23 00:10:23 +08:00
}
2018-08-06 10:21:24 +08:00
// drawPlotAreaValAx provides a function to draw the c:valAx element.
2018-01-08 23:03:59 +08:00
func ( f * File ) drawPlotAreaValAx ( formatSet * formatChart ) [ ] * cAxs {
2018-03-29 20:17:07 +08:00
min := & attrValFloat { Val : formatSet . YAxis . Minimum }
max := & attrValFloat { Val : formatSet . YAxis . Maximum }
if formatSet . YAxis . Minimum == 0 {
min = nil
}
if formatSet . YAxis . Maximum == 0 {
max = nil
}
2019-06-15 20:55:56 +08:00
axs := [ ] * cAxs {
2017-04-23 00:39:14 +08:00
{
2017-04-23 00:10:23 +08:00
AxID : & attrValInt { Val : 753999904 } ,
Scaling : & cScaling {
2018-03-29 20:17:07 +08:00
Orientation : & attrValString { Val : orientation [ formatSet . YAxis . ReverseOrder ] } ,
Max : max ,
Min : min ,
2017-04-23 00:10:23 +08:00
} ,
Delete : & attrValBool { Val : false } ,
2018-03-29 20:17:07 +08:00
AxPos : & attrValString { Val : valAxPos [ formatSet . YAxis . ReverseOrder ] } ,
2017-04-23 00:10:23 +08:00
NumFmt : & cNumFmt {
2018-01-08 23:03:59 +08:00
FormatCode : chartValAxNumFmtFormatCode [ formatSet . Type ] ,
2017-04-23 00:10:23 +08:00
SourceLinked : true ,
} ,
MajorTickMark : & attrValString { Val : "none" } ,
MinorTickMark : & attrValString { Val : "none" } ,
TickLblPos : & attrValString { Val : "nextTo" } ,
SpPr : f . drawPlotAreaSpPr ( ) ,
TxPr : f . drawPlotAreaTxPr ( ) ,
CrossAx : & attrValInt { Val : 754001152 } ,
Crosses : & attrValString { Val : "autoZero" } ,
2018-12-23 00:07:47 +08:00
CrossBetween : & attrValString { Val : chartValAxCrossBetween [ formatSet . Type ] } ,
2017-04-23 00:10:23 +08:00
} ,
}
2019-06-15 20:55:56 +08:00
if formatSet . YAxis . MajorGridlines {
axs [ 0 ] . MajorGridlines = & cChartLines { SpPr : f . drawPlotAreaSpPr ( ) }
}
if pos , ok := valTickLblPos [ formatSet . Type ] ; ok {
axs [ 0 ] . TickLblPos . Val = pos
}
return axs
}
// drawPlotAreaSerAx provides a function to draw the c:serAx element.
func ( f * File ) drawPlotAreaSerAx ( formatSet * formatChart ) [ ] * cAxs {
min := & attrValFloat { Val : formatSet . YAxis . Minimum }
max := & attrValFloat { Val : formatSet . YAxis . Maximum }
if formatSet . YAxis . Minimum == 0 {
min = nil
}
if formatSet . YAxis . Maximum == 0 {
max = nil
}
return [ ] * cAxs {
{
AxID : & attrValInt { Val : 832256642 } ,
Scaling : & cScaling {
Orientation : & attrValString { Val : orientation [ formatSet . YAxis . ReverseOrder ] } ,
Max : max ,
Min : min ,
} ,
Delete : & attrValBool { Val : false } ,
AxPos : & attrValString { Val : catAxPos [ formatSet . XAxis . ReverseOrder ] } ,
TickLblPos : & attrValString { Val : "nextTo" } ,
SpPr : f . drawPlotAreaSpPr ( ) ,
TxPr : f . drawPlotAreaTxPr ( ) ,
CrossAx : & attrValInt { Val : 753999904 } ,
} ,
}
2017-04-23 00:10:23 +08:00
}
2018-08-06 10:21:24 +08:00
// drawPlotAreaSpPr provides a function to draw the c:spPr element.
2017-04-23 00:10:23 +08:00
func ( f * File ) drawPlotAreaSpPr ( ) * cSpPr {
return & cSpPr {
Ln : & aLn {
W : 9525 ,
Cap : "flat" ,
Cmpd : "sng" ,
Algn : "ctr" ,
SolidFill : & aSolidFill {
SchemeClr : & aSchemeClr {
Val : "tx1" ,
LumMod : & attrValInt { Val : 15000 } ,
LumOff : & attrValInt { Val : 85000 } ,
} ,
} ,
} ,
}
}
2018-08-06 10:21:24 +08:00
// drawPlotAreaTxPr provides a function to draw the c:txPr element.
2017-04-23 00:10:23 +08:00
func ( f * File ) drawPlotAreaTxPr ( ) * cTxPr {
return & cTxPr {
BodyPr : aBodyPr {
Rot : - 60000000 ,
SpcFirstLastPara : true ,
VertOverflow : "ellipsis" ,
Vert : "horz" ,
Wrap : "square" ,
Anchor : "ctr" ,
AnchorCtr : true ,
} ,
P : aP {
2017-04-30 20:03:43 +08:00
PPr : & aPPr {
2017-05-16 20:42:01 +08:00
DefRPr : aRPr {
2017-04-23 00:10:23 +08:00
Sz : 900 ,
B : false ,
I : false ,
U : "none" ,
Strike : "noStrike" ,
Kern : 1200 ,
Baseline : 0 ,
SolidFill : & aSolidFill {
SchemeClr : & aSchemeClr {
Val : "tx1" ,
LumMod : & attrValInt { Val : 15000 } ,
LumOff : & attrValInt { Val : 85000 } ,
} ,
} ,
Latin : & aLatin { Typeface : "+mn-lt" } ,
Ea : & aEa { Typeface : "+mn-ea" } ,
Cs : & aCs { Typeface : "+mn-cs" } ,
} ,
} ,
EndParaRPr : & aEndParaRPr { Lang : "en-US" } ,
} ,
}
}
2018-08-06 10:21:24 +08:00
// drawingParser provides a function to parse drawingXML. In order to solve
// the problem that the label structure is changed after serialization and
2017-05-24 14:17:35 +08:00
// deserialization, two different structures: decodeWsDr and encodeWsDr are
// defined.
2019-02-25 22:14:34 +08:00
func ( f * File ) drawingParser ( path string ) ( * xlsxWsDr , int ) {
2017-05-25 11:15:38 +08:00
cNvPrID := 1
2019-02-25 22:14:34 +08:00
if f . Drawings [ path ] == nil {
content := xlsxWsDr { }
content . A = NameSpaceDrawingML
content . Xdr = NameSpaceDrawingMLSpreadSheet
_ , ok := f . XLSX [ path ]
if ok { // Append Model
decodeWsDr := decodeWsDr { }
_ = xml . Unmarshal ( namespaceStrictToTransitional ( f . readXML ( path ) ) , & decodeWsDr )
content . R = decodeWsDr . R
cNvPrID = len ( decodeWsDr . OneCellAnchor ) + len ( decodeWsDr . TwoCellAnchor ) + 1
for _ , v := range decodeWsDr . OneCellAnchor {
content . OneCellAnchor = append ( content . OneCellAnchor , & xdrCellAnchor {
EditAs : v . EditAs ,
GraphicFrame : v . Content ,
} )
}
for _ , v := range decodeWsDr . TwoCellAnchor {
content . TwoCellAnchor = append ( content . TwoCellAnchor , & xdrCellAnchor {
EditAs : v . EditAs ,
GraphicFrame : v . Content ,
} )
}
2017-04-23 00:10:23 +08:00
}
2019-02-25 22:14:34 +08:00
f . Drawings [ path ] = & content
2017-04-23 00:10:23 +08:00
}
2019-02-25 22:14:34 +08:00
return f . Drawings [ path ] , cNvPrID
2017-05-24 14:17:35 +08:00
}
2018-08-06 10:21:24 +08:00
// addDrawingChart provides a function to add chart graphic frame by given
// sheet, drawingXML, cell, width, height, relationship index and format sets.
2019-03-23 20:08:06 +08:00
func ( f * File ) addDrawingChart ( sheet , drawingXML , cell string , width , height , rID int , formatSet * formatPicture ) error {
col , row , err := CellNameToCoordinates ( cell )
if err != nil {
return err
}
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
colIdx := col - 1
rowIdx := row - 1
2017-05-24 14:17:35 +08:00
width = int ( float64 ( width ) * formatSet . XScale )
height = int ( float64 ( height ) * formatSet . YScale )
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
colStart , rowStart , _ , _ , colEnd , rowEnd , x2 , y2 :=
f . positionObjectPixels ( sheet , colIdx , rowIdx , formatSet . OffsetX , formatSet . OffsetY , width , height )
2019-02-25 22:14:34 +08:00
content , cNvPrID := f . drawingParser ( drawingXML )
2017-04-30 20:03:43 +08:00
twoCellAnchor := xdrCellAnchor { }
2018-04-26 11:41:13 +08:00
twoCellAnchor . EditAs = formatSet . Positioning
2017-04-23 00:10:23 +08:00
from := xlsxFrom { }
from . Col = colStart
from . ColOff = formatSet . OffsetX * EMU
from . Row = rowStart
from . RowOff = formatSet . OffsetY * EMU
to := xlsxTo { }
to . Col = colEnd
to . ColOff = x2 * EMU
to . Row = rowEnd
to . RowOff = y2 * EMU
twoCellAnchor . From = & from
twoCellAnchor . To = & to
2017-04-30 20:03:43 +08:00
graphicFrame := xlsxGraphicFrame {
NvGraphicFramePr : xlsxNvGraphicFramePr {
CNvPr : & xlsxCNvPr {
ID : f . countCharts ( ) + f . countMedia ( ) + 1 ,
Name : "Chart " + strconv . Itoa ( cNvPrID ) ,
2017-04-23 00:10:23 +08:00
} ,
2017-04-30 20:03:43 +08:00
} ,
Graphic : & xlsxGraphic {
GraphicData : & xlsxGraphicData {
URI : NameSpaceDrawingMLChart ,
Chart : & xlsxChart {
C : NameSpaceDrawingMLChart ,
R : SourceRelationship ,
RID : "rId" + strconv . Itoa ( rID ) ,
2017-04-23 00:10:23 +08:00
} ,
} ,
} ,
}
graphic , _ := xml . Marshal ( graphicFrame )
2017-04-30 20:03:43 +08:00
twoCellAnchor . GraphicFrame = string ( graphic )
twoCellAnchor . ClientData = & xdrClientData {
2017-04-23 00:10:23 +08:00
FLocksWithSheet : formatSet . FLocksWithSheet ,
FPrintsWithSheet : formatSet . FPrintsWithSheet ,
}
2017-04-30 20:03:43 +08:00
content . TwoCellAnchor = append ( content . TwoCellAnchor , & twoCellAnchor )
2019-02-25 22:14:34 +08:00
f . Drawings [ drawingXML ] = content
2019-03-23 20:08:06 +08:00
return err
2017-04-23 00:10:23 +08:00
}