Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add polar bar #157

Merged
merged 7 commits into from Feb 9, 2021
Merged

Feat: add polar bar #157

merged 7 commits into from Feb 9, 2021

Conversation

susiwen8
Copy link
Contributor

@susiwen8 susiwen8 commented Feb 6, 2021

New Feature

  • Polar bar

Screen Shot 2021-02-06 at 19 50 57

New API

  • EablePolarType
  • WithPolarOps
  • WithAngleAxisOps
  • WithRadiusAxisOps

Example

package main

import (
	"math/rand"
	"os"

	"github.com/go-echarts/go-echarts/v2/charts"
	"github.com/go-echarts/go-echarts/v2/opts"
	"github.com/go-echarts/go-echarts/v2/types"
)

// generate random data for bar chart
func generateBarItems() []opts.BarData {
	items := make([]opts.BarData, 0)
	for i := 0; i < 7; i++ {
		items = append(items, opts.BarData{Value: rand.Intn(300)})
	}
	return items
}

func main() {
	bar := charts.NewBar()
	bar.SetGlobalOptions(
		charts.WithInitializationOpts(opts.Initialization{Theme: "white"}),
		charts.WithTitleOpts(opts.Title{
			Title: "Polar Bar",
		}),
		charts.WithPolarOps(opts.Polar{
			Radius: [2]string{"0", "100"},
			Center: [2]string{"50%", "50%"},
			Tooltip: opts.Tooltip{
				Show: true,
			},
		}),
		charts.WithAngleAxisOps(opts.AngleAxis{
			PolarAxisBase: opts.PolarAxisBase{
				// Max:        2,
				// StartAngle: 30,
			},
		}),
		charts.WithRadiusAxisOps(opts.RadiusAxis{
			PolarAxisBase: opts.PolarAxisBase{
				Type: "category",
			},
		}),
	)
	bar.EnablePolarType().
		AddSeries("Category A", generateBarItems()).
		AddSeries("Category B", generateBarItems()).
		SetSeriesOptions(charts.WithBarChartOpts(opts.BarChart{
			Stack:          "stackA",
			ShowBackground: true,
			CoordSystem:    "polar",
			RoundCap:       true,
			Type:           types.ChartBar,
		}))
	// Where the magic happens
	f, _ := os.Create("bar.html")
	bar.Render(f)
}

TODO

update go-echarts-asset

PS

  • Apache ECharts upgrade to 5.0, I think It's time to upgrade go-echarts to v3.(no need a big upgrade, Apache ECharts has backward compatibility )

Copy link
Member

@chenjiandongx chenjiandongx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chenjiandongx chenjiandongx merged commit bf525d1 into go-echarts:master Feb 9, 2021
@susiwen8 susiwen8 deleted the polar branch February 9, 2021 02:59
@susiwen8
Copy link
Contributor Author

susiwen8 commented Feb 9, 2021

@chenjiandongx just little reminder go-echarts-asset haven't update. TODO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants