【发布时间】:2018-07-12 07:05:19
【问题描述】:
这是我的输出图像:
我在 C3 中有一个分组条形图。我有关于数据的 x 轴滚动。滚动 x 轴时,我的 y 轴随之移动。如何固定屏幕上固定的y轴位置? 由于我必须表示大量数据,因此我希望在 x 轴和 Y 轴上滚动需要固定,并且条形宽度需要与以前相同,因为随着数据数量的增加条形宽度会自动减小。
这是我的代码:
$(function() {
var months = ['Jan 2016', 'Feb2016', 'Feb2016', 'Jan 2016', 'Feb2016', 'Feb2016'];
var chart = c3.generate({
data: {
bindto: '#chart',
columns: [
['data1', 30, 200, 100, 30, 200, 100],
['data2', 130, 100, 140, 30, 200, 100]
],
type: 'bar'
},
bar: {
width: {
ratio: 0.6
}
},
axis: {
x: {
type: 'category',
categories: months,
label: {
text: 'open cases',
position: 'outer-middle'
}
},
y: {
label: {
text: 'open cases',
position: 'outer-middle'
}
}
},
});
});
svg {
width: 400px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.3/c3.css" rel="stylesheet" />
<!-- Load d3.js and c3.js -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.5.0/d3.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.6.3/c3.js"></script>
<body>
<div style="width:300px;overflow-x:auto">
<div id="chart"></div>
</div>
</body>
【问题讨论】:
标签: javascript jquery css d3.js c3.js