gpt4 book ai didi

javascript - 强制 billboard.js 样条图渲染所有线条

转载 作者:行者123 更新时间:2023-12-03 02:14:06 25 4
gpt4 key购买 nike

使用 billboard.js 创建样条图时,如果数据系列有一些“足够陡”的值,则创建的图表会 chop 一些线条。它将始终显示图表中的所有点,但不是所有连接样条线。

设置顶部/底部填充将为线条提供一些额外的空间,但这不够可靠。

我想知道是否有办法确保所有线条都位于样条图的可见区域内。

options = {
data: {
columns: [
["data1", -30, 255, 255, -50, -30, 255, 255, -50, -30, 255, 255, -50, 150, 250, 240, 20, 150, 250],
["data2", 130, 100, 140, 35, 110, 50, 130, 100, 140, 35, 110, 50, 130, 100, 140, 35, 110, 50]
],
type: "spline",
},
size: {
height: 240,
width: 480,
},
};

withpadding= {
y: {
padding: {
top:50,
},
},
};

options.bindto = "#chart";
bb.generate(options);
options.bindto = "#chart2";
options.axis = withpadding;
bb.generate(options);
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/billboard.js/dist/billboard.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/billboard.js/dist/billboard.min.css">
<div id="chart"></div>
<div id="chart2"></div>

最佳答案

您可以使用clipPath选项。只需设置 clipPath=false

bb.generate({
data: {
columns: [
["data1", -30, 255, 255, -50, -30, 255, 255, -50, -30, 255, 255, -50, 150, 250, 240, 20, 150, 250],
["data2", 130, 100, 140, 35, 110, 50, 130, 100, 140, 35, 110, 50, 130, 100, 140, 35, 110, 50]
],
type: "spline",
},
size: {
height: 240,
width: 480,
},
clipPath: false
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/billboard.js/dist/billboard.min.css" />
<script src="https://cdn.jsdelivr.net/npm/billboard.js/dist/billboard.pkgd.min.js"></script>
<title>billboard.js</title>
</head>
<body>
<div id="chart"></div>
</body>
</html>

关于javascript - 强制 billboard.js 样条图渲染所有线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49432856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com