C3.js 将折线图 Y 轴的标签位置更改为 Y 轴居中
C3.js change label position of Line Chart Y axis to center up of Y axis
我需要在Y轴上改变Y轴的标签位置,目前的六个位置选项不能满足我的场景,我也尝试过用d3自定义它,但仍然没有运气。
我创建了一个plnkr demo, and also submit an issue in github。
var chart = c3.generate({
data: {
columns: [
['data', 30, 200, 100, 400, 150, 250]
]
},
axis: {
y: {
label: {
text: 'Y Axis Label',
position: 'outer-top'
}
}
}
});
有人知道怎么做吗?
非常感谢。
和你说的不一样,可以用D3自定义。只需 select 标签(按 class)并设置 transform
:
d3.select(".c3-axis-y-label").attr("transform", "translate(25,30)")
这是演示:
// Code goes here
(function() {
var chart = c3.generate({
padding: {
top: 10
},
data: {
columns: [
['data', 30, 200, 100, 400, 150, 250]
]
},
axis: {
y: {
label: {
text: 'Y Axis Label',
position: 'outer-top'
}
}
}
});
d3.select(".c3-axis-y-label").attr("transform", "translate(25,30)")
})();
<head>
<link rel="stylesheet" href="https://unpkg.com/c3@0.4.14/c3.css">
<link rel="stylesheet" href="style.css">
<script src="https://unpkg.com/d3@3.5.6/d3.js"></script>
<script src="https://unpkg.com/c3@0.4.14/c3.js"></script>
</head>
<body>
<div id="chart"></div>
<script src="script.js"></script>
</body>
我需要在Y轴上改变Y轴的标签位置,目前的六个位置选项不能满足我的场景,我也尝试过用d3自定义它,但仍然没有运气。
我创建了一个plnkr demo, and also submit an issue in github。
var chart = c3.generate({
data: {
columns: [
['data', 30, 200, 100, 400, 150, 250]
]
},
axis: {
y: {
label: {
text: 'Y Axis Label',
position: 'outer-top'
}
}
}
});
有人知道怎么做吗?
非常感谢。
和你说的不一样,可以用D3自定义。只需 select 标签(按 class)并设置 transform
:
d3.select(".c3-axis-y-label").attr("transform", "translate(25,30)")
这是演示:
// Code goes here
(function() {
var chart = c3.generate({
padding: {
top: 10
},
data: {
columns: [
['data', 30, 200, 100, 400, 150, 250]
]
},
axis: {
y: {
label: {
text: 'Y Axis Label',
position: 'outer-top'
}
}
}
});
d3.select(".c3-axis-y-label").attr("transform", "translate(25,30)")
})();
<head>
<link rel="stylesheet" href="https://unpkg.com/c3@0.4.14/c3.css">
<link rel="stylesheet" href="style.css">
<script src="https://unpkg.com/d3@3.5.6/d3.js"></script>
<script src="https://unpkg.com/c3@0.4.14/c3.js"></script>
</head>
<body>
<div id="chart"></div>
<script src="script.js"></script>
</body>