我想使用每个条形值的滑块来更新条形图。但是,我希望条形动态变化as滑块发生变化。我已经实现了这个使用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');
}
根据this https://plot.ly/javascript/plotlyjs-function-reference/#plotly-redraw, using 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}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)