简体   繁体   English

C#中代码隐藏的动态Plotly图

[英]Dynamic Plotly graphs from codebehind in C#

I'm trying to create a webpage that dynamically creates new plotly graphs based on dynamically changing files. 我正在尝试创建一个动态创建基于动态更改文件的新图形图表的网页。 I'm having trouble accessing plotly functions from codebehind using ScriptManager.RegisterClientScriptBlock. 我无法使用ScriptManager.RegisterClientScriptBlock从代码隐藏访问绘图函数。 Maybe I am approaching this from the wrong direction but here is the gist of what I am doing. 也许我从错误的方向接近这个,但这是我正在做的事情的要点。

Codebehind: 代码隐藏:

    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "dayPop", "<script>doGraph();</script>", false);

HTML: HTML:

<div id="myDiv" style="width: 480px; height: 400px;"><!-- Plotly chart will be drawn inside this DIV --></div>

Script: 脚本:

    <script>
    var trace1 = {
        mode: 'lines',
        x: [1, 2, 3, 4],
        y: [10, 15, 13, 17]
    };

    var data = [trace1];

    //doGraph('myDiv');

    function doGraph() {
        var GRAPHONE = document.getElementById('myDiv');
        Plotly.newPlot(GRAPHONE, data);
    }
    </script>

Everything works great when I use the commented out line but Not from the codebehind. 当我使用注释掉的行而不是代码隐藏时,一切都很好。 Maybe someone here has experience doing this? 也许有人有这方面的经验吗?

<script>
$( document ).ready(function() {
    doGraph();
});
</script>

The problem is that, I suppose you are using jquery so your code should look like this for the script. 问题是,我想你正在使用jquery,所以你的代码看起来应该像脚本一样。 It is possible to call the doGraph() , before the browser is render the div, because of that you should execute it after the page is loaded. 在浏览器呈现div之前可以调用doGraph() ,因为你应该在加载页面后执行它。 If you don't use jquery you can attach this method on body onload function. 如果不使用jquery,可以在body onload函数上附加此方法。 But I strongly advise you to take a look into jquery. 但我强烈建议你去研究一下jquery。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM