javascript - 如何在 c3 分组条形图上固定 Y 轴的位置?
问题描述
这是我的输出图像。我在 C3 中有一个分组条形图。我有关于数据的 x 轴滚动。滚动 x 轴时,我的 y 轴随之移动。如何修复屏幕上固定的 y 轴位置。由于我必须表示大量数据,所以我希望在 x 轴和 Y 轴上滚动需要固定,并且条形宽度需要与以前相同,因为数据数量增加条形宽度会自动减小。这是我的代码:
<html>
<head>
<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>
<script type='text/javascript'>
$(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'
}
}
},
});
});
</script>
<style>
svg
{
width:400px;
}
</style>
</head>
<body>
<div style="width:300px;overflow-x:auto">
<div id="chart" ></div>
</div>
</div>
</body>
</html>
解决方案
推荐阅读
- android - 我们应该使用 Constraintlayout 作为 Recyclerview 项目布局吗?
- php - Big Sur 并安装 msodbcsql17
- sql - 如何遍历表名列表并查看列中的特定值是否存在?
- amazon-web-services - Terraform AWS IAM 用户在备用 terraform 应用命令上从 IAM 组中添加和删除
- swift - Swift - AVAudioEngine 无法默认为系统输出
- aspnetboilerplate - 如何将 abp 5.14 升级到 abp 6.0?
- vba - VBA 在继续之前检查页面上是否存在 HTMLDivElement
- python - 熊猫数据框样式格式行
- ssl - 当有 1 个密钥和 1 个 pem 时将 pem 密钥转换为 p12
- python - 如何返回数字的小数部分?