/
line.go
45 lines (38 loc) 路 1.07 KB
/
line.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
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"
)
// Line represents a line chart.
type Line struct {
RectChart
}
// Type returns the chart type.
func (*Line) Type() string { return types.ChartLine }
// NewLine creates a new line chart.
func NewLine() *Line {
c := &Line{}
c.initBaseConfiguration()
c.Renderer = render.NewChartRender(c, c.Validate)
c.hasXYAxis = true
return c
}
// SetXAxis adds the X axis.
func (c *Line) SetXAxis(x interface{}) *Line {
c.xAxisData = x
return c
}
// AddSeries adds the new series.
func (c *Line) AddSeries(name string, data []opts.LineData, options ...SeriesOpts) *Line {
series := SingleSeries{Name: name, Type: types.ChartLine, Data: data}
series.InitSeriesDefaultOpts(c.BaseConfiguration)
series.ConfigureSeriesOpts(options...)
c.MultiSeries = append(c.MultiSeries, series)
return c
}
// Validate validates the given configuration.
func (c *Line) Validate() {
c.XAxisList[0].Data = c.xAxisData
c.Assets.Validate(c.AssetsHost)
}