使用Plotly中的新数据更新图形的高性能方法
High performance way to update graph with new data in Plotly?
我想使用滑块更新每个条形值的条形图。但是,我希望条形图随着滑块的变化而动态变化。我已经使用 oninput
实现了这一目标。目前,我有以下内容,这是相当滞后的。
.HTML
<head>
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<h1> Plotly Test</h1>
<div id="PlotlyTest" style="width: 480px; height: 400px;"><!-- Plotly chart will be drawn inside this DIV --></div>
<p> Adjust Value 1</p>
<form oninput="amount.value=rangeInput.value">
<input type="range" id="rangeInput" name="rangeInput" min="0" max="100" value="get_min() " oninput="adjustValue1(this.value)">
<output name="amount" for="rangeInput"></output>
</form>
<script src="functionality.js"></script>
</body>
.JS
var data = [{
x: ['VALUE 1'], // in reality I have more values...
y: [20],
type: 'bar'
}];
Plotly.newPlot('PlotlyTest', data);
function adjustValue1(value)
{
data[0]['y'][0] = value;
Plotly.redraw('PlotlyTest');
}
据此,使用Plotly.redraw
并不是最快的方法。但那又是什么呢?
我很快就把它放在一起(嗯,花了很大的努力来找出如何做到这一点;我刚刚修改了我所做的一些工作以适应这个答案)。据我所知,Plotly.animate()
函数是更新跟踪的最快方法。
update = {
x: data[0].x,
y: data[0].y,
opacity: 1 // You can do things like change the opacity too
};
Plotly.animate(div="graph", {
data: update,
traces: [0], /* With a bit of work, you can list any other traces you
want to update too (e.g. make a for loop over trace++ and set
update[trace] at each iteration) */
layout: {}
}, {
// These 2 make sure the plot updates as quickly as possible:
transition: {duration: 0},
frame: {duration: 0, redraw: false}
});
相关文章:
- 如何在Javascript中更新实时图形
- 如何更新 C3.js图形线宽和刻度颜色
- 使用Plotly中的新数据更新图形的高性能方法
- 如何在 d3.js 中更新我的图形图例
- 动态更新网页上的图形
- 如何在数据更新时更新可重用的 d3.js 图形
- 如何使用图形API查询公共facebook事件?[更新的搜索]
- Flotr2,图形上的颜色已更改,图例不更新
- 从json数据更新图形
- JavaScript自动更新图形
- HighChart JavaSCript两个样条在同一图形中更新
- D3更新数据和更新图形
- 使用Microsoft图形API更新任务,给出400个无效请求的响应
- Redux-对复杂图形的状态进行建模,并触发多个更新和副作用以响应单个操作
- 用新数据更新图形
- 为什么不更新D3 SVG图形上的轴?
- 带有图形更新的树视图复选框选择不能正常工作
- JavaScript/D3:在点击时创建浮动文本框,并从文本框输入更新图形
- 无法在D3.js中动态更新图形和轴
- D3, JSON,图形,强制布局,数据更新,未完成重绘,拖动