Resolve #311, create 2D/3D area, stacked area, 100% stacked area chart support

formula
xuri 6 years ago
parent e7a96da2db
commit b04107c4a3
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7

@ -18,112 +18,142 @@ import (
// This section defines the currently supported chart types. // This section defines the currently supported chart types.
const ( const (
Bar = "bar" Area = "area"
BarStacked = "barStacked" AreaStacked = "areaStacked"
BarPercentStacked = "barPercentStacked" AreaPercentStacked = "areaPercentStacked"
Bar3DClustered = "bar3DClustered" Area3D = "area3D"
Bar3DStacked = "bar3DStacked" Area3DStacked = "area3DStacked"
Bar3DPercentStacked = "bar3DPercentStacked" Area3DPercentStacked = "area3DPercentStacked"
Col = "col" Bar = "bar"
ColStacked = "colStacked" BarStacked = "barStacked"
ColPercentStacked = "colPercentStacked" BarPercentStacked = "barPercentStacked"
Col3DClustered = "col3DClustered" Bar3DClustered = "bar3DClustered"
Col3D = "col3D" Bar3DStacked = "bar3DStacked"
Col3DStacked = "col3DStacked" Bar3DPercentStacked = "bar3DPercentStacked"
Col3DPercentStacked = "col3DPercentStacked" Col = "col"
Doughnut = "doughnut" ColStacked = "colStacked"
Line = "line" ColPercentStacked = "colPercentStacked"
Pie = "pie" Col3DClustered = "col3DClustered"
Pie3D = "pie3D" Col3D = "col3D"
Radar = "radar" Col3DStacked = "col3DStacked"
Scatter = "scatter" Col3DPercentStacked = "col3DPercentStacked"
Doughnut = "doughnut"
Line = "line"
Pie = "pie"
Pie3D = "pie3D"
Radar = "radar"
Scatter = "scatter"
) )
// This section defines the default value of chart properties. // This section defines the default value of chart properties.
var ( var (
chartView3DRotX = map[string]int{ chartView3DRotX = map[string]int{
Bar: 0, Area: 0,
BarStacked: 0, AreaStacked: 0,
BarPercentStacked: 0, AreaPercentStacked: 0,
Bar3DClustered: 15, Area3D: 15,
Bar3DStacked: 15, Area3DStacked: 15,
Bar3DPercentStacked: 15, Area3DPercentStacked: 15,
Col: 0, Bar: 0,
ColStacked: 0, BarStacked: 0,
ColPercentStacked: 0, BarPercentStacked: 0,
Col3DClustered: 15, Bar3DClustered: 15,
Col3D: 15, Bar3DStacked: 15,
Col3DStacked: 15, Bar3DPercentStacked: 15,
Col3DPercentStacked: 15, Col: 0,
Doughnut: 0, ColStacked: 0,
Line: 0, ColPercentStacked: 0,
Pie: 0, Col3DClustered: 15,
Pie3D: 30, Col3D: 15,
Radar: 0, Col3DStacked: 15,
Scatter: 0, Col3DPercentStacked: 15,
Doughnut: 0,
Line: 0,
Pie: 0,
Pie3D: 30,
Radar: 0,
Scatter: 0,
} }
chartView3DRotY = map[string]int{ chartView3DRotY = map[string]int{
Bar: 0, Area: 0,
BarStacked: 0, AreaStacked: 0,
BarPercentStacked: 0, AreaPercentStacked: 0,
Bar3DClustered: 20, Area3D: 20,
Bar3DStacked: 20, Area3DStacked: 20,
Bar3DPercentStacked: 20, Area3DPercentStacked: 20,
Col: 0, Bar: 0,
ColStacked: 0, BarStacked: 0,
ColPercentStacked: 0, BarPercentStacked: 0,
Col3DClustered: 20, Bar3DClustered: 20,
Col3D: 20, Bar3DStacked: 20,
Col3DStacked: 20, Bar3DPercentStacked: 20,
Col3DPercentStacked: 20, Col: 0,
Doughnut: 0, ColStacked: 0,
Line: 0, ColPercentStacked: 0,
Pie: 0, Col3DClustered: 20,
Pie3D: 0, Col3D: 20,
Radar: 0, Col3DStacked: 20,
Scatter: 0, Col3DPercentStacked: 20,
Doughnut: 0,
Line: 0,
Pie: 0,
Pie3D: 0,
Radar: 0,
Scatter: 0,
} }
chartView3DDepthPercent = map[string]int{ chartView3DDepthPercent = map[string]int{
Bar: 100, Area: 100,
BarStacked: 100, AreaStacked: 100,
BarPercentStacked: 100, AreaPercentStacked: 100,
Bar3DClustered: 100, Area3D: 100,
Bar3DStacked: 100, Area3DStacked: 100,
Bar3DPercentStacked: 100, Area3DPercentStacked: 100,
Col: 100, Bar: 100,
ColStacked: 100, BarStacked: 100,
ColPercentStacked: 100, BarPercentStacked: 100,
Col3DClustered: 100, Bar3DClustered: 100,
Col3D: 100, Bar3DStacked: 100,
Col3DStacked: 100, Bar3DPercentStacked: 100,
Col3DPercentStacked: 100, Col: 100,
Doughnut: 100, ColStacked: 100,
Line: 100, ColPercentStacked: 100,
Pie: 100, Col3DClustered: 100,
Pie3D: 100, Col3D: 100,
Radar: 100, Col3DStacked: 100,
Scatter: 100, Col3DPercentStacked: 100,
Doughnut: 100,
Line: 100,
Pie: 100,
Pie3D: 100,
Radar: 100,
Scatter: 100,
} }
chartView3DRAngAx = map[string]int{ chartView3DRAngAx = map[string]int{
Bar: 0, Area: 0,
BarStacked: 0, AreaStacked: 0,
BarPercentStacked: 0, AreaPercentStacked: 0,
Bar3DClustered: 1, Area3D: 1,
Bar3DStacked: 1, Area3DStacked: 1,
Bar3DPercentStacked: 1, Area3DPercentStacked: 1,
Col: 0, Bar: 0,
ColStacked: 0, BarStacked: 0,
ColPercentStacked: 0, BarPercentStacked: 0,
Col3DClustered: 1, Bar3DClustered: 1,
Col3D: 1, Bar3DStacked: 1,
Col3DStacked: 1, Bar3DPercentStacked: 1,
Col3DPercentStacked: 1, Col: 0,
Doughnut: 0, ColStacked: 0,
Line: 0, ColPercentStacked: 0,
Pie: 0, Col3DClustered: 1,
Pie3D: 0, Col3D: 1,
Radar: 0, Col3DStacked: 1,
Scatter: 0, Col3DPercentStacked: 1,
Doughnut: 0,
Line: 0,
Pie: 0,
Pie3D: 0,
Radar: 0,
Scatter: 0,
} }
chartLegendPosition = map[string]string{ chartLegendPosition = map[string]string{
"bottom": "b", "bottom": "b",
@ -133,41 +163,80 @@ var (
"top_right": "tr", "top_right": "tr",
} }
chartValAxNumFmtFormatCode = map[string]string{ chartValAxNumFmtFormatCode = map[string]string{
Bar: "General", Area: "General",
BarStacked: "General", AreaStacked: "General",
BarPercentStacked: "0%", AreaPercentStacked: "0%",
Bar3DClustered: "General", Area3D: "General",
Bar3DStacked: "General", Area3DStacked: "General",
Bar3DPercentStacked: "0%", Area3DPercentStacked: "0%",
Col: "General", Bar: "General",
ColStacked: "General", BarStacked: "General",
ColPercentStacked: "0%", BarPercentStacked: "0%",
Col3DClustered: "General", Bar3DClustered: "General",
Col3D: "General", Bar3DStacked: "General",
Col3DStacked: "General", Bar3DPercentStacked: "0%",
Col3DPercentStacked: "0%", Col: "General",
Doughnut: "General", ColStacked: "General",
Line: "General", ColPercentStacked: "0%",
Pie: "General", Col3DClustered: "General",
Pie3D: "General", Col3D: "General",
Radar: "General", Col3DStacked: "General",
Scatter: "General", Col3DPercentStacked: "0%",
Doughnut: "General",
Line: "General",
Pie: "General",
Pie3D: "General",
Radar: "General",
Scatter: "General",
}
chartValAxCrossBetween = map[string]string{
Area: "midCat",
AreaStacked: "midCat",
AreaPercentStacked: "midCat",
Area3D: "midCat",
Area3DStacked: "midCat",
Area3DPercentStacked: "midCat",
Bar: "between",
BarStacked: "between",
BarPercentStacked: "between",
Bar3DClustered: "between",
Bar3DStacked: "between",
Bar3DPercentStacked: "between",
Col: "between",
ColStacked: "between",
ColPercentStacked: "between",
Col3DClustered: "between",
Col3D: "between",
Col3DStacked: "between",
Col3DPercentStacked: "between",
Doughnut: "between",
Line: "between",
Pie: "between",
Pie3D: "between",
Radar: "between",
Scatter: "between",
} }
plotAreaChartGrouping = map[string]string{ plotAreaChartGrouping = map[string]string{
Bar: "clustered", Area: "standard",
BarStacked: "stacked", AreaStacked: "stacked",
BarPercentStacked: "percentStacked", AreaPercentStacked: "percentStacked",
Bar3DClustered: "clustered", Area3D: "standard",
Bar3DStacked: "stacked", Area3DStacked: "stacked",
Bar3DPercentStacked: "percentStacked", Area3DPercentStacked: "percentStacked",
Col: "clustered", Bar: "clustered",
ColStacked: "stacked", BarStacked: "stacked",
ColPercentStacked: "percentStacked", BarPercentStacked: "percentStacked",
Col3DClustered: "clustered", Bar3DClustered: "clustered",
Col3D: "standard", Bar3DStacked: "stacked",
Col3DStacked: "stacked", Bar3DPercentStacked: "percentStacked",
Col3DPercentStacked: "percentStacked", Col: "clustered",
Line: "standard", ColStacked: "stacked",
ColPercentStacked: "percentStacked",
Col3DClustered: "clustered",
Col3D: "standard",
Col3DStacked: "stacked",
Col3DPercentStacked: "percentStacked",
Line: "standard",
} }
plotAreaChartBarDir = map[string]string{ plotAreaChartBarDir = map[string]string{
Bar: "bar", Bar: "bar",
@ -262,27 +331,33 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
// //
// The following shows the type of chart supported by excelize: // The following shows the type of chart supported by excelize:
// //
// Type | Chart // Type | Chart
// ---------------------+------------------------------ // ----------------------+------------------------------
// bar | 2D clustered bar chart // area | 2D area chart
// barStacked | 2D stacked bar chart // areaStacked | 2D stacked area chart
// barPercentStacked | 2D 100% stacked bar chart // areaPercentStacked | 2D 100% stacked area chart
// bar3DClustered | 3D clustered bar chart // area3D | 3D area chart
// bar3DStacked | 3D stacked bar chart // area3DStacked | 3D stacked area chart
// bar3DPercentStacked | 3D 100% stacked bar chart // area3DPercentStacked | 3D 100% stacked area chart
// col | 2D clustered column chart // bar | 2D clustered bar chart
// colStacked | 2D stacked column chart // barStacked | 2D stacked bar chart
// colPercentStacked | 2D 100% stacked column chart // barPercentStacked | 2D 100% stacked bar chart
// col3DClustered | 3D clustered column chart // bar3DClustered | 3D clustered bar chart
// col3D | 3D column chart // bar3DStacked | 3D stacked bar chart
// col3DStacked | 3D stacked column chart // bar3DPercentStacked | 3D 100% stacked bar chart
// col3DPercentStacked | 3D 100% stacked column chart // col | 2D clustered column chart
// doughnut | doughnut chart // colStacked | 2D stacked column chart
// line | line chart // colPercentStacked | 2D 100% stacked column chart
// pie | pie chart // col3DClustered | 3D clustered column chart
// pie3D | 3D pie chart // col3D | 3D column chart
// radar | radar chart // col3DStacked | 3D stacked column chart
// scatter | scatter chart // col3DPercentStacked | 3D 100% stacked column chart
// doughnut | doughnut chart
// line | line chart
// pie | pie chart
// pie3D | 3D pie chart
// radar | radar chart
// scatter | scatter chart
// //
// In Excel a chart series is a collection of information that defines which data is plotted such as values, axis labels and formatting. // In Excel a chart series is a collection of information that defines which data is plotted such as values, axis labels and formatting.
// //
@ -546,25 +621,31 @@ func (f *File) addChart(formatSet *formatChart) {
}, },
} }
plotAreaFunc := map[string]func(*formatChart) *cPlotArea{ plotAreaFunc := map[string]func(*formatChart) *cPlotArea{
Bar: f.drawBaseChart, Area: f.drawBaseChart,
BarStacked: f.drawBaseChart, AreaStacked: f.drawBaseChart,
BarPercentStacked: f.drawBaseChart, AreaPercentStacked: f.drawBaseChart,
Bar3DClustered: f.drawBaseChart, Area3D: f.drawBaseChart,
Bar3DStacked: f.drawBaseChart, Area3DStacked: f.drawBaseChart,
Bar3DPercentStacked: f.drawBaseChart, Area3DPercentStacked: f.drawBaseChart,
Col: f.drawBaseChart, Bar: f.drawBaseChart,
ColStacked: f.drawBaseChart, BarStacked: f.drawBaseChart,
ColPercentStacked: f.drawBaseChart, BarPercentStacked: f.drawBaseChart,
Col3DClustered: f.drawBaseChart, Bar3DClustered: f.drawBaseChart,
Col3D: f.drawBaseChart, Bar3DStacked: f.drawBaseChart,
Col3DStacked: f.drawBaseChart, Bar3DPercentStacked: f.drawBaseChart,
Col3DPercentStacked: f.drawBaseChart, Col: f.drawBaseChart,
Doughnut: f.drawDoughnutChart, ColStacked: f.drawBaseChart,
Line: f.drawLineChart, ColPercentStacked: f.drawBaseChart,
Pie3D: f.drawPie3DChart, Col3DClustered: f.drawBaseChart,
Pie: f.drawPieChart, Col3D: f.drawBaseChart,
Radar: f.drawRadarChart, Col3DStacked: f.drawBaseChart,
Scatter: f.drawScatterChart, Col3DPercentStacked: f.drawBaseChart,
Doughnut: f.drawDoughnutChart,
Line: f.drawLineChart,
Pie3D: f.drawPie3DChart,
Pie: f.drawPieChart,
Radar: f.drawRadarChart,
Scatter: f.drawScatterChart,
} }
xlsxChartSpace.Chart.PlotArea = plotAreaFunc[formatSet.Type](formatSet) xlsxChartSpace.Chart.PlotArea = plotAreaFunc[formatSet.Type](formatSet)
@ -593,14 +674,48 @@ func (f *File) drawBaseChart(formatSet *formatChart) *cPlotArea {
{Val: 753999904}, {Val: 753999904},
}, },
} }
c.BarDir.Val = plotAreaChartBarDir[formatSet.Type] var ok bool
c.BarDir.Val, ok = plotAreaChartBarDir[formatSet.Type]
if !ok {
c.BarDir = nil
}
c.Grouping.Val = plotAreaChartGrouping[formatSet.Type] c.Grouping.Val = plotAreaChartGrouping[formatSet.Type]
if formatSet.Type == "colStacked" || formatSet.Type == "barStacked" || formatSet.Type == "barPercentStacked" || formatSet.Type == "colPercentStacked" { if formatSet.Type == "colStacked" || formatSet.Type == "barStacked" || formatSet.Type == "barPercentStacked" || formatSet.Type == "colPercentStacked" || formatSet.Type == "areaPercentStacked" {
c.Overlap = &attrValInt{Val: 100} c.Overlap = &attrValInt{Val: 100}
} }
catAx := f.drawPlotAreaCatAx(formatSet) catAx := f.drawPlotAreaCatAx(formatSet)
valAx := f.drawPlotAreaValAx(formatSet) valAx := f.drawPlotAreaValAx(formatSet)
charts := map[string]*cPlotArea{ charts := map[string]*cPlotArea{
"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,
},
"bar": { "bar": {
BarChart: &c, BarChart: &c,
CatAx: catAx, CatAx: catAx,
@ -826,7 +941,7 @@ func (f *File) drawChartSeriesSpPr(i int, formatSet *formatChart) *cSpPr {
}, },
}, },
} }
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} chartSeriesSpPr := map[string]*cSpPr{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: spPrLine, Pie: nil, Pie3D: nil, Radar: nil, Scatter: spPrScatter}
return chartSeriesSpPr[formatSet.Type] return chartSeriesSpPr[formatSet.Type]
} }
@ -855,7 +970,7 @@ func (f *File) drawChartSeriesDPt(i int, formatSet *formatChart) []*cDPt {
}, },
}, },
}} }}
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} chartSeriesDPt := map[string][]*cDPt{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: nil, Pie: dpt, Pie3D: dpt, Radar: nil, Scatter: nil}
return chartSeriesDPt[formatSet.Type] return chartSeriesDPt[formatSet.Type]
} }
@ -867,7 +982,7 @@ func (f *File) drawChartSeriesCat(v formatChartSeries, formatSet *formatChart) *
F: v.Categories, F: v.Categories,
}, },
} }
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} chartSeriesCat := map[string]*cCat{Area: cat, AreaStacked: cat, AreaPercentStacked: cat, Area3D: cat, Area3DStacked: cat, Area3DPercentStacked: cat, Bar: cat, BarStacked: cat, BarPercentStacked: cat, Bar3DClustered: cat, Bar3DStacked: cat, Bar3DPercentStacked: cat, Col: cat, ColStacked: cat, ColPercentStacked: cat, Col3DClustered: cat, Col3D: cat, Col3DStacked: cat, Col3DPercentStacked: cat, Doughnut: cat, Line: cat, Pie: cat, Pie3D: cat, Radar: cat, Scatter: nil}
return chartSeriesCat[formatSet.Type] return chartSeriesCat[formatSet.Type]
} }
@ -879,7 +994,7 @@ func (f *File) drawChartSeriesVal(v formatChartSeries, formatSet *formatChart) *
F: v.Values, F: v.Values,
}, },
} }
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} chartSeriesVal := map[string]*cVal{Area: val, AreaStacked: val, AreaPercentStacked: val, Area3D: val, Area3DStacked: val, Area3DPercentStacked: val, Bar: val, BarStacked: val, BarPercentStacked: val, Bar3DClustered: val, Bar3DStacked: val, Bar3DPercentStacked: val, Col: val, ColStacked: val, ColPercentStacked: val, Col3DClustered: val, Col3D: val, Col3DStacked: val, Col3DPercentStacked: val, Doughnut: val, Line: val, Pie: val, Pie3D: val, Radar: val, Scatter: nil}
return chartSeriesVal[formatSet.Type] return chartSeriesVal[formatSet.Type]
} }
@ -905,7 +1020,7 @@ func (f *File) drawChartSeriesMarker(i int, formatSet *formatChart) *cMarker {
}, },
}, },
} }
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} chartSeriesMarker := map[string]*cMarker{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: nil, Pie: nil, Pie3D: nil, Radar: nil, Scatter: marker}
return chartSeriesMarker[formatSet.Type] return chartSeriesMarker[formatSet.Type]
} }
@ -917,7 +1032,7 @@ func (f *File) drawChartSeriesXVal(v formatChartSeries, formatSet *formatChart)
F: v.Categories, F: v.Categories,
}, },
} }
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} chartSeriesXVal := map[string]*cCat{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: nil, Pie: nil, Pie3D: nil, Radar: nil, Scatter: cat}
return chartSeriesXVal[formatSet.Type] return chartSeriesXVal[formatSet.Type]
} }
@ -929,7 +1044,7 @@ func (f *File) drawChartSeriesYVal(v formatChartSeries, formatSet *formatChart)
F: v.Values, F: v.Values,
}, },
} }
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} chartSeriesYVal := map[string]*cVal{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: nil, Pie: nil, Pie3D: nil, Radar: nil, Scatter: val}
return chartSeriesYVal[formatSet.Type] return chartSeriesYVal[formatSet.Type]
} }
@ -951,7 +1066,7 @@ func (f *File) drawChartDLbls(formatSet *formatChart) *cDLbls {
// given format sets. // given format sets.
func (f *File) drawChartSeriesDLbls(formatSet *formatChart) *cDLbls { func (f *File) drawChartSeriesDLbls(formatSet *formatChart) *cDLbls {
dLbls := f.drawChartDLbls(formatSet) dLbls := f.drawChartDLbls(formatSet)
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} chartSeriesDLbls := map[string]*cDLbls{Area: dLbls, AreaStacked: dLbls, AreaPercentStacked: dLbls, Area3D: dLbls, Area3DStacked: dLbls, Area3DPercentStacked: dLbls, Bar: dLbls, BarStacked: dLbls, BarPercentStacked: dLbls, Bar3DClustered: dLbls, Bar3DStacked: dLbls, Bar3DPercentStacked: dLbls, Col: dLbls, ColStacked: dLbls, ColPercentStacked: dLbls, Col3DClustered: dLbls, Col3D: dLbls, Col3DStacked: dLbls, Col3DPercentStacked: dLbls, Doughnut: dLbls, Line: dLbls, Pie: dLbls, Pie3D: dLbls, Radar: dLbls, Scatter: nil}
return chartSeriesDLbls[formatSet.Type] return chartSeriesDLbls[formatSet.Type]
} }
@ -1025,7 +1140,7 @@ func (f *File) drawPlotAreaValAx(formatSet *formatChart) []*cAxs {
TxPr: f.drawPlotAreaTxPr(), TxPr: f.drawPlotAreaTxPr(),
CrossAx: &attrValInt{Val: 754001152}, CrossAx: &attrValInt{Val: 754001152},
Crosses: &attrValString{Val: "autoZero"}, Crosses: &attrValString{Val: "autoZero"},
CrossBetween: &attrValString{Val: "between"}, CrossBetween: &attrValString{Val: chartValAxCrossBetween[formatSet.Type]},
}, },
} }
} }

