gpt4 book ai didi

d3.js - 如何增加绘图面积图的宽度和高度

转载 作者:行者123 更新时间:2023-12-02 07:45:18 25 4
gpt4 key购买 nike

我不想增加 div 标签的高度和宽度。只是我只想增加图表的以下部分。我提到this code

enter image description here

我的html代码是:

<div id="myDiv" style="width: 480px; height: 400px;"></div>

我的plotly.js代码是:

var trace1 = {
x: ['2013-10-04 22:23:00', '2013-10-06 22:23:00', '2013-11-04 22:23:00', '2013-11-07 22:23:00','2013-12-04 22:23:00', '2013-12-08 22:23:00'],
y: [1, 3, 6,2, 4, 5],
fill: 'tozeroy',
type: 'scatter',
fillcolor: 'red'

};

var plotlyData = [trace1];                                      
plotly.newPlot('heap_memory_graph', plotlyData);
var plotDiv = document.getElementById('heap_memory_graph');

plotDiv.on('plotly_relayout',
function(eventdata){
xValStart = new Date(eventdata['xaxis.range[0]']);
xValEnd = new Date(eventdata['xaxis.range[1]']);
});

当我将此图表放入我的应用程序中时,图表变得非常小。我尝试增加宽度和高度,但无法增加图表的这部分。

最佳答案

添加marginlayout 并指定图形与周围框的距离(以像素为单位)。

var trace1 = {
x: ['2013-10-04 22:23:00', '2013-10-06 22:23:00', '2013-11-04 22:23:00', '2013-11-07 22:23:00','2013-12-04 22:23:00', '2013-12-08 22:23:00'],
y: [1, 3, 6,2, 4, 5],
fill: 'tozeroy',
type: 'scatter',
fillcolor: 'red'
};
var layout = {
margin: {
l: 20,
r: 10,
b: 40,
t: 10
},
};

var plotlyData = [trace1];
Plotly.newPlot('heap_memory_graph', plotlyData, layout);
var plotDiv = document.getElementById('heap_memory_graph');
  
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>

<div id="heap_memory_graph" style="width: 480px; height: 400px;"></div>

关于d3.js - 如何增加绘图面积图的宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39833344/

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