mirror of
https://github.com/unidoc/unioffice.git
synced 2025-04-25 13:48:53 +08:00
spreadsheet: add support for scatter charts
This commit is contained in:
parent
3cfef7d6e9
commit
744babf1bd
@ -32,7 +32,7 @@ func main() {
|
||||
// make it a bit wider than the default
|
||||
anc.BottomRight().SetCol(15)
|
||||
|
||||
lc := chart.AddLineChart()
|
||||
lc := chart.AddScatterChart()
|
||||
priceSeries := lc.AddSeries()
|
||||
priceSeries.SetText("Price")
|
||||
// Set a category axis reference on the first series to pull the product names
|
||||
|
@ -191,6 +191,17 @@ func (c Chart) AddSurface3DChart() Surface3DChart {
|
||||
return b
|
||||
}
|
||||
|
||||
// AddScatterChart adds a scatter (X/Y) chart.
|
||||
func (c Chart) AddScatterChart() ScatterChart {
|
||||
chc := crt.NewCT_PlotAreaChoice()
|
||||
c.x.Chart.PlotArea.Choice = append(c.x.Chart.PlotArea.Choice, chc)
|
||||
chc.ScatterChart = crt.NewCT_ScatterChart()
|
||||
|
||||
b := ScatterChart{x: chc.ScatterChart}
|
||||
b.InitializeDefaults()
|
||||
return b
|
||||
}
|
||||
|
||||
// Properties returns the chart's shape properties.
|
||||
func (c Chart) Properties() drawing.ShapeProperties {
|
||||
if c.x.SpPr == nil {
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
crt "baliance.com/gooxml/schema/schemas.openxmlformats.org/drawingml/2006/chart"
|
||||
)
|
||||
|
||||
// LineChartSeries is the data series for a line chart.
|
||||
type LineChartSeries struct {
|
||||
x *crt.CT_LineSer
|
||||
}
|
||||
|
48
chart/scatterchart.go
Normal file
48
chart/scatterchart.go
Normal file
@ -0,0 +1,48 @@
|
||||
// Copyright 2017 Baliance. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by the terms of the Affero GNU General
|
||||
// Public License version 3.0 as published by the Free Software Foundation and
|
||||
// appearing in the file LICENSE included in the packaging of this file. A
|
||||
// commercial license can be purchased by contacting sales@baliance.com.
|
||||
|
||||
package chart
|
||||
|
||||
import (
|
||||
crt "baliance.com/gooxml/schema/schemas.openxmlformats.org/drawingml/2006/chart"
|
||||
)
|
||||
|
||||
type ScatterChart struct {
|
||||
chartBase
|
||||
x *crt.CT_ScatterChart
|
||||
}
|
||||
|
||||
// X returns the inner wrapped XML type.
|
||||
func (c ScatterChart) X() *crt.CT_ScatterChart {
|
||||
return c.x
|
||||
}
|
||||
|
||||
func (c ScatterChart) InitializeDefaults() {
|
||||
c.x.ScatterStyle.ValAttr = crt.ST_ScatterStyleMarker
|
||||
}
|
||||
|
||||
// AddSeries adds a default series to a Scatter chart.
|
||||
func (c ScatterChart) AddSeries() ScatterChartSeries {
|
||||
color := c.nextColor(len(c.x.Ser))
|
||||
ser := crt.NewCT_ScatterSer()
|
||||
c.x.Ser = append(c.x.Ser, ser)
|
||||
ser.Idx.ValAttr = uint32(len(c.x.Ser) - 1)
|
||||
ser.Order.ValAttr = uint32(len(c.x.Ser) - 1)
|
||||
|
||||
ls := ScatterChartSeries{ser}
|
||||
ls.InitializeDefaults()
|
||||
ls.Marker().Properties().LineProperties().SetSolidFill(color)
|
||||
ls.Marker().Properties().SetSolidFill(color)
|
||||
return ls
|
||||
}
|
||||
|
||||
// AddAxis adds an axis to a Scatter chart.
|
||||
func (c ScatterChart) AddAxis(axis Axis) {
|
||||
axisID := crt.NewCT_UnsignedInt()
|
||||
axisID.ValAttr = axis.AxisID()
|
||||
c.x.AxId = append(c.x.AxId, axisID)
|
||||
}
|
105
chart/scatterchartseries.go
Normal file
105
chart/scatterchartseries.go
Normal file
@ -0,0 +1,105 @@
|
||||
// Copyright 2017 Baliance. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by the terms of the Affero GNU General
|
||||
// Public License version 3.0 as published by the Free Software Foundation and
|
||||
// appearing in the file LICENSE included in the packaging of this file. A
|
||||
// commercial license can be purchased by contacting sales@baliance.com.
|
||||
|
||||
package chart
|
||||
|
||||
import (
|
||||
"baliance.com/gooxml/drawing"
|
||||
dml "baliance.com/gooxml/schema/schemas.openxmlformats.org/drawingml"
|
||||
crt "baliance.com/gooxml/schema/schemas.openxmlformats.org/drawingml/2006/chart"
|
||||
)
|
||||
|
||||
// ScatterChartSeries is the data series for a scatter chart.
|
||||
type ScatterChartSeries struct {
|
||||
x *crt.CT_ScatterSer
|
||||
}
|
||||
|
||||
// X returns the inner wrapped XML type.
|
||||
func (c ScatterChartSeries) X() *crt.CT_ScatterSer {
|
||||
return c.x
|
||||
}
|
||||
|
||||
// Index returns the index of the series
|
||||
func (c ScatterChartSeries) Index() uint32 {
|
||||
return c.x.Idx.ValAttr
|
||||
}
|
||||
|
||||
// SetIndex sets the index of the series
|
||||
func (c ScatterChartSeries) SetIndex(idx uint32) {
|
||||
c.x.Idx.ValAttr = idx
|
||||
}
|
||||
|
||||
// Order returns the order of the series
|
||||
func (c ScatterChartSeries) Order() uint32 {
|
||||
return c.x.Order.ValAttr
|
||||
}
|
||||
|
||||
// SetOrder sets the order of the series
|
||||
func (c ScatterChartSeries) SetOrder(idx uint32) {
|
||||
c.x.Order.ValAttr = idx
|
||||
}
|
||||
|
||||
// SetText sets the series text
|
||||
func (c ScatterChartSeries) SetText(s string) {
|
||||
c.x.Tx = crt.NewCT_SerTx()
|
||||
c.x.Tx.Choice.V = &s
|
||||
}
|
||||
|
||||
// Properties returns the line chart series shape properties.
|
||||
func (c ScatterChartSeries) Properties() drawing.ShapeProperties {
|
||||
if c.x.SpPr == nil {
|
||||
c.x.SpPr = dml.NewCT_ShapeProperties()
|
||||
}
|
||||
return drawing.MakeShapeProperties(c.x.SpPr)
|
||||
}
|
||||
|
||||
// Marker returns the marker properties.
|
||||
func (c ScatterChartSeries) Marker() Marker {
|
||||
if c.x.Marker == nil {
|
||||
c.x.Marker = crt.NewCT_Marker()
|
||||
}
|
||||
return MakeMarker(c.x.Marker)
|
||||
}
|
||||
|
||||
// Labels returns the data label properties.
|
||||
func (c ScatterChartSeries) Labels() DataLabels {
|
||||
if c.x.DLbls == nil {
|
||||
c.x.DLbls = crt.NewCT_DLbls()
|
||||
}
|
||||
return MakeDataLabels(c.x.DLbls)
|
||||
}
|
||||
|
||||
func (c ScatterChartSeries) CategoryAxis() CategoryAxisDataSource {
|
||||
if c.x.XVal == nil {
|
||||
c.x.XVal = crt.NewCT_AxDataSource()
|
||||
}
|
||||
return MakeAxisDataSource(c.x.XVal)
|
||||
}
|
||||
|
||||
func (c ScatterChartSeries) Values() NumberDataSource {
|
||||
if c.x.YVal == nil {
|
||||
c.x.YVal = crt.NewCT_NumDataSource()
|
||||
}
|
||||
return MakeNumberDataSource(c.x.YVal)
|
||||
}
|
||||
|
||||
func (c ScatterChartSeries) SetSmooth(b bool) {
|
||||
c.x.Smooth = crt.NewCT_Boolean()
|
||||
c.x.Smooth.ValAttr = &b
|
||||
}
|
||||
|
||||
func (c ScatterChartSeries) InitializeDefaults() {
|
||||
// turn off the line
|
||||
c.Properties().LineProperties().SetNoFill()
|
||||
c.Marker().SetSymbol(crt.ST_MarkerStyleAuto)
|
||||
c.Labels().SetShowLegendKey(false)
|
||||
c.Labels().SetShowValue(true)
|
||||
c.Labels().SetShowPercent(false)
|
||||
c.Labels().SetShowCategoryName(false)
|
||||
c.Labels().SetShowSeriesName(false)
|
||||
c.Labels().SetShowLeaderLines(false)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user