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

Feature question - double lined x-axis legend #439

Closed
hirschferkel opened this issue Jun 6, 2018 · 2 comments
Closed

Feature question - double lined x-axis legend #439

hirschferkel opened this issue Jun 6, 2018 · 2 comments
Labels

Comments

@hirschferkel
Copy link

Hi there,

ist it possible with billboard to create a double lined x-axis legend like in this example made with charts.js?
https://www.merics.org/en/china-monitor/content/5401#5406
Best, hirschferkel

@hirschferkel hirschferkel changed the title Feature question Feature question - double lined x-axis legend Jun 6, 2018
@netil netil added the question label Jun 7, 2018
@netil
Copy link
Member

netil commented Jun 8, 2018

Hi @hirschferkel, just for now it doesn't have the support of multiple axes option.
But we have plan to implement on it (Ref. #98).

Just for now, you can implement another x axis manually.
I made an example to take in reference.

onrendered: function() {
	const h = this.height;
	let i = 0;
	const x2Axis = this.svg.select(".bb-axis-x2");
	
	// check more d3's axis API: https://github.com/d3/d3-axis#api-reference
	const x2 = d3.axisBottom(this.x)
		.ticks(24)
		.tickFormat(function() {
		    const quarter = ["Q1", "Q2", "Q3", "Q4"];
		
			return quarter[i++ % 4];
		});

	if (x2Axis.empty()) {
		setTimeout(() => {
			this.svg.attr("height", h + 50);
		
			// append new x2 axis
		        this.svg.select("g")
		            .append("g")
		            .attr("class", "bb-axis bb-axis-x2")
			    .style("shape-rendering", "crispEdges")
		            .attr("transform", `translate(0,${h + 25})`)
		            .call(x2);
	    }, 100);
	}
}

With above code, you'll get:
image

Checkout the online working demo:

@hirschferkel
Copy link
Author

Thanks for this solution, that's what I was searching for.
All the best

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

No branches or pull requests

2 participants