【发布时间】:2016-06-16 14:13:47
【问题描述】:
我有一个 c3 条形图类别。我想格式化类别标签以便能够将其截断到一定长度。但我想不通。
这是图形定义:
var chart;
chart = c3.generate({
padding: {
top: 20,
bottom: 20
},
data: {
columns: [
["Listeners",4,2,0],
["Listens",4,2,0]],
type: 'bar',
groups:[["Listeners", "Listens"]]
},
axis: {
x: {
type: 'category',
categories: ["012345678890", "012345678890", "012345678890"],
}
},
bar: {
width: {
ratio: 0.5 // this makes bar width 50% of length between ticks
}
},
legend: {
show: false
}
});
<link href="https://raw.githubusercontent.com/c3js/c3/0.4.11/c3.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<script src="https://raw.githubusercontent.com/c3js/c3/0.4.11/c3.js"></script>
<div id="chart" class="c3" style="max-height: 280px; position: relative;"></div>
我尝试添加它以格式化 x 轴定义内的刻度,但它抱怨图表未定义
tick:{format:function (x) { return chart.categories()[x].substring(0, 10); }}
提前致谢!
【问题讨论】:
标签: javascript c3.js