在Billboard.js中使用此代码段:
var chart = bb.generate({
data: {
columns: [
["data1", 30, 200, 100, 400, 150, 250],
["data2", 130, 100, 140, 200, 150, 50]
],
type: "spline"
},
bindto: "#SplineChart"
});
它将生成此图表:
可以看出,在这种情况下,Y轴的最小值为0,最大值为400(或某处)。
有没有办法获得该值并将其存储到变量中?
答案 0 :(得分:1)
如果我理解正确,你想获得Y轴的domain
。你可以通过以下方式实现它:
chart.internal.y.domain()
查看下面的演示:
var chart = bb.generate({
data: {
columns: [
["data1", 30, 200, 100, 400, 150, 250],
["data2", 130, 100, 140, 200, 150, 50]
],
type: "spline"
},
bindto: "#SplineChart"
});
var yDomain = chart.internal.y.domain()
console.log('y domain==> ', yDomain);
<script src="https://d3js.org/d3.v4.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/billboard.js/dist/billboard.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/billboard.js/dist/billboard.min.js"></script>
<div id="SplineChart"></div>