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

Gradient fills in barchart #397

Closed
flipcode1973 opened this issue May 3, 2018 · 4 comments
Closed

Gradient fills in barchart #397

flipcode1973 opened this issue May 3, 2018 · 4 comments
Assignees

Comments

@flipcode1973
Copy link

Are gradient fills possible in barcharts? Something like the following mockup?
capture
or
capture2
I have been grappling with code (based on code I found online to do something similar), something like the following...

oninit: function () {
				d3.select('svg').append("linearGradient")
					.attr("id", "svgGradient")
					.attr("gradientUnits", "userSpaceOnUse")
					.attr("x1", 0).attr("y1", 0)
					.attr("x2", 0).attr("y2", 100)
					.selectAll("stop")
					.data([
						{ offset: "0%", color: "red", opacity: 1},
						{ offset: "100%", color: "blue", opacity: 1 }
					])
					.enter().append("stop")
					.attr("offset", function (d) { return d.offset; })
					.attr("stop-color", function (d) { return d.color; })
					.attr("stop-opacity", function (d) { return d.opacity; });
			}

where I would insert the gradient and subsequently use 'svgGradient' as a colour but I can't get it to fill the bars accordingly. Is it possible to have gradient fills in Billboard.js?
Thanks

@netil
Copy link
Member

netil commented May 5, 2018

It needs to check on that. Did you tried color.tiles option?

@watnab
Copy link

watnab commented Jun 23, 2020

The first image looks like https://naver.github.io/billboard.js/demo/#ChartOptions.ColorTiles3 .
However it seems there is a trick in the example to separate positive and negative areas.

@watnab
Copy link

watnab commented Jun 24, 2020

Gradient fills in barchart
separate positive and negative areas.

There seems to be a way to separate positive and negative areas with gradient fill when chart type is bar.
https://jsfiddle.net/xLuw6b4e/

https://naver.github.io/billboard.js/release/latest/doc/Options.html#.data%25E2%2580%25A4color

it must return a string that represents color (e.g. '#00ff00').

It seems returned value can be reference to gradient in other svg (e.g. 'url(#idOfGradient)').

However this way will not work when chart type is area because returned value will be used for not area but data point.

However this issue can be closed because there is a way to gradient fill (separete areas) in barchart.

@watnab
Copy link

watnab commented Jun 24, 2020

there is a trick in the example

It may possibly be that gradientTransform can adjust position of gradient though.

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/gradientTransform

@netil netil added the request label Sep 26, 2022
@netil netil self-assigned this Sep 26, 2022
netil added a commit to netil/billboard.js that referenced this issue Sep 27, 2022
Implement gradient color for bar

Ref naver#397
@netil netil closed this as completed in 3a9989f Sep 27, 2022
github-actions bot pushed a commit that referenced this issue Sep 29, 2022
# [3.6.0](3.5.1...3.6.0) (2022-09-29)

### Bug Fixes

* **area:** Fix unnecessary area element generation ([d43a1a7](d43a1a7)), closes [#2826](#2826)
* **axis:** fix undefined error reading generatedTicks ([4f3c101](4f3c101)), closes [#2786](#2786)
* **data:** Fix idConverter error ([98f7103](98f7103)), closes [#2808](#2808)
* **gauge:** Fix size mismatch w/o gauge multi label text is hidden ([6ee8a1e](6ee8a1e)), closes [#2799](#2799)
* **grid:** Remove grid.y.ticks default value ([4818e44](4818e44)), closes [#2809](#2809)
* **legend:** Add default for legend.contents.template ([55fbb02](55fbb02)), closes [#2780](#2780)
* **type:** Add missing polar module export ([a950abd](a950abd)), closes [#2833](#2833)
* **typescript:** update entry point in tsconfig ([ab4d98d](ab4d98d)), closes [#2855](#2855)
* **types:** Fix legend.item.tile.type literal type typo ([de9781f](de9781f))
* **types:** Fix the type declarations for the y tick format ([1d378e0](1d378e0)), closes [#2790](#2790)
* **types:** Fix the type declarations for the y tick format ([#2865](#2865)) ([2e38dee](2e38dee))

### Features

* **api:** Enhance .config() to return generation options ([455944e](455944e)), closes [#2864](#2864)
* **options:** Intent to ship bar.linearGradient ([3a9989f](3a9989f)), closes [#397](#397)
* **options:** Intent to ship bar.overlap ([046aedb](046aedb)), closes [#2839](#2839)
* **options:** Intent to ship data.groupsZeroAs ([3de8e7a](3de8e7a)), closes [#2813](#2813)
* **options:** Intent to ship legend.item.tile.type ([c379c9f](c379c9f)), closes [#2874](#2874)
* **packages:** Intent to ship React wrapper ([4cef6ad](4cef6ad)), closes [#2838](#2838)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants