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

Example of label callback #31

Closed
lukarolak opened this issue Nov 18, 2022 · 2 comments
Closed

Example of label callback #31

lukarolak opened this issue Nov 18, 2022 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@lukarolak
Copy link

Hi, could you create an example where the formatter uses a callback to format text per series element?

charts.WithLabelOpts(
		opts.Label{
			Show:      true,
			Formatter: callback?,
		},
	)
@Koooooo-7 Koooooo-7 added the help wanted Extra attention is needed label Apr 2, 2023
@shmarlovsky
Copy link
Contributor

shmarlovsky commented Apr 5, 2023

@lukarolak
Function callback can be provided with
chart.AddCustomJS()
Example:

func makeLine() {
        ....
	line.AddCustomJS(customTooltipFormatter(line.ChartID))
	return line
}

func customTooltipFormatter(chartID string) string {

	formatterFunc := `
	function (params) {
		<callback function body>
	`
	return fmt.Sprintf(
		`goechart_%s.setOption({"tooltip": {"formatter": %s}});`,
		chartID,
		formatterFunc,
	)
}

@lukarolak
Copy link
Author

@shmarlovsky Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants