diff --git a/charts/series.go b/charts/series.go index e777c47cd..764b4c57a 100644 --- a/charts/series.go +++ b/charts/series.go @@ -11,18 +11,21 @@ type SingleSeries struct { Type string `json:"type,omitempty"` // Rectangular charts - // Line + // Line | Bar Stack string `json:"stack,omitempty"` - // Line + // Line | Bar XAxisIndex int `json:"xAxisIndex,omitempty"` - // Line + // Line | Bar YAxisIndex int `json:"yAxisIndex,omitempty"` // Bar - BarGap string `json:"barGap,omitempty"` - BarCategoryGap string `json:"barCategoryGap,omitempty"` + BarGap string `json:"barGap,omitempty"` + // Bar + BarCategoryGap string `json:"barCategoryGap,omitempty"` + // Bar ShowBackground types.Bool `json:"showBackground,omitempty"` - RoundCap types.Bool `json:"roundCap,omitempty"` + // Bar + RoundCap types.Bool `json:"roundCap,omitempty"` // Bar3D Shading string `json:"shading,omitempty"` @@ -48,9 +51,9 @@ type SingleSeries struct { BarMinWidth string `json:"barMinWidth,omitempty"` BarMaxWidth string `json:"barMaxWidth,omitempty"` - // Line + // Line | Bar ColorBy string `json:"colorBy,omitempty"` - // Line + // Line | Bar PolarIndex int `json:"polarIndex,omitempty"` // Line Step interface{} `json:"step,omitempty"` @@ -70,7 +73,7 @@ type SingleSeries struct { // Map MapType string `json:"map,omitempty"` - // Map | Line + // Map | Line | Bar CoordSystem string `json:"coordinateSystem,omitempty"` // Pie @@ -238,14 +241,16 @@ func WithCircularStyleOpts(opt opts.CircularStyle) SeriesOpts { // WithBarChartOpts sets the BarChart option. func WithBarChartOpts(opt opts.BarChart) SeriesOpts { return func(s *SingleSeries) { - s.Stack = opt.Stack - s.BarGap = opt.BarGap - s.BarCategoryGap = opt.BarCategoryGap + s.ColorBy = opt.ColorBy + s.CoordSystem = opt.CoordSystem s.XAxisIndex = opt.XAxisIndex s.YAxisIndex = opt.YAxisIndex - s.ShowBackground = opt.ShowBackground + s.PolarIndex = opt.PolarIndex s.RoundCap = opt.RoundCap - s.CoordSystem = opt.CoordSystem + s.ShowBackground = opt.ShowBackground + s.Stack = opt.Stack + s.BarGap = opt.BarGap + s.BarCategoryGap = opt.BarCategoryGap } } diff --git a/opts/charts.go b/opts/charts.go index 158350c13..d05bb8aa4 100644 --- a/opts/charts.go +++ b/opts/charts.go @@ -2,41 +2,6 @@ package opts import "github.com/go-echarts/go-echarts/v2/types" -// 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 - - // The gap between bars between different series, is a percent value like '30%', - // which means 30% of the bar width. - // Set barGap as '-100%' can overlap bars that belong to different series, - // which is useful when putting a series of bar as background. - // In a single coordinate system, this attribute is shared by multiple 'bar' series. - // This attribute should be set on the last 'bar' series in the coordinate system, - // then it will be adopted by all 'bar' series in the coordinate system. - BarGap string - - // The bar gap of a single series, defaults to be 20% of the category gap, - // can be set as a fixed value. - // In a single coordinate system, this attribute is shared by multiple 'bar' series. - // This attribute should be set on the last 'bar' series in the coordinate system, - // then it will be adopted by all 'bar' series in the coordinate system. - BarCategoryGap string - - // Index of x axis to combine with, which is useful for multiple x axes in one chart. - XAxisIndex int - - // Index of y axis to combine with, which is useful for multiple y axes in one chart. - YAxisIndex int - - ShowBackground types.Bool - RoundCap types.Bool - CoordSystem string -} - // SunburstChart // https://echarts.apache.org/en/option.html#series-sunburst type SunburstChart struct { diff --git a/opts/series_bar.go b/opts/series_bar.go new file mode 100644 index 000000000..18b19cc2c --- /dev/null +++ b/opts/series_bar.go @@ -0,0 +1,54 @@ +package opts + +import "github.com/go-echarts/go-echarts/v2/types" + +// BarChart +// https://echarts.apache.org/en/option.html#series-bar +type BarChart struct { + // ColorBy The policy to take color from option.color. Valid values: + // 'series': assigns the colors in the palette by series, so that all data in the same series are in the same color; + // 'data': assigns colors in the palette according to data items, with each data item using a different color. + ColorBy string + + // CoordinateSystem The coordinate used in the series, whose options are: + //'cartesian2d' Use a two-dimensional rectangular coordinate (also known as Cartesian coordinate), with xAxisIndex and + // yAxisIndex to assign the corresponding axis component. + // + // 'polar' Use polar coordinates, with polarIndex to assign the corresponding polar coordinate component. + CoordSystem string + + // Index of x axis to combine with, which is useful for multiple x axes in one chart. + XAxisIndex int + + // Index of y axis to combine with, which is useful for multiple y axes in one chart. + YAxisIndex int + + // Index of polar coordinate to combine with, which is useful for multiple polar axes in one chart. + PolarIndex int + + // Whether to add round caps at the end of the bar sectors. Valid only for bar series on polar coordinates. + RoundCap types.Bool + + // Whether to show background behind each bar. Use backgroundStyle to set background style. + ShowBackground types.Bool + + // 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 + + // The gap between bars between different series, is a percent value like '30%', + // which means 30% of the bar width. + // Set barGap as '-100%' can overlap bars that belong to different series, + // which is useful when putting a series of bar as background. + // In a single coordinate system, this attribute is shared by multiple 'bar' series. + // This attribute should be set on the last 'bar' series in the coordinate system, + // then it will be adopted by all 'bar' series in the coordinate system. + BarGap string + + // The bar gap of a single series, defaults to be 20% of the category gap, + // can be set as a fixed value. + // In a single coordinate system, this attribute is shared by multiple 'bar' series. + // This attribute should be set on the last 'bar' series in the coordinate system, + // then it will be adopted by all 'bar' series in the coordinate system. + BarCategoryGap string +}