[英]How can I make a stepline or stepped chart in chart.js or D3?
我可以在 Google Spreadsheets 中完成此操作,下面是屏幕截圖:
這是 CSV 中的小數據集
Buy PPU,Sell PPU,Net PPU
0.023,0.019,-0.000725
0.026,0.0165,-0.003725
0.021,0.021,0.00735
0.015,0.0165,0.0147
0.021,0.028,0.0168
0.018,0.028,0.0198
任何幫助表示贊賞。 我在任何一個庫中都沒有看到這種特定類型圖表的示例(我相信稱為“步進”或“步進線”),但我相信它們足夠靈活以實現這一目標?
謝謝
似乎沒有人回答這個問題,但你可以通過在數據集配置中設置steppedLine:true來使用chart.js。
var config = {
type: 'line',
data: {
datasets: [{
label: "My dataset",
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
steppedLine: true,
}
}
您可以使用d3.svg.line
和設置line.interpolate
要么step-before
或step-after
。
這是文檔:
https://github.com/mbostock/d3/wiki/SVG-Shapes#line_interpolate
這是一個例子:
Chartjs為各種圖表提供了step屬性的stepped
折線圖。 例如,在 HTML 文檔中,添加 canvas 並使用 id:
[HTML]
<canvas id="myChart" width="400" height="400"></canvas>
<script src="index.js"></script>
[索引.js]
const ctx = document.getElementById('myChart').getContext('2d');
const data = {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [5, 4, 3, 6, 2, 3],
borderColor: '#FF0000',
borderWidth: 2,
stepped: 'after',
}]
}
const myChart = new Chart(ctx, {
type: 'line',
data: data,
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
stepped
可以是false
、 true
、 before
、 after
、 middle
的任何一個。 請參閱 文檔以獲取更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.