/
bar.go
63 lines (53 loc) 路 1.37 KB
/
bar.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package charts
import (
"github.com/go-echarts/go-echarts/v2/opts"
"github.com/go-echarts/go-echarts/v2/render"
"github.com/go-echarts/go-echarts/v2/types"
)
// Bar represents a bar chart.
type Bar struct {
RectChart
isXYReversal bool
}
// Type returns the chart type.
func (Bar) Type() string { return types.ChartBar }
// NewBar creates a new bar chart instance.
func NewBar() *Bar {
c := &Bar{}
c.initBaseConfiguration()
c.Renderer = render.NewChartRender(c, c.Validate)
c.hasXYAxis = true
return c
}
// EnablePolarType enable polar bar
func (c *Bar) EnablePolarType() *Bar {
c.hasXYAxis = false
c.hasPolar = true
return c
}
// SetXAxis sets the X axis.
func (c *Bar) SetXAxis(x interface{}) *Bar {
c.xAxisData = x
return c
}
// AddSeries adds the new series.
func (c *Bar) AddSeries(name string, data []opts.BarData, options ...SeriesOpts) *Bar {
series := SingleSeries{Name: name, Type: types.ChartBar, Data: data}
series.configureSeriesOpts(options...)
c.MultiSeries = append(c.MultiSeries, series)
return c
}
// XYReversal checks if X axis and Y axis are reversed.
func (c *Bar) XYReversal() *Bar {
c.isXYReversal = true
return c
}
// Validate validates the given configuration.
func (c *Bar) Validate() {
c.XAxisList[0].Data = c.xAxisData
if c.isXYReversal {
c.YAxisList[0].Data = c.xAxisData
c.XAxisList[0].Data = nil
}
c.Assets.Validate(c.AssetsHost)
}