plotly javascript 如何重新绘图(更新图片、擦除图片、清屏)

Plotly.js 一个可以用来做分析和可视化的 javascript 绘图库

代码:

<body>
<div id="tester" style="width:600px;height:250px;"></div>

<p id="clean" >click me</p>
<p id="create" >create - click me</p>

</body>

<script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script>
<script src="http://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript">
$("#create").click(function(){
    TESTER = document.getElementById('tester');
    Plotly.plot(TESTER, [{
        x: [1, 2, 3, 4, 5],
        y: [1, 2, 4, 8, 16]
    }], {
        margin: {t: 0}
    });
})
$("#clean").click(function(){
    TESTER = document.getElementById('tester');
    Plotly.newPlot(TESTER, [{
        x: [1, 2, 3, 4, 5],
        y: [1, 2, 4, 8, 8]
    }], {
        margin: {t: 0}
    });
})
</script>

参考:https://plot.ly/javascript/responsive-fluid-layout/

说明:Plotly.plot 将在原图片上继续绘图,而Plotly.newPlot 将对原来的图片进行擦除重新绘图。当需要定时更新图片时,直接使用Plotly.newPlot 就可以了。


深度学习推荐
深度学习推荐

墨之科技,版权所有 © Copyright 2017-2027

湘ICP备14012786号     邮箱:ai@inksci.com