var chart = c3.generate({
data: {
columns: [
['data1', 100, 250, 100, 300, 75],
['data2', 60, 500, 250, 450, 300],
]
},
onresized: function() {
setTimeout(updateLabels, 200);
}
});
var rightlabel = d3.select("#chart svg g")
.append("text")
.text("i'm a label in the green region").style("fill", "green")
.attr("transform","translate(" + (chart.internal.x(3)) + ",20)")
.style("text-anchor","middle");
var leftlabel = d3.select("#chart svg g")
.append("text")
.text("i'm a label in the red region").style("fill", "red")
.attr("transform","translate(" + (chart.internal.x(1)) + ",20)")
.style("text-anchor","middle");
function updateLabels(){
rightlabel.attr("transform","translate(" + chart.internal.x(3) + ",20)");
leftlabel.attr("transform","translate(" + chart.internal.x(1) + ",20)");
}
chart.regions.add([{axis: 'x', end: 2, class: 'c3-region-r'},{axis: 'x', start: 2, class: 'c3-region-gr'}]);
.c3-region-gr{
fill: green;
fill-opacity: 0.1;
}
.c3-region-r{
fill: red;
fill-opacity: 0.1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<link href="https://rawgit.com/masayuki0812/c3/master/c3.css" rel="stylesheet"/>
<script src="https://rawgit.com/masayuki0812/c3/master/c3.js"></script>
<div id="chart"></div>
非常有用的東西。謝謝! – deseosuho