Giter VIP home page Giter VIP logo

Comments (3)

Koooooo-7 avatar Koooooo-7 commented on June 6, 2024

Since the #342 expose echarts instance finished, the JS function could be more useful with or without action/event api.i.e
Implement the official example case of echarts events.

func PieWithDispatchAction() *charts.Pie {
	const actionWithEchartsInstance = `
		let currentIndex = -1;
		setInterval(function() {
		  const myChart = %MY_ECHARTS%;
		  var dataLen = myChart.getOption().series[0].data.length;
		  myChart.dispatchAction({
			type: 'downplay',
			seriesIndex: 0,
			dataIndex: currentIndex
		  });
		  currentIndex = (currentIndex + 1) % dataLen;
		  myChart.dispatchAction({
			type: 'highlight',
			seriesIndex: 0,
			dataIndex: currentIndex
		  });
		  myChart.dispatchAction({
			type: 'showTip',
			seriesIndex: 0,
			dataIndex: currentIndex
		  });
		}, 1000);
`

	pie := charts.NewPie()
	pie.AddJSFuncStrs(actionWithEchartsInstance)
	pie.SetGlobalOptions(
		charts.WithTitleOpts(opts.Title{
			Title: "dispatchAction pie",
		}),
		charts.WithTooltipOpts(opts.Tooltip{
			Trigger:   "item",
			Formatter: "{a} <br/>{b} : {c} ({d}%)",
		}),
		charts.WithLegendOpts(opts.Legend{
			Left:   "left",
			Orient: "vertical",
		}),
	)

	pie.AddSeries("pie action", generatePieItems()).
		SetSeriesOptions(
			charts.WithLabelOpts(opts.Label{
				Show:      opts.Bool(true),
				Formatter: "{b}: {c}",
			}),
			charts.WithPieChartOpts(opts.PieChart{
				Radius: []string{"55%"},
				Center: []string{"50%", "60%"},
			}),

			charts.WithEmphasisOpts(opts.Emphasis{
				ItemStyle: &opts.ItemStyle{
					ShadowBlur:    10,
					ShadowOffsetX: 0,
					ShadowColor:   "rgba(0, 0, 0, 0.5)",
				},
			}),
		)

	return pie

}

from go-echarts.

Koooooo-7 avatar Koooooo-7 commented on June 6, 2024

Events example.

	bar := charts.NewBar()
	const JFunc = `(params) => alert(params.name)`

	bar.SetGlobalOptions(
		charts.WithInitializationOpts(opts.Initialization{
			Width:    "1200px",
			Height:   "600px",
		}),
		charts.WithEventListeners(
			event.Listener{
				EventName: "click",
                                 // Handler:   JFunc,
				Handler:   opts.FuncOpts(JFunc),
			},
		),
	)

	bar.SetXAxis(weeks).
		AddSeries("CategoryA", generateBarItems()).
		AddSeries("Category B", generateBarItems())
	return bar

from go-echarts.

Koooooo-7 avatar Koooooo-7 commented on June 6, 2024

Action is not high priority.

from go-echarts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.