-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Bootstrap + C3; Grid layout doesn't work on load #2474
Comments
I guess that it happens because the first column occupies the whole width because it's the only column in a row when it's drawn. How about preparing the container <div id="charts" class="container">
<div class="row">
<div class="col-sm"><div id="chart0"><div></div>
<div class="col-sm"><div id="chart1"><div></div>
<div class="col-sm"><div id="chart2"><div></div>
</div>
<div class="row">
<div class="col-sm"><div id="chart3"><div></div>
<div class="col-sm"><div id="chart4"><div></div>
<div class="col-sm"><div id="chart5"><div></div>
</div>
<div class="row">
<div class="col-sm"><div id="chart6"><div></div>
<div class="col-sm"><div id="chart7"><div></div>
<div class="col-sm"><div id="chart8"><div></div>
</div>
<div class="row">
<div class="col-sm"><div id="chart9"><div></div>
<div class="col-sm"><div id="chart10"><div></div>
<div class="col-sm"><div id="chart11"><div></div>
</div>
</div> |
Here's my code now...
But now when I open the browser I see only the first donut chart. When I open the DOM inspector, |
Just noticed the typos in the HTML and corrected them.
Thanks for the tip. The charts show up in four rows of threes. But is there any way to accomplish this while drawing them? It's not absolutely necessary, but I prefer automating those |
- Follow suggestion to try fixing white vote charts: c3js/c3#2474 (comment)
I think the point is the timing between creating container elements and drawing charts. You need to create all rows and columns before drawing any charts. How about the following? <script type="text/javascript">
var dataDir = "vote-by-race";
d3.csv(dataDir+"/white.csv").then(function(data){
var row;
// Creates container rows and columns
data.forEach(function(d,i){
if (i%3===0) {
row = document.createElement("div");
row.className = "row";
}
var col = document.createElement("div");
col.className = "col-sm";
var chartDiv = document.createElement("div");
chartDiv.id = "chart"+i;
col.appendChild(chartDiv);
row.appendChild(col);
document.getElementById("charts").appendChild(row);
})
// Draws charts
data.forEach(function(d,i){
var chartDataObj = Object.assign({},d);
delete chartDataObj["Year"];
var chart = c3.generate({
...
});
});
});
</script>
<div id="charts" class="container"></div> |
Closing the issue because the rest of the problem doesn't seem belonging to c3. |
I want to make a web page that has four rows of three donut charts each. I'm using Bootstrap with C3.js.
My code looks like this.
My CSV...
When I load the page in my browser, I see 12 donut charts in a single vertical column. But when I resize the browser window to its thinnest, then expand it again, I see four rows of three donut charts each.
How do I make the browser show four rows of three charts each when the charts are first loaded?
The text was updated successfully, but these errors were encountered: