diff --git a/README.md b/README.md index 8f3f3369d..0afcca3a8 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ > If a language can be used to build web scrapers, it definitely needs to provide a graceful data visualization library. --- by dongdong. -In the Golang ecosystem, there are not many choices for data visualization libraries. The development of [go-echarts](https://github.com/go-echarts/go-echarts) aims to provide a simple yet powerful data visualization library for Golang. [Echarts](https://echarts.apache.org/) is an outstanding charting and visualization library opensourced by Baidu, it supports adorable chart types and various interactive features. There are many language bindings for Echarts, for example, [pyecharts](https://github.com/pyecharts/pyecharts). go-echarts learns from pyecharts and has evolved a lot. +In the Golang ecosystem, there are not many choices for data visualization libraries. The development of [go-echarts](https://github.com/go-echarts/go-echarts) aims to provide a simple yet powerful data visualization library for Golang. [Apache ECharts](https://echarts.apache.org/) is an outstanding charting and visualization library, it supports adorable chart types and various interactive features. There are many language bindings for Echarts, for example, [pyecharts](https://github.com/pyecharts/pyecharts). go-echarts learns from pyecharts and has evolved a lot. [中文 README](README_CN.md) diff --git a/README_CN.md b/README_CN.md index 6b71dcfe7..2b0e1b4df 100644 --- a/README_CN.md +++ b/README_CN.md @@ -27,7 +27,7 @@ > 如果一门语言可以用来写爬虫,那么它就需要一个优雅的数据可视化库。 --- by dongdong -在 Golang 这门语言中,目前数据可视化的第三方库还是特别少,[go-echarts](https://github.com/go-echarts/go-echarts) 的开发就是为了填补这部分的空隙。[Echarts](http://echarts.apche.com/) 是百度开源的非常优秀的可视化图表库,凭借着良好的交互性,精巧的图表设计,得到了众多开发者的认可。也有其他语言为其实现了相应语言版本的接口,如 Python 的 [pyecharts](https://github.com/pyecharts/pyecharts),go-echarts 也是借鉴了 pyecharts 的一些设计思想。 +在 Golang 这门语言中,目前数据可视化的第三方库还是特别少,[go-echarts](https://github.com/go-echarts/go-echarts) 的开发就是为了填补这部分的空隙。[Apache ECharts](http://echarts.apache.org/) 是非常优秀的可视化图表库,凭借着良好的交互性,精巧的图表设计,得到了众多开发者的认可。也有其他语言为其实现了相应语言版本的接口,如 Python 的 [pyecharts](https://github.com/pyecharts/pyecharts),go-echarts 也是借鉴了 pyecharts 的一些设计思想。 ### 🔰 安装 diff --git a/charts/bar.go b/charts/bar.go index a4c884bd1..56809bdef 100644 --- a/charts/bar.go +++ b/charts/bar.go @@ -25,6 +25,13 @@ func NewBar() *Bar { 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 diff --git a/charts/base.go b/charts/base.go index a922d5bcb..e115eae0f 100644 --- a/charts/base.go +++ b/charts/base.go @@ -11,10 +11,13 @@ type GlobalOpts func(bc *BaseConfiguration) // BaseConfiguration represents an option set needed by all chart types. type BaseConfiguration struct { - opts.Legend `json:"legend"` - opts.Tooltip `json:"tooltip"` - opts.Toolbox `json:"toolbox"` - opts.Title `json:"title"` + opts.Legend `json:"legend"` + opts.Tooltip `json:"tooltip"` + opts.Toolbox `json:"toolbox"` + opts.Title `json:"title"` + opts.Polar `json:"polar"` + opts.AngleAxis `json:"angleAxis"` + opts.RadiusAxis `json:"radiusAxis"` render.Renderer `json:"-"` opts.Initialization `json:"-"` @@ -52,6 +55,7 @@ type BaseConfiguration struct { hasRadar bool hasParallel bool hasSingleAxis bool + hasPolar bool } // JSON wraps all the options to a map so that it could be used in the base template @@ -66,6 +70,12 @@ func (bc *BaseConfiguration) JSON() map[string]interface{} { "series": bc.MultiSeries, } + if bc.hasPolar { + obj["polar"] = bc.Polar + obj["angleAxis"] = bc.AngleAxis + obj["radiusAxis"] = bc.RadiusAxis + } + if bc.hasGeo { obj["geo"] = bc.GeoComponent } @@ -132,8 +142,8 @@ func (bc *BaseConfiguration) initBaseConfiguration() { func (bc *BaseConfiguration) initSeriesColors() { bc.Colors = []string{ - "#c23531", "#2f4554", "#61a0a8", "#d48265", "#91c7ae", - "#749f83", "#ca8622", "#bda29a", "#6e7074", "#546570", + "#5470c6", "#91cc75", "#fac858", "#ee6666", "#73c0de", + "#3ba272", "#fc8452", "#9a60b4", "#ea7ccc", } } @@ -152,6 +162,27 @@ func (bc *BaseConfiguration) setBaseGlobalOptions(opts ...GlobalOpts) { } } +// WithPolarOps set angleAxis +func WithAngleAxisOps(opt opts.AngleAxis) GlobalOpts { + return func(bc *BaseConfiguration) { + bc.AngleAxis = opt + } +} + +// WithPolarOps set radiusAxis +func WithRadiusAxisOps(opt opts.RadiusAxis) GlobalOpts { + return func(bc *BaseConfiguration) { + bc.RadiusAxis = opt + } +} + +// WithPolarOps set polar +func WithPolarOps(opt opts.Polar) GlobalOpts { + return func(bc *BaseConfiguration) { + bc.Polar = opt + } +} + // WithTitleOpts func WithTitleOpts(opt opts.Title) GlobalOpts { return func(bc *BaseConfiguration) { @@ -191,7 +222,9 @@ func WithLegendOpts(opt opts.Legend) GlobalOpts { func WithInitializationOpts(opt opts.Initialization) GlobalOpts { return func(bc *BaseConfiguration) { bc.Initialization = opt - if bc.Initialization.Theme != "" { + if bc.Initialization.Theme != "" && + bc.Initialization.Theme != "white" && + bc.Initialization.Theme != "dark" { bc.JSAssets.Add("themes/" + opt.Theme + ".js") } bc.Initialization.Validate() diff --git a/charts/series.go b/charts/series.go index 78831cd85..2a2d5908c 100644 --- a/charts/series.go +++ b/charts/series.go @@ -14,6 +14,8 @@ type SingleSeries struct { // Bar BarGap string `json:"barGap,omitempty"` BarCategoryGap string `json:"barCategoryGap,omitempty"` + ShowBackground bool `json:"showBackground,omitempty"` + RoundCap bool `json:"roundCap,omitempty"` // Bar3D Shading string `json:"shading,omitempty"` @@ -121,6 +123,10 @@ func WithBarChartOpts(opt opts.BarChart) SeriesOpts { s.BarCategoryGap = opt.BarCategoryGap s.XAxisIndex = opt.XAxisIndex s.YAxisIndex = opt.YAxisIndex + s.ShowBackground = opt.ShowBackground + s.RoundCap = opt.RoundCap + s.CoordSystem = opt.CoordSystem + s.Type = opt.Type } } diff --git a/opts/charts.go b/opts/charts.go index 6fc3a197e..769a6440d 100644 --- a/opts/charts.go +++ b/opts/charts.go @@ -3,6 +3,7 @@ package opts // BarChart // https://echarts.apache.org/en/option.html#series-bar type BarChart struct { + Type string // Name of stack. On the same category axis, the series with the // same stack name would be put on top of each other. Stack string @@ -28,6 +29,10 @@ type BarChart struct { // Index of y axis to combine with, which is useful for multiple y axes in one chart. YAxisIndex int + + ShowBackground bool + RoundCap bool + CoordSystem string } // BarData diff --git a/opts/global.go b/opts/global.go index 01998969d..1599ca794 100644 --- a/opts/global.go +++ b/opts/global.go @@ -915,6 +915,49 @@ type ParallelAxis struct { Data interface{} `json:"data,omitempty"` } +// Polar Bar options +type Polar struct { + ID string `json:"id,omitempty"` + Zlevel int `json:"zlevel,omitempty"` + Z int `json:"z,omitempty"` + Center [2]string `json:"center,omitempty"` + Radius [2]string `json:"radius,omitempty"` + Tooltip Tooltip `json:"tooltip,omitempty"` +} + +type PolarAxisBase struct { + ID string `json:"id,omitempty"` + PolarIndex int `json:"polarIndex,omitempty"` + StartAngle float64 `json:"startAngle,omitempty"` + Type string `json:"type,omitempty"` + BoundaryGap bool `json:"boundaryGap,omitempty"` + Min float64 `json:"min,omitempty"` + Max float64 `json:"max,omitempty"` + Scale bool `json:"scale,omitempty"` + SplitNumber int `json:"splitNumber,omitempty"` + MinInterval float64 `json:"minInterval,omitempty"` + MaxInterval float64 `json:"maxInterval,omitempty"` + Interval float64 `json:"interval,omitempty"` + LogBase float64 `json:"logBase,omitempty"` + Silent bool `json:"silent,omitempty"` + TriggerEvent bool `json:"triggerEvent,omitempty"` +} + +type AngleAxis struct { + PolarAxisBase + Clockwise bool `json:"clockwise,omitempty"` +} + +type RadiusAxis struct { + PolarAxisBase + Name string `json:"name,omitempty"` + NameLocation string `json:"nameLocation,omitempty"` + NameTextStyle TextStyle `json:"nameTextStyle,omitempty"` + NameGap float64 `json:"nameGap,omitempty"` + NameRadius float64 `json:"nameRotate,omitempty"` + Inverse bool `json:"inverse,omitempty"` +} + var funcPat = regexp.MustCompile(`\n|\t`) const funcMarker = "__f__"