@ -959,6 +959,13 @@ func TestAddChart(t *testing.T) {
xlsx.AddChart("Sheet2", "X64", `{"type":"bar3DClustered","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"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":"left","show_legend_key":false},"title":{"name":"Fruit 3D Clustered Bar 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"}`) xlsx.AddChart("Sheet2", "X64", `{"type":"bar3DClustered","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"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":"left","show_legend_key":false},"title":{"name":"Fruit 3D Clustered Bar 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"}`)
xlsx.AddChart("Sheet2", "P80", `{"type":"bar3DStacked","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"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":"left","show_legend_key":false},"title":{"name":"Fruit 3D Stacked Bar 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","y_axis":{"maximum":7.5,"minimum":0.5}}`) xlsx.AddChart("Sheet2", "P80", `{"type":"bar3DStacked","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"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":"left","show_legend_key":false},"title":{"name":"Fruit 3D Stacked Bar 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","y_axis":{"maximum":7.5,"minimum":0.5}}`)
xlsx.AddChart("Sheet2", "X80", `{"type":"bar3DPercentStacked","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"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":"left","show_legend_key":false},"title":{"name":"Fruit 3D 100% Stacked Bar 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,"maximum":0,"minimum":0},"y_axis":{"reverse_order":true,"maximum":0,"minimum":0}}`) xlsx.AddChart("Sheet2", "X80", `{"type":"bar3DPercentStacked","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"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":"left","show_legend_key":false},"title":{"name":"Fruit 3D 100% Stacked Bar 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,"maximum":0,"minimum":0},"y_axis":{"reverse_order":true,"maximum":0,"minimum":0}}`)
// area series charts
xlsx.AddChart("Sheet2", "AF1", `{"type":"area","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"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":"left","show_legend_key":false},"title":{"name":"Fruit 2D Area 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"}`)
xlsx.AddChart("Sheet2", "AN1", `{"type":"areaStacked","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"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":"left","show_legend_key":false},"title":{"name":"Fruit 2D Stacked Area 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"}`)
xlsx.AddChart("Sheet2", "AF16", `{"type":"areaPercentStacked","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"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":"left","show_legend_key":false},"title":{"name":"Fruit 2D 100% Stacked Area 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"}`)
xlsx.AddChart("Sheet2", "AN16", `{"type":"area3D","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"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":"left","show_legend_key":false},"title":{"name":"Fruit 3D Area 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"}`)
xlsx.AddChart("Sheet2", "AF32", `{"type":"area3DStacked","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"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":"left","show_legend_key":false},"title":{"name":"Fruit 3D Stacked Area 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"}`)
xlsx.AddChart("Sheet2", "AN32", `{"type":"area3DPercentStacked","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"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":"left","show_legend_key":false},"title":{"name":"Fruit 3D 100% Stacked Area 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"}`)
// Save xlsx file by the given path. // Save xlsx file by the given path.
err = xlsx.SaveAs("./test/Book_addchart.xlsx") err = xlsx.SaveAs("./test/Book_addchart.xlsx")
if err != nil { if err != nil {

@ -301,6 +301,8 @@ type cView3D struct {
// plot area of the chart. // plot area of the chart.
type cPlotArea struct { type cPlotArea struct {
Layout *string `xml:"c:layout"` Layout *string `xml:"c:layout"`
AreaChart *cCharts `xml:"c:areaChart"`
Area3DChart *cCharts `xml:"c:area3DChart"`
BarChart *cCharts `xml:"c:barChart"` BarChart *cCharts `xml:"c:barChart"`
Bar3DChart *cCharts `xml:"c:bar3DChart"` Bar3DChart *cCharts `xml:"c:bar3DChart"`
DoughnutChart *cCharts `xml:"c:doughnutChart"` DoughnutChart *cCharts `xml:"c:doughnutChart"`

Loading…
Cancel
Save